mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Merge pull request #811 from sapics/faster-nearest-parameter
Faster curve.getNearestParameter when curve has no handles
This commit is contained in:
commit
cbefa668f4
1 changed files with 12 additions and 0 deletions
|
@ -645,6 +645,18 @@ statics: {
|
||||||
},
|
},
|
||||||
|
|
||||||
getNearestParameter: function(v, point) {
|
getNearestParameter: function(v, point) {
|
||||||
|
if (!this.hasHandles(v)) {
|
||||||
|
var p1x = v[0], p1y = v[1],
|
||||||
|
p2x = v[6], p2y = v[7],
|
||||||
|
v12x = p2x - p1x, v12y = p2y - p1x,
|
||||||
|
t = ((point.x - p1x) * v12x + (point.y - p1y) * v12y) /
|
||||||
|
(v12x * v12x + v12y * v12y),
|
||||||
|
epsilon = /*#=*/Numerical.EPSILON;
|
||||||
|
if (t < epsilon) return 0;
|
||||||
|
if (t + epsilon > 1) return 1;
|
||||||
|
return 0.5 - Math.cos(Math.acos(2 * t - 1) / 3 + Math.PI * 4 / 3) || 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
var count = 100,
|
var count = 100,
|
||||||
minDist = Infinity,
|
minDist = Infinity,
|
||||||
minT = 0;
|
minT = 0;
|
||||||
|
|
Loading…
Reference in a new issue