From 1b129feebfb5bcd34d9c7b78dbe69429ab575f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sundstr=C3=B6m?= Date: Tue, 27 Oct 2015 15:33:09 -0700 Subject: [PATCH] Handle exportSVG({ precision: 0 }) correctly --- src/util/Formatter.js | 2 +- test/tests/SVGExport.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/util/Formatter.js b/src/util/Formatter.js index 320828a5..969140e7 100644 --- a/src/util/Formatter.js +++ b/src/util/Formatter.js @@ -20,7 +20,7 @@ var Formatter = Base.extend(/** @lends Formatter# */{ * @param {Number} [precision=5] the amount of fractional digits */ initialize: function(precision) { - this.precision = precision || 5; + this.precision = precision == null ? 5 : precision; this.multiplier = Math.pow(10, this.precision); }, diff --git a/test/tests/SVGExport.js b/test/tests/SVGExport.js index 29f53e6e..647bef32 100644 --- a/test/tests/SVGExport.js +++ b/test/tests/SVGExport.js @@ -103,3 +103,12 @@ test('Export SVG polyline', function() { })); }); +test('Export SVG path defaults to precision 5', function() { + var path = new Path('M0.123456789,1.9l0.8,1.1'); + equals(path.exportSVG({}).getAttribute('d'), 'M0.12346,1.9l0.8,1.1'); +}); + +test('Export SVG path at precision 0', function() { + var path = new Path('M0.123456789,1.9l0.8,1.1'); + equals(path.exportSVG({ precision: 0 }).getAttribute('d'), 'M0,2l1,1'); +});