From 501e42fb9da78c0adf141cde32897af27e5a49d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 6 Mar 2011 14:58:10 +0000 Subject: [PATCH] Add Path#getLength(). --- src/path/Path.js | 10 ++++++++++ test/tests/Path_Length.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/path/Path.js b/src/path/Path.js index 975d71f8..e581728e 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -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)); diff --git a/test/tests/Path_Length.js b/test/tests/Path_Length.js index 49a17dc4..905f9835 100644 --- a/test/tests/Path_Length.js +++ b/test/tests/Path_Length.js @@ -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); });