Use isZero() when checking for straight curves in Curve.getLength()

This commit is contained in:
Jürg Lehni 2013-09-23 08:13:32 -07:00
parent 123b6b680d
commit 1ee6bb7e79
2 changed files with 4 additions and 2 deletions

View file

@ -1009,8 +1009,10 @@ new function() { // Scope for methods that require numerical integration
a = 0;
if (b === undefined)
b = 1;
var isZero = Numerical.isZero;
// See if the curve is linear by checking p1 == c1 and p2 == c2
if (v[0] == v[2] && v[1] == v[3] && v[6] == v[4] && v[7] == v[5]) {
if (isZero(v[0] - v[2]) && isZero(v[1] - v[3])
&& isZero(v[6] - v[4]) && isZero(v[7] - v[5])) {
// Straight line
var dx = v[6] - v[0], // p2x - p1x
dy = v[7] - v[1]; // p2y - p1y

View file

@ -39,7 +39,7 @@ test('path.curves synchronisation', function() {
var length = path.curves[0].length;
ok(path.curves[0]._length, 'Curve length does not appear to be cached');
path.scale(2, [0, 0]);
equals(path.curves[0].length, 200, 'Curve length should be updated when path is transformed');
compareNumbers(path.curves[0].length, 200, 'Curve length should be updated when path is transformed');
var points = [];
for (var i = 0; i < 40; i++)