Use constant substitution for Numerical constants as well.

This commit is contained in:
Jürg Lehni 2012-12-27 18:36:59 +01:00
parent 050ca1dcb1
commit 57a9f4fc91
6 changed files with 12 additions and 11 deletions

View file

@ -494,7 +494,7 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
getRotation: function() { getRotation: function() {
var angle1 = -Math.atan2(this._b, this._d), var angle1 = -Math.atan2(this._b, this._d),
angle2 = Math.atan2(this._c, this._a); angle2 = Math.atan2(this._c, this._a);
return Math.abs(angle1 - angle2) < Numerical.EPSILON return Math.abs(angle1 - angle2) < /*#=*/ Numerical.EPSILON
? angle1 * 180 / Math.PI : undefined; ? angle1 * 180 / Math.PI : undefined;
}, },

View file

@ -687,7 +687,7 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
* @returns {Boolean} {@true it is parallel} * @returns {Boolean} {@true it is parallel}
*/ */
isColinear: function(point) { isColinear: function(point) {
return this.cross(point) < Numerical.TOLERANCE; return this.cross(point) < /*#=*/ Numerical.TOLERANCE;
}, },
/** /**
@ -698,7 +698,7 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
* @returns {Boolean} {@true it is orthogonal} * @returns {Boolean} {@true it is orthogonal}
*/ */
isOrthogonal: function(point) { isOrthogonal: function(point) {
return this.dot(point) < Numerical.TOLERANCE; return this.dot(point) < /*#=*/ Numerical.TOLERANCE;
}, },
/** /**

View file

@ -16,4 +16,5 @@
/*#*/ include('item/ChangeFlag.js'); /*#*/ include('item/ChangeFlag.js');
/*#*/ include('path/SelectionState.js'); /*#*/ include('path/SelectionState.js');
/*#*/ include('util/Numerical.js');
/*#*/ include('svg/constants.js'); /*#*/ include('svg/constants.js');

View file

@ -316,8 +316,8 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
getCrossings: function(point, roots) { getCrossings: function(point, roots) {
// Implement the crossing number algorithm: // Implement the crossing number algorithm:
// http://en.wikipedia.org/wiki/Point_in_polygon // http://en.wikipedia.org/wiki/Point_in_polygon
// Solve the y-axis cubic polynominal for point.y and count all // Solve the y-axis cubic polynomial for point.y and count all solutions
// solutions to the right of point.x as crossings. // to the right of point.x as crossings.
var vals = this.getValues(), var vals = this.getValues(),
count = Curve.solveCubic(vals, 1, point.y, roots), count = Curve.solveCubic(vals, 1, point.y, roots),
crossings = 0; crossings = 0;
@ -329,9 +329,9 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
// touching a tip. Passing 1 for Curve.evaluate()'s type means // touching a tip. Passing 1 for Curve.evaluate()'s type means
// we're calculating tangents, and then check their y-slope for // we're calculating tangents, and then check their y-slope for
// a change of direction: // a change of direction:
if (t < Numerical.TOLERANCE && Curve.evaluate( if (t < /*#=*/ Numerical.TOLERANCE && Curve.evaluate(
this.getPrevious().getValues(), 1, 1).y this.getPrevious().getValues(), 1, 1).y
* Curve.evaluate(vals, t, 1).y >= Numerical.TOLERANCE) * Curve.evaluate(vals, t, 1).y >= /*#=*/ Numerical.TOLERANCE)
continue; continue;
crossings++; crossings++;
} }
@ -657,7 +657,7 @@ new function() { // Scope for methods that require numerical integration
} }
return Numerical.findRoot(f, ds, return Numerical.findRoot(f, ds,
forward ? a + guess : b - guess, // Initial guess for x forward ? a + guess : b - guess, // Initial guess for x
a, b, 16, Numerical.TOLERANCE); a, b, 16, /*#=*/ Numerical.TOLERANCE);
} }
}; };
}, new function() { // Scope for nearest point on curve problem }, new function() { // Scope for nearest point on curve problem

View file

@ -95,7 +95,7 @@ var PathFitter = Base.extend({
// Use least-squares method to find Bezier control points for region. // Use least-squares method to find Bezier control points for region.
generateBezier: function(first, last, uPrime, tan1, tan2) { generateBezier: function(first, last, uPrime, tan1, tan2) {
var epsilon = Numerical.EPSILON, var epsilon = /*#=*/ Numerical.EPSILON,
pt1 = this.points[first], pt1 = this.points[first],
pt2 = this.points[last], pt2 = this.points[last],
// Create the C and X matrices // Create the C and X matrices
@ -194,7 +194,7 @@ var PathFitter = Base.extend({
diff = pt.subtract(point), diff = pt.subtract(point),
df = pt1.dot(pt1) + diff.dot(pt2); df = pt1.dot(pt1) + diff.dot(pt2);
// Compute f(u) / f'(u) // Compute f(u) / f'(u)
if (Math.abs(df) < Numerical.TOLERANCE) if (Math.abs(df) < /*#=*/ Numerical.TOLERANCE)
return u; return u;
// u = u - f(u) / f'(u) // u = u - f(u) / f'(u)
return u - diff.dot(pt1) / df; return u - diff.dot(pt1) / df;

View file

@ -62,7 +62,7 @@ var PathFlattener = Base.extend({
var x = curve[6] - curve[0], var x = curve[6] - curve[0],
y = curve[7] - curve[1], y = curve[7] - curve[1],
dist = Math.sqrt(x * x + y * y); dist = Math.sqrt(x * x + y * y);
if (dist > Numerical.TOLERANCE) { if (dist > /*#=*/ Numerical.TOLERANCE) {
this.length += dist; this.length += dist;
this.parts.push({ this.parts.push({
offset: this.length, offset: this.length,