about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-09-03 19:22:17 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-09-03 19:24:40 -0700
commit1a6f533e2c08c0f330217e10d7ae01d1fd2a8d7a (patch)
tree28112bb0f0dcf6dab98511a8aa42b61af8d881c5
parentc6f88dccfa9ef6922fa19885f3d5569e809414ed (diff)
downloadtext.love-1a6f533e2c08c0f330217e10d7ae01d1fd2a8d7a.tar.gz
dedup points while loading drawing from disk
-rw-r--r--drawing.lua5
-rw-r--r--file.lua16
2 files changed, 8 insertions, 13 deletions
diff --git a/drawing.lua b/drawing.lua
index 26683b2..0343f85 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -712,11 +712,6 @@ function round(num)
   return math.floor(num+.5)
 end
 
-function Drawing.insert_point(points, x,y)
-  table.insert(points, {x=x, y=y})
-  return #points
-end
-
 function Drawing.find_or_insert_point(points, x,y, width)
   -- check if UI would snap the two points together
   for i,point in ipairs(points) do
diff --git a/file.lua b/file.lua
index 4e268a7..53ef047 100644
--- a/file.lua
+++ b/file.lua
@@ -61,20 +61,20 @@ function load_drawing(infile_next_line)
       -- no changes needed
     elseif shape.mode == 'line' or shape.mode == 'manhattan' then
       local name = shape.p1.name
-      shape.p1 = Drawing.insert_point(drawing.points, shape.p1.x, shape.p1.y)
+      shape.p1 = Drawing.find_or_insert_point(drawing.points, shape.p1.x, shape.p1.y, --[[large width to minimize overlap]] 1600)
       drawing.points[shape.p1].name = name
       name = shape.p2.name
-      shape.p2 = Drawing.insert_point(drawing.points, shape.p2.x, shape.p2.y)
+      shape.p2 = Drawing.find_or_insert_point(drawing.points, shape.p2.x, shape.p2.y, --[[large width to minimize overlap]] 1600)
       drawing.points[shape.p2].name = name
     elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
       for i,p in ipairs(shape.vertices) do
         local name = p.name
-        shape.vertices[i] = Drawing.insert_point(drawing.points, p.x,p.y)
+        shape.vertices[i] = Drawing.find_or_insert_point(drawing.points, p.x,p.y, --[[large width to minimize overlap]] 1600)
         drawing.points[shape.vertices[i]].name = name
       end
     elseif shape.mode == 'circle' or shape.mode == 'arc' then
       local name = shape.center.name
-      shape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)
+      shape.center = Drawing.find_or_insert_point(drawing.points, shape.center.x,shape.center.y, --[[large width to minimize overlap]] 1600)
       drawing.points[shape.center].name = name
     elseif shape.mode == 'deleted' then
       -- ignore
@@ -154,20 +154,20 @@ function load_drawing_from_array(iter, a, i)
       -- no changes needed
     elseif shape.mode == 'line' or shape.mode == 'manhattan' then
       local name = shape.p1.name
-      shape.p1 = Drawing.insert_point(drawing.points, shape.p1.x, shape.p1.y)
+      shape.p1 = Drawing.find_or_insert_point(drawing.points, shape.p1.x, shape.p1.y, --[[large width to minimize overlap]] 1600)
       drawing.points[shape.p1].name = name
       name = shape.p2.name
-      shape.p2 = Drawing.insert_point(drawing.points, shape.p2.x, shape.p2.y)
+      shape.p2 = Drawing.find_or_insert_point(drawing.points, shape.p2.x, shape.p2.y, --[[large width to minimize overlap]] 1600)
       drawing.points[shape.p2].name = name
     elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
       for i,p in ipairs(shape.vertices) do
         local name = p.name
-        shape.vertices[i] = Drawing.insert_point(drawing.points, p.x,p.y)
+        shape.vertices[i] = Drawing.find_or_insert_point(drawing.points, p.x,p.y, --[[large width to minimize overlap]] 1600)
         drawing.points[shape.vertices[i]].name = name
       end
     elseif shape.mode == 'circle' or shape.mode == 'arc' then
       local name = shape.center.name
-      shape.center = Drawing.insert_point(drawing.points, shape.center.x,shape.center.y)
+      shape.center = Drawing.find_or_insert_point(drawing.points, shape.center.x,shape.center.y, --[[large width to minimize overlap]] 1600)
       drawing.points[shape.center].name = name
     elseif shape.mode == 'deleted' then
       -- ignore