mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Fix typo: #isColinear() -> #isCollinear()
Keeping misspelled version around for a while.
This commit is contained in:
parent
07b58e928e
commit
26cdbb6805
5 changed files with 29 additions and 19 deletions
|
@ -81,7 +81,7 @@ var Line = Base.extend(/** @lends Line# */{
|
|||
* @param {Line} line
|
||||
* @param {Boolean} [isInfinite=false]
|
||||
* @return {Point} the intersection point of the lines, {@code undefined}
|
||||
* if the two lines are colinear, or {@code null} if they don't intersect.
|
||||
* if the two lines are collinear, or {@code null} if they don't intersect.
|
||||
*/
|
||||
intersect: function(line, isInfinite) {
|
||||
return Line.intersect(
|
||||
|
|
|
@ -695,16 +695,21 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* Checks if the vector represented by this point is colinear (parallel) to
|
||||
* Checks if the vector represented by this point is collinear (parallel) to
|
||||
* another vector.
|
||||
*
|
||||
* @param {Point} point the vector to check against
|
||||
* @return {Boolean} {@true it is colinear}
|
||||
* @return {Boolean} {@true it is collinear}
|
||||
*/
|
||||
isColinear: function(point) {
|
||||
isCollinear: function(point) {
|
||||
// NOTE: Numerical.EPSILON is too small, breaking shape-path-shape
|
||||
// conversion test.
|
||||
return Math.abs(this.cross(point)) < /*#=*/Numerical.TOLERANCE;
|
||||
},
|
||||
|
||||
// TODO: Remove version with typo after a while (deprecated June 2015)
|
||||
isColinear: '#isCollinear',
|
||||
|
||||
/**
|
||||
* Checks if the vector represented by this point is orthogonal
|
||||
* (perpendicular) to another vector.
|
||||
|
@ -713,6 +718,8 @@ 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.
|
||||
return Math.abs(this.dot(point)) < /*#=*/Numerical.TOLERANCE;
|
||||
},
|
||||
|
||||
|
|
|
@ -1378,8 +1378,8 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
radius,
|
||||
topCenter;
|
||||
|
||||
function isColinear(i, j) {
|
||||
return segments[i].isColinear(segments[j]);
|
||||
function isCollinear(i, j) {
|
||||
return segments[i].isCollinear(segments[j]);
|
||||
}
|
||||
|
||||
function isOrthogonal(i) {
|
||||
|
@ -1398,12 +1398,12 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
// between straight objects (line, polyline, rect, and polygon) and
|
||||
// objects with curves(circle, ellipse, roundedRectangle).
|
||||
if (this.isPolygon() && segments.length === 4
|
||||
&& isColinear(0, 2) && isColinear(1, 3) && isOrthogonal(1)) {
|
||||
&& isCollinear(0, 2) && isCollinear(1, 3) && isOrthogonal(1)) {
|
||||
type = Shape.Rectangle;
|
||||
size = new Size(getDistance(0, 3), getDistance(0, 1));
|
||||
topCenter = segments[1]._point.add(segments[2]._point).divide(2);
|
||||
} else if (segments.length === 8 && isArc(0) && isArc(2) && isArc(4)
|
||||
&& isArc(6) && isColinear(1, 5) && isColinear(3, 7)) {
|
||||
&& isArc(6) && isCollinear(1, 5) && isCollinear(3, 7)) {
|
||||
// It's a rounded rectangle.
|
||||
type = Shape.Rectangle;
|
||||
size = new Size(getDistance(1, 6), getDistance(0, 3));
|
||||
|
@ -2706,7 +2706,7 @@ statics: {
|
|||
var handleIn = segment._handleIn,
|
||||
handleOut = segment._handleOut;
|
||||
if (join === 'round' || !handleIn.isZero() && !handleOut.isZero()
|
||||
&& handleIn.isColinear(handleOut)) {
|
||||
&& handleIn.isCollinear(handleOut)) {
|
||||
addRound(segment);
|
||||
} else {
|
||||
Path._addBevelJoin(segment, join, radius, miterLimit, add);
|
||||
|
|
|
@ -210,7 +210,7 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
// See #setPoint:
|
||||
this._handleIn.set(point.x, point.y);
|
||||
// Update corner accordingly
|
||||
// this.corner = !this._handleIn.isColinear(this._handleOut);
|
||||
// this.corner = !this._handleIn.isCollinear(this._handleOut);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -229,7 +229,7 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
// See #setPoint:
|
||||
this._handleOut.set(point.x, point.y);
|
||||
// Update corner accordingly
|
||||
// this.corner = !this._handleIn.isColinear(this._handleOut);
|
||||
// this.corner = !this._handleIn.isCollinear(this._handleOut);
|
||||
},
|
||||
|
||||
// TODO: Rename this to #corner?
|
||||
|
@ -253,21 +253,24 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
}
|
||||
},
|
||||
|
||||
// DOCS: #isColinear(segment), #isOrthogonal(), #isArc()
|
||||
// DOCS: #isCollinear(segment), #isOrthogonal(), #isArc()
|
||||
|
||||
/**
|
||||
* Returns true if the the two segments are the beginning of two lines and
|
||||
* if these two lines are running parallel.
|
||||
*/
|
||||
isColinear: function(segment) {
|
||||
isCollinear: function(segment) {
|
||||
var next1 = this.getNext(),
|
||||
next2 = segment.getNext();
|
||||
return this._handleOut.isZero() && next1._handleIn.isZero()
|
||||
&& segment._handleOut.isZero() && next2._handleIn.isZero()
|
||||
&& next1._point.subtract(this._point).isColinear(
|
||||
&& next1._point.subtract(this._point).isCollinear(
|
||||
next2._point.subtract(segment._point));
|
||||
},
|
||||
|
||||
// TODO: Remove version with typo after a while (deprecated June 2015)
|
||||
isColinear: '#isCollinear',
|
||||
|
||||
isOrthogonal: function() {
|
||||
var prev = this.getPrevious(),
|
||||
next = this.getNext();
|
||||
|
|
|
@ -134,18 +134,18 @@ test('equals()', function() {
|
|||
}, false);
|
||||
});
|
||||
|
||||
test('isColinear()', function() {
|
||||
test('isCollinear()', function() {
|
||||
equals(function() {
|
||||
return new Point(10, 5).isColinear(new Point(20, 10));
|
||||
return new Point(10, 5).isCollinear(new Point(20, 10));
|
||||
}, true);
|
||||
equals(function() {
|
||||
return new Point(5, 10).isColinear(new Point(-5, -10));
|
||||
return new Point(5, 10).isCollinear(new Point(-5, -10));
|
||||
}, true);
|
||||
equals(function() {
|
||||
return new Point(10, 10).isColinear(new Point(20, 10));
|
||||
return new Point(10, 10).isCollinear(new Point(20, 10));
|
||||
}, false);
|
||||
equals(function() {
|
||||
return new Point(10, 10).isColinear(new Point(10, -10));
|
||||
return new Point(10, 10).isCollinear(new Point(10, -10));
|
||||
}, false);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue