From d730c244a54905b96117fc8025bdf209c6880ba6 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 24 Aug 2017 18:01:30 -0700 Subject: [PATCH] [kit] Return a (0,0) point if the radius is too big for the bounds --- MetaballsKit/Metaballs.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MetaballsKit/Metaballs.swift b/MetaballsKit/Metaballs.swift index 39a111d..b748598 100644 --- a/MetaballsKit/Metaballs.swift +++ b/MetaballsKit/Metaballs.swift @@ -178,6 +178,9 @@ public class Field { } private func randomPoint(forBallWithRadius radius: Float) -> Point { + guard Float(bounds.width) > radius && Float(bounds.height) > radius else { + return Point() + } let insetBounds = bounds.insetBy(dx: CGFloat(radius), dy: CGFloat(radius)) let x = Float(UInt32(insetBounds.minX) + arc4random_uniform(UInt32(insetBounds.width))) let y = Float(UInt32(insetBounds.minY) + arc4random_uniform(UInt32(insetBounds.height)))