Add sample() func to Field -- needs for two commits ago
This commit is contained in:
parent
1c1171df59
commit
f1a326e1cb
1 changed files with 11 additions and 0 deletions
|
@ -178,6 +178,17 @@ public class Field {
|
||||||
balls.removeAll(keepingCapacity: true)
|
balls.removeAll(keepingCapacity: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sample(at point: Float2) -> Float {
|
||||||
|
var sample: Float = 0.0;
|
||||||
|
for b in balls {
|
||||||
|
let r2 = b.radius * b.radius
|
||||||
|
let xDiff = point.x - b.position.x
|
||||||
|
let yDiff = point.y - b.position.y
|
||||||
|
sample += r2 / (xDiff * xDiff + yDiff * yDiff)
|
||||||
|
}
|
||||||
|
return sample
|
||||||
|
}
|
||||||
|
|
||||||
private func randomPoint(forBallWithRadius radius: Float) -> Float2 {
|
private func randomPoint(forBallWithRadius radius: Float) -> Float2 {
|
||||||
guard Float(bounds.width) > radius && Float(bounds.height) > radius else {
|
guard Float(bounds.width) > radius && Float(bounds.height) > radius else {
|
||||||
return Float2()
|
return Float2()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue