Correct Numerical.KAPPA value.

This commit is contained in:
Jürg Lehni 2013-04-19 18:57:31 -07:00
parent 9da392a99c
commit bf9acd4499
4 changed files with 11 additions and 10 deletions

View file

@ -43,11 +43,11 @@ var Shape = this.Shape = Item.extend(/** @lends Shape# */{
ctx.arc(0, 0, width, 0, Math.PI * 2, true); ctx.arc(0, 0, width, 0, Math.PI * 2, true);
break; break;
case 'ellipse': case 'ellipse':
var kappa = Numerical.KAPPA, var mx = width / 2,
cx = width * kappa, my = height / 2,
cy = height * kappa, kappa = Numerical.KAPPA,
mx = width / 2, cx = mx * kappa,
my = height / 2; cy = my * kappa;
ctx.moveTo(0, my); ctx.moveTo(0, my);
ctx.bezierCurveTo(0, my - cy, mx - cx, 0, mx, 0); ctx.bezierCurveTo(0, my - cy, mx - cx, 0, mx, 0);
ctx.bezierCurveTo(mx + cx, 0, width, my - cy, width, my); ctx.bezierCurveTo(mx + cx, 0, width, my - cy, width, my);

View file

@ -56,7 +56,7 @@ Path.inject({ statics: new function() {
return path; return path;
} }
var kappa = Numerical.KAPPA; var kappa = Numerical.KAPPA / 2;
var ellipseSegments = [ var ellipseSegments = [
new Segment([0, 0.5], [0, kappa ], [0, -kappa]), new Segment([0, 0.5], [0, kappa ], [0, -kappa]),

View file

@ -120,7 +120,8 @@ new function() {
var segment = segments[i], var segment = segments[i],
next = segment.getNext(), next = segment.getNext(),
handle1 = segment._handleOut, handle1 = segment._handleOut,
handle2 = next._handleIn; handle2 = next._handleIn,
kappa = Numerical.KAPPA;
if (handle1.isOrthogonal(handle2)) { if (handle1.isOrthogonal(handle2)) {
var from = segment._point, var from = segment._point,
to = next._point, to = next._point,
@ -129,9 +130,9 @@ new function() {
corner = new Line(from, handle1).intersect( corner = new Line(from, handle1).intersect(
new Line(to, handle2)); new Line(to, handle2));
return corner && Numerical.isZero(handle1.getLength() / return corner && Numerical.isZero(handle1.getLength() /
corner.subtract(from).getLength() - Numerical.KAPPA) corner.subtract(from).getLength() - kappa)
&& Numerical.isZero(handle2.getLength() / && Numerical.isZero(handle2.getLength() /
corner.subtract(to).getLength() - Numerical.KAPPA); corner.subtract(to).getLength() - kappa);
} }
} }

View file

@ -69,7 +69,7 @@ var Numerical = this.Numerical = new function() {
// TODO: Find a good value // TODO: Find a good value
EPSILON: 10e-12, EPSILON: 10e-12,
// Kappa, see: http://www.whizkidtech.redprince.net/bezier/circle/kappa/ // 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 * Check if the value is 0, within a tolerance defined by