mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Simplify Point#project()
This commit is contained in:
parent
d7fb5cd512
commit
f91373efd8
1 changed files with 9 additions and 12 deletions
|
@ -721,6 +721,7 @@ var Point = Base.extend(/** @lends Point# */{
|
||||||
isOrthogonal: function(point) {
|
isOrthogonal: function(point) {
|
||||||
// NOTE: Numerical.EPSILON is too small, breaking shape-path-shape
|
// NOTE: Numerical.EPSILON is too small, breaking shape-path-shape
|
||||||
// conversion test.
|
// 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.TOLERANCE;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -767,23 +768,19 @@ var Point = Base.extend(/** @lends Point# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the projection of the point on another point.
|
* Returns the projection of the point onto another point.
|
||||||
* Both points are interpreted as vectors.
|
* Both points are interpreted as vectors.
|
||||||
*
|
*
|
||||||
* @param {Point} point
|
* @param {Point} point
|
||||||
* @return {Point} the projection of the point on another point
|
* @return {Point} the projection of the point onto another point
|
||||||
*/
|
*/
|
||||||
project: function(/* point */) {
|
project: function(/* point */) {
|
||||||
var point = Point.read(arguments);
|
var point = Point.read(arguments),
|
||||||
if (point.isZero()) {
|
scale = point.isZero() ? 0 : this.dot(point) / point.dot(point);
|
||||||
return new Point(0, 0);
|
return new Point(
|
||||||
} else {
|
point.x * scale,
|
||||||
var scale = this.dot(point) / point.dot(point);
|
point.y * scale
|
||||||
return new Point(
|
);
|
||||||
point.x * scale,
|
|
||||||
point.y * scale
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue