From f1a326e1cbfae384a3636134e33b53632610050e Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 13 Oct 2018 12:41:53 -0700 Subject: [PATCH] Add sample() func to Field -- needs for two commits ago --- MetaballsKit/Metaballs.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MetaballsKit/Metaballs.swift b/MetaballsKit/Metaballs.swift index 3690da6..fa1e1a3 100644 --- a/MetaballsKit/Metaballs.swift +++ b/MetaballsKit/Metaballs.swift @@ -178,6 +178,17 @@ public class Field { 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 { guard Float(bounds.width) > radius && Float(bounds.height) > radius else { return Float2()