mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Add Path#getLength().
This commit is contained in:
parent
8b32aa9f09
commit
501e42fb9d
2 changed files with 11 additions and 1 deletions
|
@ -338,6 +338,14 @@ var Path = this.Path = PathItem.extend({
|
||||||
this.closed = ture;
|
this.closed = ture;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getLength: function() {
|
||||||
|
var curves = this.getCurves();
|
||||||
|
var length = 0;
|
||||||
|
for (var i = 0, l = curves.length; i < l; i++)
|
||||||
|
length += curves[i].getLength();
|
||||||
|
return length;
|
||||||
|
},
|
||||||
|
|
||||||
draw: function(ctx, param) {
|
draw: function(ctx, param) {
|
||||||
if (!param.compound)
|
if (!param.compound)
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
|
@ -559,6 +567,8 @@ var Path = this.Path = PathItem.extend({
|
||||||
function addJoin(segment, join) {
|
function addJoin(segment, join) {
|
||||||
var handleIn = segment.getHandleInIfSet(),
|
var handleIn = segment.getHandleInIfSet(),
|
||||||
handleOut = segment.getHandleOutIfSet();
|
handleOut = segment.getHandleOutIfSet();
|
||||||
|
// When both handles are set in a segment, the join setting is
|
||||||
|
// ignored and round is always used.
|
||||||
if (join == 'round' || handleIn && handleOut) {
|
if (join == 'round' || handleIn && handleOut) {
|
||||||
bounds = bounds.unite(new Rectangle(new Size(width, width))
|
bounds = bounds.unite(new Rectangle(new Size(width, width))
|
||||||
.setCenter(segment._point));
|
.setCenter(segment._point));
|
||||||
|
|
|
@ -6,5 +6,5 @@ test('path.length', function() {
|
||||||
new Segment(new Point(121, 334), new Point(-19, 38), new Point(30.7666015625, -61.53369140625)),
|
new Segment(new Point(121, 334), new Point(-19, 38), new Point(30.7666015625, -61.53369140625)),
|
||||||
new Segment(new Point(248, 320), new Point(-42, -74), new Point(42, 74))
|
new Segment(new Point(248, 320), new Point(-42, -74), new Point(42, 74))
|
||||||
]);
|
]);
|
||||||
compareNumbers(path.curves[0].length, 172.10122680664062);
|
compareNumbers(path.length, 172.10122680664062);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue