mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Introduce GEOMETRIC_EPSILON, for isOrthogonal(), isCollinear() and overlap checks.
Relates to #777
This commit is contained in:
parent
cdd0cee623
commit
fb5f8c0115
5 changed files with 6 additions and 14 deletions
|
@ -113,10 +113,8 @@ var Line = Base.extend(/** @lends Line# */{
|
|||
},
|
||||
|
||||
isCollinear: function(line) {
|
||||
// TODO: Tests showed that 1e-10 might work well here, but we want to
|
||||
// keep it in sync with Point#isCollinear()
|
||||
return this._vx * line._vy - this._vy * line._vx
|
||||
< /*#=*/Numerical.TOLERANCE;
|
||||
< /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
},
|
||||
|
||||
statics: /** @lends Line */{
|
||||
|
|
|
@ -702,10 +702,7 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @return {Boolean} {@true it is collinear}
|
||||
*/
|
||||
isCollinear: function(point) {
|
||||
// NOTE: Numerical.EPSILON is too small, breaking shape-path-shape
|
||||
// conversion test. But tolerance is probably too large?
|
||||
// TODO: Tests showed that 1e-10 might work well here.
|
||||
return Math.abs(this.cross(point)) < /*#=*/Numerical.TOLERANCE;
|
||||
return Math.abs(this.cross(point)) < /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
},
|
||||
|
||||
// TODO: Remove version with typo after a while (deprecated June 2015)
|
||||
|
@ -719,10 +716,7 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @return {Boolean} {@true it is orthogonal}
|
||||
*/
|
||||
isOrthogonal: function(point) {
|
||||
// NOTE: Numerical.EPSILON is too small, breaking shape-path-shape
|
||||
// conversion test.
|
||||
// TODO: Test if 1e-10 works here too? See #isCollinear()
|
||||
return Math.abs(this.dot(point)) < /*#=*/Numerical.TOLERANCE;
|
||||
return Math.abs(this.dot(point)) < /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1614,7 +1614,7 @@ new function() { // Scope for intersection using bezier fat-line clipping
|
|||
var line1 = new Line(v1[0], v1[1], v1[6], v1[7]),
|
||||
line2 = new Line(v2[0], v2[1], v2[6], v2[7]);
|
||||
if (!line1.isCollinear(line2) || line1.getDistance(line2.getPoint())
|
||||
> /*#=*/Numerical.GEOMETRY_TOLERANCE)
|
||||
> /*#=*/Numerical.GEOMETRIC_EPSILON)
|
||||
return false;
|
||||
} else if (straight1 ^ straight2) {
|
||||
// If one curve is straight, the other curve must be straight, too,
|
||||
|
|
|
@ -2502,7 +2502,6 @@ new function() { // PostScript-style drawing commands
|
|||
x = pt.x,
|
||||
y = pt.y,
|
||||
abs = Math.abs,
|
||||
epsilon = /*#=*/Numerical.EPSILON,
|
||||
rx = abs(radius.width),
|
||||
ry = abs(radius.height),
|
||||
rxSq = rx * rx,
|
||||
|
@ -2519,7 +2518,7 @@ new function() { // PostScript-style drawing commands
|
|||
}
|
||||
factor = (rxSq * rySq - rxSq * ySq - rySq * xSq) /
|
||||
(rxSq * ySq + rySq * xSq);
|
||||
if (abs(factor) < epsilon)
|
||||
if (abs(factor) < /*#=*/Numerical.EPSILON)
|
||||
factor = 0;
|
||||
if (factor < 0)
|
||||
throw new Error(
|
||||
|
|
|
@ -81,6 +81,7 @@ var Numerical = new function() {
|
|||
* range (see MACHINE_EPSILON).
|
||||
*/
|
||||
EPSILON: EPSILON,
|
||||
GEOMETRIC_EPSILON: 1e-9,
|
||||
/**
|
||||
* MACHINE_EPSILON for a double precision (Javascript Number) is
|
||||
* 2.220446049250313e-16. (try this in the js console)
|
||||
|
|
Loading…
Reference in a new issue