From 61eaceff25d668074ef09a003526e8f3280bd471 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 5 Jan 2024 04:13:36 +0000 Subject: connect wires to editing handles --- main.lua | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'main.lua') diff --git a/main.lua b/main.lua index ff0d56d..fa41c00 100644 --- a/main.lua +++ b/main.lua @@ -65,9 +65,24 @@ end local EditHandle = class() EditHandle.R = 0.04 +EditHandle.D = 0.2 +function EditHandle.make(cls, theta,p,q,w,pg) + local self = setmetatable({ + x = cls.D * math.cos(theta) + p.x, + y = cls.D * math.sin(theta) + p.y, + color = w.color, + here = p, + there = q, + pg = pg, + },cls) + self.curve = catenary.catenary( + self.x,self.y, self.there.x,self.there.y) + return self +end function EditHandle.draw(self) G.setColor(self.color) G.circle('fill',self.x,self.y,self.R) + G.line(self.curve) end function EditHandle.contains(self, px,py) local d = math.sqrt((self.x - px)^2 + (self.y - py)^2) @@ -77,7 +92,6 @@ function EditHandle.remove_wire(self) self.pg:remove_conn(self.here,self.there) end - local PortGraph = class() function PortGraph.make(cls) return setmetatable({ @@ -111,8 +125,14 @@ function PortGraph.draw(self) p:draw(istate) end for w in pairs(self.wires) do + if self.state == 'editing' then + if self.selected == w.p1 or self.selected == w.p2 then + goto next + end + end local istate = self:istate_of_wire(w) w:draw(istate) + ::next:: end if self.state == 'joining' then @@ -140,14 +160,8 @@ function PortGraph.make_edit_handles(self) for q,w in pairs(p.conns) do local theta = tau * i/n i = i + 1 - local h = setmetatable({ - x = D * math.cos(theta) + p.x, - y = D * math.sin(theta) + p.y, - color = w.color, - here = p, - there = q, - pg = self, - },EditHandle) + local h = EditHandle:make(theta,p,q,w,self) + hs[h] = true end @@ -162,9 +176,9 @@ function PortGraph.click(self,button) self.state = 'joining' self.selected = p elseif button == 2 then - self.state = 'editing' self.selected = p self.handles = self:make_edit_handles() + self.state = 'editing' end end elseif self.state == 'joining' then -- cgit v1.2.3