mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Switch to improved version of Line. getSignedDistance()
Based on the error analysis by @iconexperience outlined in #799
This commit is contained in:
parent
5c70f47b6f
commit
e92a71e8c7
1 changed files with 7 additions and 5 deletions
|
@ -182,11 +182,13 @@ var Line = Base.extend(/** @lends Line# */{
|
|||
vx -= px;
|
||||
vy -= py;
|
||||
}
|
||||
return Numerical.isZero(vx)
|
||||
? vy >= 0 ? px - x : x - px
|
||||
: Numerical.isZero(vy)
|
||||
? vx >= 0 ? y - py : py - y
|
||||
: (vx * (y - py) - vy * (x - px)) / Math.sqrt(vx * vx + vy * vy);
|
||||
// Based on the error analysis by @iconexperience outlined in
|
||||
// https://github.com/paperjs/paper.js/issues/799
|
||||
return vx == 0
|
||||
? vy >= 0 ? px - x : x - px
|
||||
: vy == 0
|
||||
? vx >= 0 ? y - py : py - y
|
||||
: (vx * (y - py) - vy * (x - px)) / Math.sqrt(vx * vx + vy * vy);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue