Faster anchor search in some common cases
This commit is contained in:
parent
a8b921e05b
commit
a20ad44f75
@ -214,6 +214,17 @@ function level:anchor_points()
|
||||
return pairs(self._anch)
|
||||
end
|
||||
|
||||
function level:anchors_in(px0,py0,px1,py1)
|
||||
ancs={}
|
||||
for ax=px0\4,(px1+3)\4 do
|
||||
for ay=py0\4,(py1+3)\4 do
|
||||
local anc=self._anch[_amix(ax,ay)]
|
||||
if (anc!=nil) add(ancs, anc)
|
||||
end
|
||||
end
|
||||
return ancs
|
||||
end
|
||||
|
||||
function level:point_anchor(px,py)
|
||||
local ax,ay=self:p2a(px,py)
|
||||
local anc=self._anch[_amix(ax,ay)]
|
||||
@ -762,14 +773,8 @@ function rope:_find_needed_anchors(i)
|
||||
local anchors_bydist={}
|
||||
local x0,x2=_mnmx(a0.x,a2.x)
|
||||
local y0,y2=_mnmx(a0.y,a2.y)
|
||||
for _,a1 in level:anchor_points() do
|
||||
-- the new anchor point must be in the bounding box
|
||||
-- of the old line
|
||||
-- note: this fudge never turned out necessary
|
||||
-- i just would be ok with it
|
||||
if x0-1<=a1.x and a1.x<=x2+1 and y0-1<=a1.y and a1.y<=y2+1 then
|
||||
add(anchors_bydist,{el=a1,key=_linedist(a0,a1,a2)})
|
||||
end
|
||||
for a1 in all(level:anchors_in(x0-1,y0-1,x2+1,y2+1)) do
|
||||
add(anchors_bydist,{el=a1,key=_linedist(a0,a1,a2)})
|
||||
end
|
||||
shellsort(anchors_bydist)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user