Export Numerical object and move KAPPA constant there.

This commit is contained in:
Jürg Lehni 2013-04-19 17:03:41 -07:00
parent 9cc0822477
commit 90f2614d52
4 changed files with 8 additions and 10 deletions

View file

@ -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;

View file

@ -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]),

View file

@ -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);
}
}

View file

@ -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