From e14a71ab6a08c0b3ee2754be4becc8be25bb8317 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Fri, 21 Dec 2018 19:47:39 -0500 Subject: [PATCH] Pointt.iterateClosest --- sys/apis/point.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/apis/point.lua b/sys/apis/point.lua index 1d83eab..f36933b 100644 --- a/sys/apis/point.lua +++ b/sys/apis/point.lua @@ -189,6 +189,8 @@ function Point.closest(reference, pts) end function Point.eachClosest(spt, ipts, fn) + if not ipts then error('Point.eachClosest: invalid points', 2) end + local pts = Util.shallowCopy(ipts) while #pts > 0 do local pt = Point.closest(spt, pts) @@ -200,6 +202,17 @@ function Point.eachClosest(spt, ipts, fn) end end +function Point.iterateClosest(spt, ipts) + local pts = Util.shallowCopy(ipts) + return function() + local pt = Point.closest(spt, pts) + if pt then + Util.removeByValue(pts, pt) + return pt + end + end +end + function Point.adjacentPoints(pt) local pts = { }