From 90f2614d52ac2719ef609f472a6a2d21f1b28064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 19 Apr 2013 17:03:41 -0700 Subject: [PATCH] Export Numerical object and move KAPPA constant there. --- examples/Tools/SquareRounded.html | 2 +- src/path/Path.Constructors.js | 3 +-- src/svg/SvgExport.js | 9 +++------ src/util/Numerical.js | 4 +++- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/Tools/SquareRounded.html b/examples/Tools/SquareRounded.html index 1b3de8e9..90c94ff9 100644 --- a/examples/Tools/SquareRounded.html +++ b/examples/Tools/SquareRounded.html @@ -23,7 +23,7 @@ function checkValues() { var min = values.radius * 2; if (values.tolerance < min) values.tolerance = min; - handle = values.radius * 0.5522847498; // kappa + handle = values.radius * Numerical.KAPPA; } var path; diff --git a/src/path/Path.Constructors.js b/src/path/Path.Constructors.js index 9a195cfe..53517363 100644 --- a/src/path/Path.Constructors.js +++ b/src/path/Path.Constructors.js @@ -56,8 +56,7 @@ Path.inject({ statics: new function() { return path; } - // Kappa, see: http://www.whizkidtech.redprince.net/bezier/circle/kappa/ - var kappa = 2 * (Math.sqrt(2) - 1) / 3; + var kappa = Numerical.KAPPA; var ellipseSegments = [ new Segment([0, 0.5], [0, kappa ], [0, -kappa]), diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index a42288e9..002c7349 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -112,13 +112,10 @@ new function() { seg4._point.subtract(seg3._point)); } - // Kappa, see: http://www.whizkidtech.redprince.net/bezier/circle/kappa/ - var kappa = 4 * (Math.sqrt(2) - 1) / 3; - // Returns true if the segment at the given index is the beginning of // a orthogonal arc segment. The code is looking at the length of the // handles and their relation to the distance to the imaginary corner - // point. If the relation is kappa (see above), then it's an arc. + // point. If the relation is kappa, then it's an arc. function isArc(i) { var segment = segments[i], next = segment.getNext(), @@ -132,9 +129,9 @@ new function() { corner = new Line(from, handle1).intersect( new Line(to, handle2)); return corner && Numerical.isZero(handle1.getLength() / - corner.subtract(from).getLength() - kappa) + corner.subtract(from).getLength() - Numerical.KAPPA) && Numerical.isZero(handle2.getLength() / - corner.subtract(to).getLength() - kappa); + corner.subtract(to).getLength() - Numerical.KAPPA); } } diff --git a/src/util/Numerical.js b/src/util/Numerical.js index 8ccf77f0..5c530064 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -10,7 +10,7 @@ * All rights reserved. */ -var Numerical = new function() { +var Numerical = this.Numerical = new function() { // Lookup tables for abscissas and weights with values for n = 2 .. 16. // As values are symetric, only store half of them and addapt algorithm @@ -68,6 +68,8 @@ var Numerical = new function() { // Precision when comparing against 0 // TODO: Find a good value EPSILON: 10e-12, + // Kappa, see: http://www.whizkidtech.redprince.net/bezier/circle/kappa/ + KAPPA: 2 * (sqrt(2) - 1) / 3, /** * Check if the value is 0, within a tolerance defined by