mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-13 16:33:28 -04:00
Make Line.isCollinear() / Point#isCollinear() more reliable.
This commit is contained in:
parent
cc7e60e51a
commit
515d4ff93d
2 changed files with 16 additions and 4 deletions
|
@ -113,8 +113,9 @@ var Line = Base.extend(/** @lends Line# */{
|
|||
},
|
||||
|
||||
isCollinear: function(line) {
|
||||
return this._vx * line._vy - this._vy * line._vx
|
||||
< /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
// TODO: Optimize:
|
||||
// return Point.isCollinear(this._vx, this._vy, line._vx, line._vy);
|
||||
return this.getVector().isCollinear(line.getVector());
|
||||
},
|
||||
|
||||
statics: /** @lends Line */{
|
||||
|
|
|
@ -702,7 +702,13 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @return {Boolean} {@true it is collinear}
|
||||
*/
|
||||
isCollinear: function(point) {
|
||||
return Math.abs(this.cross(point)) < /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
// NOTE: We use normalized vectors so that the epsilon comparison is
|
||||
// reliable. We could instead scale the epsilon based on the vector
|
||||
// length.
|
||||
// TODO: Optimize by creating a static Point.isCollinear() to be used
|
||||
// in Line.isCollinear() as well.
|
||||
return Math.abs(this.normalize().cross(point.normalize()))
|
||||
< /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
},
|
||||
|
||||
// TODO: Remove version with typo after a while (deprecated June 2015)
|
||||
|
@ -716,7 +722,12 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @return {Boolean} {@true it is orthogonal}
|
||||
*/
|
||||
isOrthogonal: function(point) {
|
||||
return Math.abs(this.dot(point)) < /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
// NOTE: We use normalized vectors so that the epsilon comparison is
|
||||
// reliable. We could instead scale the epsilon based on the vector
|
||||
// length.
|
||||
// TODO: Optimize
|
||||
return Math.abs(this.normalize().dot(point.normalize()))
|
||||
< /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue