mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Fix imprecision in #getNearestLocation()
This commit is contained in:
parent
38f832a888
commit
eb32bad57e
1 changed files with 5 additions and 5 deletions
|
@ -843,11 +843,11 @@ statics: {
|
|||
getNearestLocation: function(point) {
|
||||
point = Point.read(arguments);
|
||||
var values = this.getValues(),
|
||||
step = 1 / 100,
|
||||
count = 100,
|
||||
tolerance = Numerical.TOLERANCE,
|
||||
minDist = Infinity,
|
||||
minT = 0,
|
||||
max = 1 + tolerance; // Accomodate imprecision
|
||||
max = 1 + tolerance; // Accomodate imprecision in comparisson
|
||||
|
||||
function refine(t) {
|
||||
if (t >= 0 && t <= 1) {
|
||||
|
@ -861,11 +861,11 @@ statics: {
|
|||
}
|
||||
}
|
||||
|
||||
for (var t = 0; t <= max; t += step)
|
||||
refine(t);
|
||||
for (var i = 0; i <= count; i++)
|
||||
refine(i / count);
|
||||
|
||||
// Now iteratively refine solution until we reach desired precision.
|
||||
step /= 2;
|
||||
var step = 1 / (count * 2);
|
||||
while (step > tolerance) {
|
||||
if (!refine(minT - step) && !refine(minT + step))
|
||||
step /= 2;
|
||||
|
|
Loading…
Reference in a new issue