mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -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) {
|
intersect: function(line) {
|
||||||
var cross = this.vector.cross(line.vector);
|
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;
|
return null;
|
||||||
var v = line.point.subtract(this.point),
|
var v = line.point.subtract(this.point),
|
||||||
t1 = v.cross(line.vector) / cross,
|
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.
|
// 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.TOLERANCE,
|
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
|
||||||
|
|
|
@ -63,6 +63,9 @@ var Numerical = new function() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
TOLERANCE: 10e-6,
|
TOLERANCE: 10e-6,
|
||||||
|
// Precision when comparing against 0
|
||||||
|
// TODO: Find a good value
|
||||||
|
EPSILON: 10e-12,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gauss-Legendre Numerical Integration
|
* Gauss-Legendre Numerical Integration
|
||||||
|
|
Loading…
Reference in a new issue