work on breaking intersecting lines. Doesn't work.
This commit is contained in:
parent
05573cb9d0
commit
1c10240f57
|
|
@ -219,6 +219,26 @@ def onMouseUpGroup(self, x, y,button=1,clicks=1):
|
||||||
lastline = l
|
lastline = l
|
||||||
self.lines.append(l)
|
self.lines.append(l)
|
||||||
self.delete(self.activelayer.frames[self.currentframe].objs[-1])
|
self.delete(self.activelayer.frames[self.currentframe].objs[-1])
|
||||||
|
for line in self.lines:
|
||||||
|
for otherline in self.lines:
|
||||||
|
if not otherline is line:
|
||||||
|
if line.connection1 and otherline in line.connection1.lines: continue
|
||||||
|
if line.connection2 and otherline in line.connection2.lines: continue
|
||||||
|
inter = line.intersects(otherline)
|
||||||
|
if inter:
|
||||||
|
print "INTERSECTION"
|
||||||
|
inter = svlgui.Point(*inter)
|
||||||
|
l1 = svlgui.Line(line.endpoint1,inter,line.connection1,inter)
|
||||||
|
l2 = svlgui.Line(line.endpoint2,inter,line.connection2,inter)
|
||||||
|
l3 = svlgui.Line(otherline.endpoint1,inter,otherline.connection1,inter)
|
||||||
|
l4 = svlgui.Line(otherline.endpoint2,inter,otherline.connection2,inter)
|
||||||
|
inter.lines.add(l1)
|
||||||
|
inter.lines.add(l2)
|
||||||
|
inter.lines.add(l3)
|
||||||
|
inter.lines.add(l4)
|
||||||
|
self.lines[self.lines.index(line):self.lines.index(line)+1]=[l1,l2]
|
||||||
|
self.lines[self.lines.index(otherline):self.lines.index(otherline)+1]=[l3,l4]
|
||||||
|
break
|
||||||
'''for i in self.lines:
|
'''for i in self.lines:
|
||||||
if abs(self.cshape.endpoint2.x-i.endpoint1.x)<10 and abs(self.cshape.endpoint2.y-i.endpoint1.y)<10:
|
if abs(self.cshape.endpoint2.x-i.endpoint1.x)<10 and abs(self.cshape.endpoint2.y-i.endpoint1.y)<10:
|
||||||
self.cshape.connection2 = i.endpoint1
|
self.cshape.connection2 = i.endpoint1
|
||||||
|
|
|
||||||
46
svlgui.py
46
svlgui.py
|
|
@ -3128,6 +3128,52 @@ class Line(object):
|
||||||
cz = x1*y2-y1*x2
|
cz = x1*y2-y1*x2
|
||||||
if cz>0: angle=360-angle
|
if cz>0: angle=360-angle
|
||||||
return angle
|
return angle
|
||||||
|
def intersects(self,other):
|
||||||
|
'''def IsOnLeft(a,b,c):
|
||||||
|
return Area2(a,b,c) > 0
|
||||||
|
def IsOnRight(a,b,c):
|
||||||
|
return Area2(a,b,c) < 0
|
||||||
|
def IsCollinear(a,b,c):
|
||||||
|
return Area2(a,b,c) == 0
|
||||||
|
def Area2 (a,b,c):
|
||||||
|
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)
|
||||||
|
if (IsOnLeft(self.endpoint1,self.endpoint2,other.endpoint1) and IsOnRight(self.endpoint1,self.endpoint2,other.endpoint2))
|
||||||
|
or (IsOnLeft(self.endpoint1,self.endpoint2,other.endpoint2) and IsOnRight(self.endpoint1,self.endpoint2,other.endpoint1):
|
||||||
|
if (IsOnLeft(other.endpoint1,other.endpoint2,self.endpoint1) and IsOnRight(other.endpoint1,other.endpoint2,self.endpoint2))
|
||||||
|
or (IsOnLeft(other.endpoint1,other.endpoint2,self.endpoint2) and IsOnRight(other.endpoint1,other.endpoint2,self.endpoint1):
|
||||||
|
return True'''
|
||||||
|
# Formula for line is y = mx + b
|
||||||
|
try:
|
||||||
|
sm = (self.endpoint1.y-self.endpoint2.y)/(self.endpoint1.x-self.endpoint1.y)
|
||||||
|
om = (other.endpoint1.y-other.endpoint2.y)/(other.endpoint1.x-other.endpoint1.y)
|
||||||
|
sb = self.endpoint1.y-sm*self.endpoint1.x
|
||||||
|
ob = other.endpoint1.y-sm*other.endpoint1.x
|
||||||
|
if sm == om: return False
|
||||||
|
x = (ob-sb)/(sm-om)
|
||||||
|
y = sm*x + sb
|
||||||
|
if min(self.endpoint1.x,self.endpoint2.x)<x<max(self.endpoint1.x,self.endpoint2.x):
|
||||||
|
return [x,y]
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except ZeroDivisionError:
|
||||||
|
# One of the lines is vertical.
|
||||||
|
# Formula for line in terms of y is x = my + b
|
||||||
|
try:
|
||||||
|
sm = (self.endpoint1.x-self.endpoint2.x)/(self.endpoint1.y-self.endpoint1.x)
|
||||||
|
om = (other.endpoint1.x-other.endpoint2.x)/(other.endpoint1.y-other.endpoint1.x)
|
||||||
|
sb = self.endpoint1.x-sm*self.endpoint1.y
|
||||||
|
ob = other.endpoint1.x-sm*other.endpoint1.y
|
||||||
|
if sm == om: return False
|
||||||
|
y = (ob-sb)/(sm-om)
|
||||||
|
x = sm*y + sb
|
||||||
|
if min(self.endpoint1.y,self.endpoint2.y)<y<max(self.endpoint1.y,self.endpoint2.y):
|
||||||
|
return [x,y]
|
||||||
|
except ZeroDivisionError:
|
||||||
|
# One of the lines is horizontal, too. Or one has zero length.
|
||||||
|
# Logic this.
|
||||||
|
return False
|
||||||
|
|
||||||
|
return False
|
||||||
def draw(self, cr=None, transform=None, rect=None):
|
def draw(self, cr=None, transform=None, rect=None):
|
||||||
if self.connection1:
|
if self.connection1:
|
||||||
self.endpoint1 = self.connection1
|
self.endpoint1 = self.connection1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue