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.5k stars 1.23k forks source link

If points lie on same coordinate closePath eats up last point #435

Closed christophknoth closed 10 years ago

christophknoth commented 10 years ago

If you create a new path and put all the points on the same coordinate and then use closePath, one point is missing.

http://sketch.paperjs.org/#S/tZBPi8IwEMW/SogHK5SS1HpRvCjePCy4t+0eQh3b4nRGmuAi4ndfE9hl/wQFwVuGvN+b9+YsyXQgp3KzB1c1MpUVb/18NL1A2LnVCdbGQi/mguBDvBjXJOeSSrdrEZeM3E/FcLAqdKEXw7Sky2h2/aWfaNbxEV45CTy35BKVCjXywl8ybOmZMh2VVcgWQqtIcAt1B+Tsm3rPDt7k6wrh7R21Uv8svykdpSbXvMUNKo9SuVJ3to3jGSfhPKFbxWQZIUOuk9s9M0M1gqfuM/oBJn+AGf9h5OUT

var leftEyeLaser = new Path({
    fillColor: '#E4141B',
});

leftEyeLaser.moveTo(new Point(0, 0));
leftEyeLaser.lineTo(new Point(0, 0));
leftEyeLaser.lineTo(new Point(0, 0));
leftEyeLaser.lineTo(new Point(1, 0));  //<- change this to (0, 0)
leftEyeLaser.closePath();

leftEyeLaser.segments[0].point = new Point (1, 100);
leftEyeLaser.segments[1].point = new Point (50, 40);
leftEyeLaser.segments[2].point = new Point (200, 100);
leftEyeLaser.segments[3].point = new Point (150, 0);

console.log(leftEyeLaser.segments[0].point.angle);
console.log(leftEyeLaser.segments[1].point.angle);
console.log(leftEyeLaser.segments[2].point.angle);
console.log(leftEyeLaser.segments[3].point.angle);
lehni commented 10 years ago

Yes that's because currently close path combines the first and last segment if they are on the same point, merging their handles. Perhaps that's too much intelligence in a command that people are used to from other APIs already? Maybe this should happen if path.join() is called without any other argument?

christophknoth commented 10 years ago

The problem is that in a lot of paperjs examples a path is generated and then afterwards there is a loop that runs through the points and changes their coordinates. I tried to follow that and because I did not know the coordination at creation time of the path I set them all to 0,0. And finally I was wondering why I am missing a point.

I think that I only want to loose points when I command the library to do so. If not it is a bit like as if I am losing a variable because I set it to the same value as another one.

lehni commented 10 years ago

Yes I agree. I will see why I changed it this way and will move the "intelligence" to a better place. For now you can use path.closed = true instead of path.closePath(); to avoid this behavior.

lehni commented 10 years ago

Caused by this change: 5ff911f68ca63a4e2b63440f0c82c4cf3d05db2e