<commit_before>import UIKit

class Rule: NSObject {
    var velocity: CGPoint!
    var weight: CGFloat

    var weighted: CGPoint {
        return CGPoint(x: velocity.x * weight, y: velocity.y * weight)
    }

    init(weight: CGFloat) {
        self.weight = weight
        super.init()
        clear()
    }
    
    func clear() {
        velocity = CGPoint(x: 0.0, y: 0.0)
    }
    
    func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        clear()
    }    
}

class AlignmentRule: Rule {
    let factor: CGFloat = 2.0
    
    override func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        super.evaluate(targetNode: targetNode, birdNodes: birdNodes)

        for birdNode in birdNodes {
            if birdNode != targetNode {
                velocity.x += birdNode.velocity.x
                velocity.y += birdNode.velocity.y
            }
        }

        if birdNodes.count <= 1 {
            return
        }

        velocity.x /= CGFloat(birdNodes.count - 1)
        velocity.y /= CGFloat(birdNodes.count - 1)
        
        velocity.x = (velocity.x - targetNode.velocity.x) / factor
        velocity.y = (velocity.y - targetNode.velocity.y) / factor
    }
}

class CohesionRule: Rule {
    let factor: CGFloat = 300.0
    
    override func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        super.evaluate(targetNode: targetNode, birdNodes: birdNodes)

        for birdNode in birdNodes {
            if birdNode != targetNode {
                velocity.x += birdNode.position.x
                velocity.y += birdNode.position.y
            }
        }

        if birdNodes.count <= 1 {
            return
        }

        velocity.x /= CGFloat(birdNodes.count - 1)
        velocity.y /= CGFloat(birdNodes.count - 1)
        
        velocity.x = (velocity.x - targetNode.position.x) / factor
        velocity.y = (velocity.y - targetNode.position.y) / factor
    }
}

class NoiseRule: Rule {
    override func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        super.evaluate(targetNode: targetNode, birdNodes: birdNodes)
<commit_msg>Group boids based on a range<commit_after>import UIKit

class Rule: NSObject {
    var velocity: CGPoint!
    var weight: CGFloat

    var weighted: CGPoint {
        return CGPoint(x: velocity.x * weight, y: velocity.y * weight)
    }

    init(weight: CGFloat) {
        self.weight = weight
        super.init()
        clear()
    }
    
    func clear() {
        velocity = CGPoint(x: 0.0, y: 0.0)
    }
    
    func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        clear()
    }    
}

class AlignmentRule: Rule {
    let factor: CGFloat = 2.0
	let range = 300.0
    
    override func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        super.evaluate(targetNode: targetNode, birdNodes: birdNodes)

		var boidsInCurrentGroup = 0
        for birdNode in birdNodes {
			if birdNode == targetNode {
				continue
			}

			if distanceBetween(birdNode.position, targetNode.position) > range {
				continue
			}

			boidsInCurrentGroup += 1
			velocity.x += birdNode.velocity.x
			velocity.y += birdNode.velocity.y
        }

        if boidsInCurrentGroup <= 1 {
            return
        }

        velocity.x /= CGFloat(boidsInCurrentGroup)
        velocity.y /= CGFloat(boidsInCurrentGroup)
        
        velocity.x = (velocity.x - targetNode.velocity.x) / factor
        velocity.y = (velocity.y - targetNode.velocity.y) / factor
    }
}

class CohesionRule: Rule {
    let factor: CGFloat = 300.0
	let range = 300.0
    
    override func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        super.evaluate(targetNode: targetNode, birdNodes: birdNodes)

		var boidsInCurrentGroup = 0
        for birdNode in birdNodes {
            if birdNode == targetNode {
				continue
			}

			if distanceBetween(birdNode.position, targetNode.position) > range {
				continue
			}

			boidsInCurrentGroup += 1
			velocity.x += birdNode.position.x
			velocity.y += birdNode.position.y
        }

        if boidsInCurrentGroup <= 1 {
            return
        }

        velocity.x /= CGFloat(boidsInCurrentGroup)
        velocity.y /= CGFloat(boidsInCurrentGroup)
        
        velocity.x = (velocity.x - targetNode.position.x) / factor
        velocity.y = (velocity.y - targetNode.position.y) / factor
    }
}

class NoiseRule: Rule {
    override func evaluate(targetNode targetNode: BirdNode, birdNodes: [BirdNode]) {
        super.evaluate(targetNode: targetNode, birdNodes: birdNodes)

{'fraction_non_alphanumeric': 0.0986159169550173, 'fraction_numerical': 0.00865051903114187, 'mean_word_length': 2.135593220338983, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5539345', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1388, 'n_words': 327}