diff --git a/src/path/Segment.js b/src/path/Segment.js index 70b8b923..d1cbb837 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -130,7 +130,7 @@ var Segment = Base.extend(/** @lends Segment# */{ } else { point = arg0; } - } else if (typeof arg0 === 'object') { + } else if (arg0 == null || typeof arg0 === 'object') { // It doesn't matter if all of these arguments exist. // new SegmentPoint() produces creates points with (0, 0) otherwise. point = arg0; diff --git a/test/tests/Segment.js b/test/tests/Segment.js index 24ce21e9..3a2107af 100644 --- a/test/tests/Segment.js +++ b/test/tests/Segment.js @@ -12,6 +12,11 @@ QUnit.module('Segment'); +test('new Segment()', function() { + var segment = new Segment(null, null, null); + equals(segment.toString(), '{ point: { x: 0, y: 0 } }'); +}); + test('new Segment(point)', function() { var segment = new Segment(new Point(10, 10)); equals(segment.toString(), '{ point: { x: 10, y: 10 } }'); @@ -22,6 +27,11 @@ test('new Segment(x, y)', function() { equals(segment.toString(), '{ point: { x: 10, y: 10 } }'); }); +test('new Segment(undefined)', function() { + var segment = new Segment(undefined); + equals(segment.toString(), '{ point: { x: 0, y: 0 } }'); +}); + test('new Segment(object)', function() { var segment = new Segment({ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }); equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }'); @@ -32,6 +42,16 @@ test('new Segment(point, handleIn, handleOut)', function() { equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }'); }); +test('new Segment(null, null, null)', function() { + var segment = new Segment(null, null, null); + equals(segment.toString(), '{ point: { x: 0, y: 0 } }'); +}); + +test('new Segment(undefined, null, null)', function() { + var segment = new Segment(undefined, null, null); + equals(segment.toString(), '{ point: { x: 0, y: 0 } }'); +}); + test('new Segment(x, y, inX, inY, outX, outY)', function() { var segment = new Segment(10, 10, 5, 5, 15, 15); equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }');