mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Improve precision of Line#intersect() and other parts that check for a divisor to not be 0, by comparing against the new Numerical.EPSILON rather than Numerical.TOLERANCE.
This commit is contained in:
parent
1519a1d220
commit
3a7c5286b5
3 changed files with 6 additions and 2 deletions
|
@ -74,7 +74,8 @@ var Line = this.Line = Base.extend(/** @lends Line# */{
|
|||
*/
|
||||
intersect: function(line) {
|
||||
var cross = this.vector.cross(line.vector);
|
||||
if (Math.abs(cross) <= Numerical.TOLERANCE)
|
||||
// Avoid divisions by 0, and errors when getting too close to 0
|
||||
if (Math.abs(cross) <= Numerical.EPSILON)
|
||||
return null;
|
||||
var v = line.point.subtract(this.point),
|
||||
t1 = v.cross(line.vector) / cross,
|
||||
|
|
|
@ -93,7 +93,7 @@ var PathFitter = Base.extend({
|
|||
|
||||
// Use least-squares method to find Bezier control points for region.
|
||||
generateBezier: function(first, last, uPrime, tan1, tan2) {
|
||||
var epsilon = Numerical.TOLERANCE,
|
||||
var epsilon = Numerical.EPSILON,
|
||||
pt1 = this.points[first],
|
||||
pt2 = this.points[last],
|
||||
// Create the C and X matrices
|
||||
|
|
|
@ -63,6 +63,9 @@ var Numerical = new function() {
|
|||
|
||||
return {
|
||||
TOLERANCE: 10e-6,
|
||||
// Precision when comparing against 0
|
||||
// TODO: Find a good value
|
||||
EPSILON: 10e-12,
|
||||
|
||||
/**
|
||||
* Gauss-Legendre Numerical Integration
|
||||
|
|
Loading…
Reference in a new issue