mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Some reworking of code and comments.
This commit is contained in:
parent
fe5916766a
commit
26e35322a4
3 changed files with 55 additions and 52 deletions
|
@ -300,7 +300,7 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
*/
|
||||
getLength: function() {
|
||||
if (this._length == null) {
|
||||
// Use simple point distance for linear curves
|
||||
// Use simple point distance for straight curves
|
||||
this._length = this.isLinear()
|
||||
? this._segment2._point.getDistance(this._segment1._point)
|
||||
: Curve.getLength(this.getValues(), 0, 1);
|
||||
|
@ -343,8 +343,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* Checks if this curve appears as a line. This can mean that it has no
|
||||
* handles defined, or that the handles run collinear with the line.
|
||||
* Checks if this curve appears as a straight line. This can mean that it
|
||||
* has no handles defined, or that the handles run collinear with the line.
|
||||
*
|
||||
* @return {Boolean} {@true if the curve is linear}
|
||||
* @see Segment#isLinear()
|
||||
|
|
|
@ -368,50 +368,6 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
return this._segments.length === 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if this path consists of only linear curves. This can mean that
|
||||
* the curves have no handles defined, or that the handles run collinear
|
||||
* with the line.
|
||||
*
|
||||
* @return {Boolean} {@true if the path is entirely linear}
|
||||
* @see Segment#isLinear()
|
||||
* @see Curve#isLinear()
|
||||
*/
|
||||
isLinear: function() {
|
||||
var segments = this._segments;
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
if (!segments[i].isLinear())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if none of the curves in the path define any curve handles.
|
||||
*
|
||||
* @return {Boolean} {@true if the path contains no curve handles}
|
||||
* @see Segment#hasHandles()
|
||||
* @see Curve#hasHandles()
|
||||
*/
|
||||
hasHandles: function() {
|
||||
var segments = this._segments;
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
if (segments[i].hasHandles())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears the path's handles by setting their coordinates to zero,
|
||||
* turning the path into a polygon (or a polyline if it isn't closed).
|
||||
*/
|
||||
clearHandles: function() {
|
||||
var segments = this._segments;
|
||||
for (var i = 0, l = segments.length; i < l; i++)
|
||||
segments[i].clearHandles();
|
||||
},
|
||||
|
||||
_transformContent: function(matrix) {
|
||||
var coords = new Array(6);
|
||||
for (var i = 0, l = this._segments.length; i < l; i++)
|
||||
|
@ -819,6 +775,50 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
// DOCS Path#clear()
|
||||
clear: '#removeSegments',
|
||||
|
||||
/**
|
||||
* Checks if none of the curves in the path define any curve handles.
|
||||
*
|
||||
* @return {Boolean} {@true if the path contains no curve handles}
|
||||
* @see Segment#hasHandles()
|
||||
* @see Curve#hasHandles()
|
||||
*/
|
||||
hasHandles: function() {
|
||||
var segments = this._segments;
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
if (segments[i].hasHandles())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears the path's handles by setting their coordinates to zero,
|
||||
* turning the path into a polygon (or a polyline if it isn't closed).
|
||||
*/
|
||||
clearHandles: function() {
|
||||
var segments = this._segments;
|
||||
for (var i = 0, l = segments.length; i < l; i++)
|
||||
segments[i].clearHandles();
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if this path consists of only straight curves. This can mean that
|
||||
* the curves have no handles defined, or that the handles run collinear
|
||||
* with the line.
|
||||
*
|
||||
* @return {Boolean} {@true if the path is entirely linear}
|
||||
* @see Segment#isLinear()
|
||||
* @see Curve#isLinear()
|
||||
*/
|
||||
isLinear: function() {
|
||||
var segments = this._segments;
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
if (!segments[i].isLinear())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* The approximate length of the path in points.
|
||||
*
|
||||
|
|
|
@ -251,11 +251,11 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* Checks if the curve that starts in this segment appears as a line. This
|
||||
* can mean that it has no handles defined, or that the handles run
|
||||
* collinear with the line.
|
||||
* Checks if the curve that starts in this segment appears as a straight
|
||||
* line. This can mean that it has no handles defined, or that the handles
|
||||
* run collinear with the line.
|
||||
*
|
||||
* @return {Boolean} {@true if the curve is linear}
|
||||
* @return {Boolean} {@true if the curve starting in this segment is linear}
|
||||
* @see Curve#isLinear()
|
||||
* @see Path#isLinear()
|
||||
*/
|
||||
|
@ -563,7 +563,10 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
|
||||
statics: {
|
||||
// These statics are shared between Segment and Curve, for versions of
|
||||
// these methods that are implemented in both places.
|
||||
// these methods that are implemented in both places. Most of these
|
||||
// methods relate more to the nature of curves than segments, but since
|
||||
// curves are made out of segments, and segments are the main path data
|
||||
// structure, while curves are 2nd class citizens, they are defined here
|
||||
|
||||
isLinear: function(seg1, seg2) {
|
||||
var l = seg2._point.subtract(seg1._point),
|
||||
|
|
Loading…
Reference in a new issue