mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Improve Curve#getParameterOf() to better handle very small curves.
See #799
This commit is contained in:
parent
61db3d9d01
commit
c1d0bd21b8
1 changed files with 7 additions and 5 deletions
|
@ -668,17 +668,19 @@ statics: {
|
||||||
|
|
||||||
getParameterOf: function(v, point) {
|
getParameterOf: function(v, point) {
|
||||||
var coords = [point.x, point.y],
|
var coords = [point.x, point.y],
|
||||||
roots = [];
|
roots = [],
|
||||||
|
epsilon = /*#=*/Numerical.GEOMETRIC_EPSILON;
|
||||||
for (var c = 0; c < 2; c++) {
|
for (var c = 0; c < 2; c++) {
|
||||||
var count = Curve.solveCubic(v, c, coords[c], roots, 0, 1);
|
var count = Curve.solveCubic(v, c, coords[c], roots, 0, 1);
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var t = roots[i],
|
var t = roots[i];
|
||||||
pt = Curve.getPoint(v, t);
|
if (point.isClose(Curve.getPoint(v, t), epsilon))
|
||||||
if (point.isClose(pt, /*#=*/Numerical.GEOMETRIC_EPSILON))
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return point.isClose(new Point(v[0], v[1]), epsilon) ? 0
|
||||||
|
: point.isClose(new Point(v[6], v[7]), epsilon) ? 1
|
||||||
|
: null;
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: Find better name
|
// TODO: Find better name
|
||||||
|
|
Loading…
Reference in a new issue