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

Setting angle and length on vectors reverts direction. #246

Closed lehni closed 11 years ago

lehni commented 11 years ago

As reported by Евгений Хорев on the mailing list:

When for existing path I do

path.segments[0].point = p0;
path.segments[0].handleOut = {angle: alpha, length: l};

it works as expected, but when I do

path.segments[0].point = p0;
path.segments[0].handleOut.angle = alpha;
path.segments[0].handleOut.length = l;

it changes the handle’s direction to opposite for the same ‘alpha’ and ‘l’ values in some cases, totally unpredictable for me.

Mentioned direction changes occurs with negative handle's values.

Didn't figured it out earlier because the drawing is preceded with nice chunk of trigonometry, so the vector with a negative length and rotated by pi is the same vector. And then this math, which captured all of my attention, is somehow friendshipped with paperjs library.

Anyway, here's a code snippet demonstrating difference in behavior:

http://jsfiddle.net/DMKWH/

lehni commented 11 years ago

This is actually the right behavior: Setting length to negative values should flip around defined vectors.