Sg2.9
intersects() and Line
Recent RSS
intersects() and Line
Date:  30. April 2012, 13:09

Do I have an error in this code or does intersects() not work for a Line?
I notice a bug report at October 2011 that also suggests 2 point lines are not behaving the same as paths with more points?

  • --------

When I run this code, I get 'no hit' followed by a list of hits if i use a Line
If I change the line to a thin Rectangle , intersects() seems to work ok.

var testLine = Path.Line(left,y,right,y);
document.activeLayer.appendTop(testLine) ;
// get intersections with hit item
if ( ! testLine.intersects(hitItem) ) {
console.log ('line at ', y, 'intersects says no hit');
}
console.log ('line at ', y, 'intersections are ...');
var locations = testLine.getIntersections(hitItem);
// Loop through the locations (if any):
for(var i = 0; i < locations.length; i++) {
// The position of the intersection:
var point = locations[i].point;
console.log ( point.x, ',' , point.y);
}

Re: intersects() and Line
Date:  6. May 2012, 10:51

looking at the Scriptographer source code I see that is how it is written.

.intersects is not implemented as x.getintersections(y).length != 0
but uses an area based test - and I guess lines dont have an area in that sense?

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Triangular 25.01.11