Open highfellow opened 11 years ago
Incidentally I think it's more than it only showing the first intersection.
I have some other code which checks for intersections between a large number of FLines. There are some which return more than one cursor pair per pair of FLines, but it still doesn't find all the intersections between FLines in the drawing.
If I change FLine() to PLine(), and use pLine.intersections(pLine2), it works fine.
I think the difference between FLines and PLines needs documenting.
PLine's need to disappear and FLine's need to have all their functionality. This is clearly a bug. Investigating....
Any progress on sorting this out?
I think I've resolved this. In Contents/python/NewCachedLines.py, change the functions pointsOfIntersection2 and doIntersection2 as follows:
diff --git a/Contents/python/NewCachedLines.py b/Contents/python/NewCachedLines.py
index 211cbd0..c7db406 100644
--- a/Contents/python/NewCachedLines.py
+++ b/Contents/python/NewCachedLines.py
@@ -745,7 +745,7 @@ CachedLine.cursor = cursor
def pointsOfIntersection2(self, otherLine):
"""Returns a list of points where this line intersects with otherLine"""
- x = Intersections.intersectAndSubdivide([self.copy()], [otherLine.copy()], 5)
+ x = Intersections.intersectAndSubdivide([self.copy()], [otherLine.copy()], 100)
rr = []
for xx in x:
rr.append( xx[0].getAt())
@@ -755,7 +755,7 @@ def doIntersection2(self, otherLine):
"""Intersects this line with otherLine; mutates both
This method will insert nodes in both lines where they intersect and return cursors for each line at these intersection points. These cursors are returned as [(this, other), (this, other) ... ]"""
- ret = Intersections.intersectAndSubdivide([self], [otherLine], 5)
+ ret = Intersections.intersectAndSubdivide([self], [otherLine], 100)
rr = []
for r in ret:
a,b = Intersections.resolve(r[0]), Intersections.resolve(r[1])
The only change is to alter the 'limit' parameter of Intersections.intersectAndSubdivide from 5 to 100, which is the value used in the equivalent PLine functions. (See TweakTools.py, line 786).
With this change, all the intersections are detected OK. You can verify this using this code:
line=FLine()
line.moveTo(500,300)
for n in xrange(20):
vect = Vector2(100,0 )
vect.scale((n+1)/7.0)
vect.rotateBy(n/1.5)
line.lineTo(500 + vect.x, 300 + vect.y)
line2=line.copy()
line2+= Vector2(20,-20)
# mark the points
line3=FLine()
line3.color=Vector4(1.0,0,0,1.0)
for point in line2.pointsOfIntersection2(line):
line3.ellipse(10,10,point[0],point[1])
# mark the cursors
line4=FLine()
line4.color=Vector4(0,1.0,0,1.0)
for cursors in line2.doIntersection2(line):
pos = cursors[0].position()
line4.ellipse(5,5,pos[0],pos[1])
_self.lines.clear()
_self.lines.add(line)
_self.lines.add(line2)
_self.lines.add(line3)
_self.lines.add(line4)
If I find the time, I'll put in a proper pull request.
Many thanks. Pull request if you can, otherwise I'll put it into my next (already huge) push.
Marc
On Sat, May 18, 2013 at 1:24 PM, Andrew Baxter notifications@github.comwrote:
I think I've resolved this. In Contents/python/NewCachedLines.py, change the functions pointsOfIntersection2 and doIntersection2 as follows:
diff --git a/Contents/python/NewCachedLines.py b/Contents/python/NewCachedLines.py index 211cbd0..c7db406 100644 --- a/Contents/python/NewCachedLines.py +++ b/Contents/python/NewCachedLines.py @@ -745,7 +745,7 @@ CachedLine.cursor = cursor
def pointsOfIntersection2(self, otherLine): """Returns a list of points where this line intersects with otherLine"""
- x = Intersections.intersectAndSubdivide([self.copy()], [otherLine.copy()], 5)
x = Intersections.intersectAndSubdivide([self.copy()], [otherLine.copy()], 100) rr = [] for xx in x: rr.append( xx[0].getAt()) @@ -755,7 +755,7 @@ def doIntersection2(self, otherLine): """Intersects this line with otherLine; mutates both
This method will insert nodes in both lines where they intersect and return cursors for each line at these intersection points. These cursors are returned as [(this, other), (this, other) ... ]"""
- ret = Intersections.intersectAndSubdivide([self], [otherLine], 5)
- ret = Intersections.intersectAndSubdivide([self], [otherLine], 100) rr = [] for r in ret: a,b = Intersections.resolve(r[0]), Intersections.resolve(r[1])
The only change is to alter the 'limit' parameter of Intersections.intersectAndSubdivide from 5 to 100, which is the value used in the equivalent PLine functions. (See TweakTools.py, line 786).
With this change, all the intersections are detected OK. You can verify this using this code:
line=FLine() line.moveTo(500,300)
for n in xrange(20): vect = Vector2(100,0 ) vect.scale((n+1)/7.0) vect.rotateBy(n/1.5) line.lineTo(500 + vect.x, 300 + vect.y)
line2=line.copy() line2+= Vector2(20,-20)
mark the points
line3=FLine() line3.color=Vector4(1.0,0,0,1.0) for point in line2.pointsOfIntersection2(line): line3.ellipse(10,10,point[0],point[1])
mark the cursors
line4=FLine() line4.color=Vector4(0,1.0,0,1.0) for cursors in line2.doIntersection2(line): pos = cursors[0].position() line4.ellipse(5,5,pos[0],pos[1])
_self.lines.clear() _self.lines.add(line) _self.lines.add(line2) _self.lines.add(line3) _self.lines.add(line4)
If I find the time, I'll put in a proper pull request.
— Reply to this email directly or view it on GitHubhttps://github.com/OpenEndedGroup/Field/issues/28#issuecomment-18099227 .
Could you put in the push? I'm away from home for a week, and I don't have access to all my files.
Neither of the intersection methods on FLines are working for me (in linux).
This code in a spline box:
produces this output:
The two spirals actually cross at 3 points.
I.e.:
doIntersection2 does add nodes to the lines correctly at the first crossing.