Add Path#getLength().

This commit is contained in:
Jürg Lehni 2011-03-06 14:58:10 +00:00
parent 8b32aa9f09
commit 501e42fb9d
2 changed files with 11 additions and 1 deletions

View file

@ -338,6 +338,14 @@ var Path = this.Path = PathItem.extend({
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) {
if (!param.compound)
ctx.beginPath();
@ -559,6 +567,8 @@ var Path = this.Path = PathItem.extend({
function addJoin(segment, join) {
var handleIn = segment.getHandleInIfSet(),
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) {
bounds = bounds.unite(new Rectangle(new Size(width, width))
.setCenter(segment._point));

View file

@ -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(248, 320), new Point(-42, -74), new Point(42, 74))
]);
compareNumbers(path.curves[0].length, 172.10122680664062);
compareNumbers(path.length, 172.10122680664062);
});