Implement Segment#isLinear() and Path#isPolygon().

This commit is contained in:
Jürg Lehni 2012-11-04 00:03:49 -07:00
parent 5577e7e1ee
commit 1050e3314e
2 changed files with 19 additions and 1 deletions

View file

@ -231,7 +231,15 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
},
isEmpty: function() {
return this._segments.length == 0;
return this._segments.length === 0;
},
isPolygon: function() {
for (var i = 0, l = this._segments.length; i < l; i++) {
if (!this._segments[i].isLinear())
return false;
}
return true;
},
_apply: function(matrix) {

View file

@ -162,6 +162,16 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
// this.corner = !this._handleIn.isColinear(this._handleOut);
},
/**
* Checks whether the segment has no handles defined, meaning it connects
* two straight lines.
*
* @return {Boolean} {@true the segment is linear}
*/
isLinear: function() {
return this._handleIn.isZero() && this._handleOut.isZero();
},
_isSelected: function(point) {
var state = this._selectionState;
return point == this._point ? !!(state & SelectionState.POINT)