From bf9acd4499f52158c7709e0cea4de7cb3e3c1918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 19 Apr 2013 18:57:31 -0700 Subject: [PATCH] Correct Numerical.KAPPA value. --- src/item/Shape.js | 10 +++++----- src/path/Path.Constructors.js | 2 +- src/svg/SvgExport.js | 7 ++++--- src/util/Numerical.js | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/item/Shape.js b/src/item/Shape.js index 6d8f7821..580c4124 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -43,11 +43,11 @@ var Shape = this.Shape = Item.extend(/** @lends Shape# */{ ctx.arc(0, 0, width, 0, Math.PI * 2, true); break; case 'ellipse': - var kappa = Numerical.KAPPA, - cx = width * kappa, - cy = height * kappa, - mx = width / 2, - my = height / 2; + var mx = width / 2, + my = height / 2, + kappa = Numerical.KAPPA, + cx = mx * kappa, + cy = my * kappa; ctx.moveTo(0, my); ctx.bezierCurveTo(0, my - cy, mx - cx, 0, mx, 0); ctx.bezierCurveTo(mx + cx, 0, width, my - cy, width, my); diff --git a/src/path/Path.Constructors.js b/src/path/Path.Constructors.js index ce4e7dae..2a6fb34f 100644 --- a/src/path/Path.Constructors.js +++ b/src/path/Path.Constructors.js @@ -56,7 +56,7 @@ Path.inject({ statics: new function() { return path; } - var kappa = Numerical.KAPPA; + var kappa = Numerical.KAPPA / 2; var ellipseSegments = [ new Segment([0, 0.5], [0, kappa ], [0, -kappa]), diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index 002c7349..8d9082ad 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -120,7 +120,8 @@ new function() { var segment = segments[i], next = segment.getNext(), handle1 = segment._handleOut, - handle2 = next._handleIn; + handle2 = next._handleIn, + kappa = Numerical.KAPPA; if (handle1.isOrthogonal(handle2)) { var from = segment._point, to = next._point, @@ -129,9 +130,9 @@ new function() { corner = new Line(from, handle1).intersect( new Line(to, handle2)); return corner && Numerical.isZero(handle1.getLength() / - corner.subtract(from).getLength() - Numerical.KAPPA) + corner.subtract(from).getLength() - kappa) && Numerical.isZero(handle2.getLength() / - corner.subtract(to).getLength() - Numerical.KAPPA); + corner.subtract(to).getLength() - kappa); } } diff --git a/src/util/Numerical.js b/src/util/Numerical.js index 5c530064..a13f5f16 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -69,7 +69,7 @@ var Numerical = this.Numerical = new function() { // TODO: Find a good value EPSILON: 10e-12, // Kappa, see: http://www.whizkidtech.redprince.net/bezier/circle/kappa/ - KAPPA: 2 * (sqrt(2) - 1) / 3, + KAPPA: 4 * (sqrt(2) - 1) / 3, /** * Check if the value is 0, within a tolerance defined by