Various changes to #isCollinear(), #isOrthogonal(), #isArc()

- Rename #isArc() - > #isOrthogonalArc()
- Implement versions for Curve
- Write proper documentation
This commit is contained in:
Jürg Lehni 2015-08-17 14:33:48 +02:00
parent f8314f927e
commit 4ee68e5782
3 changed files with 49 additions and 8 deletions

View file

@ -314,6 +314,29 @@ var Curve = Base.extend(/** @lends Curve# */{
return this._segment1.isLinear();
},
/**
* Checks if the the two curves describe lines that are collinear, meaning
* they run in parallel.
*
* @param {Curve} the other curve to check against
* @return {Boolean} {@true if the two lines are collinear}
* @see Segment#isCollinear(segment)
*/
isCollinear: function(curve) {
return this._segment1.isCollinear(curve._segment1);
},
/**
* Checks if the curve describes an orthogonal arc, as used in the
* construction of circles and ellipses.
*
* @return {Boolean} {@true if the curve describes an orthogonal arc}
* @see Segment#isOrthogonalArc()
*/
isOrthogonalArc: function() {
return this._segment1.isOrthogonalArc();
},
// DOCS: Curve#getIntersections()
getIntersections: function(curve) {
return Curve.filterIntersections(Curve.getIntersections(

View file

@ -1418,7 +1418,7 @@ var Path = PathItem.extend(/** @lends Path# */{
}
function isArc(i) {
return segments[i].isArc();
return segments[i].isOrthogonalArc();
}
function getDistance(i, j) {

View file

@ -268,8 +268,12 @@ var Segment = Base.extend(/** @lends Segment# */{
},
/**
* Returns true if the the two segments are the beginning of two lines and
* if these two lines are running parallel.
* Checks if the the two segments are the beginning of two lines that are
* collinear, meaning they run in parallel.
*
* @param {Segment} the other segment to check against
* @return {Boolean} {@true if the two lines are collinear}
* @see Curve#isCollinear(curve)
*/
isCollinear: function(segment) {
var next1 = this.getNext(),
@ -283,6 +287,13 @@ var Segment = Base.extend(/** @lends Segment# */{
// TODO: Remove version with typo after a while (deprecated June 2015)
isColinear: '#isCollinear',
/**
* Checks if the segment is connecting two lines that are orthogonal,
* meaning they connect at an 90° angle.
*
* @return {Boolean} {@true if the two lines connected by this segment are
* orthogonal}
*/
isOrthogonal: function() {
var prev = this.getPrevious(),
next = this.getNext();
@ -293,16 +304,20 @@ var Segment = Base.extend(/** @lends Segment# */{
},
/**
* Returns true if the segment at the given index is the beginning of an
* orthogonal arc segment. The code looks at the length of the handles and
* their relation to the distance to the imaginary corner point. If the
* relation is kappa, then it's an arc.
* Checks if the segment is the beginning of an orthogonal arc, as used in
* the construction of circles and ellipses.
*
* @return {Boolean} {@true if the segment is the beginning of an orthogonal
* arc}
* @see Curve#isOrthogonalArc()
*/
isArc: function() {
isOrthogonalArc: function() {
var next = this.getNext(),
handle1 = this._handleOut,
handle2 = next._handleIn,
kappa = /*#=*/Numerical.KAPPA;
// Look at the length of the handles and their relation to the distance
// to the imaginary corner point and see if it their relation is kappa.
if (handle1.isOrthogonal(handle2)) {
var from = this._point,
to = next._point,
@ -318,6 +333,9 @@ var Segment = Base.extend(/** @lends Segment# */{
return false;
},
// TODO: Remove a while (deprecated August 2015)
isArc: '#isOrthogonalArc',
_selectionState: 0,
/**