paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.45k stars 1.22k forks source link

getIntersections fails when line intersects closed path at vertex #477

Closed stringertheory closed 10 years ago

stringertheory commented 10 years ago

These steps will reproduce the problem:

var a = new Path(
  new Point(0, 0),
  new Point(50, 50),
  new Point(0, 100)
);
a.closed = true;
a.fillColor = 'blue';

var b = new Path(
  new Point(25, 50),
  new Point(75, 50)
);
b.strokeColor = 'red';

var intersections = a.getIntersections(b);

intersections is a blank list after this.

lehni commented 10 years ago

Which version of the library are you experiencing this with? It works for me on sketch:

http://sketch.paperjs.org/#S/dc7BCsIwDAbgVym9bIUxOmEIDk+evAled2m7uI3VBLpOD+K726qoQ70lX5s/uXBUR+Arvh/Am45n3FAT+5NyTLE1QziznfJdWiN7NNSjT2XGpMjmVgYsvzRgIaWoUVQ1qtxYGqEJwd5NcJdDb+2GLLmAibYTJIFrjAfo/wcsyl/LllGL5zKdj97RAK9wB807O3wHN4LxPeEYXlXegt9+YqpjigkVWcgttelsRlT8egM=

stringertheory commented 10 years ago

Sorry, had a typo in previous code example (the line did not go through a vertex of triangle). Just updated the comment, and updated on sketch: http://sketch.paperjs.org/#S/dc6xCsIwEAbgVwlZTKCEKBTB4uTkJrhmSdKzLY05SFIdxHc3taAWdbv7kvvvbtTrM9ANPfaQbEsLarEe+4sORJMt8XAlB51apjyZGux8YrIgkhdzKzOWX5pxKSVXnlfKa2EdRqhzcAoDPOXUObdDhyHjwrgBFpmVHw8w/w9Ylb+WrSedlhkRU8AeXuEB6nd2/g4hgk0d+phftWgg7T+RmTHF5godCIcNm83wit4f

hkrish commented 10 years ago

I was a small issue in the PathItem#getIntersections.

@lehni I have fixed it.

Previously, when we had only 2 intersections, one of which is a duplicate of other —typical in this case since the intersection is on the vertex between two curves; we were removing both intersections wrongly.