【发布时间】:2014-07-11 19:34:10
【问题描述】:
引用 here 并更新为与 Snap.svg here 一起使用,我想更好地了解所提供的 gradSearch 函数的实际工作原理(这有点超出我的想象),以及是否有任何好的替代方案采用这种方法?
gradSearch = function (l0, pt) {
l0 = l0 + totLen;
var l1 = l0,
dist0 = dist(path.getPointAtLength(l0 % totLen), pt),
dist1,
searchDir;
if (dist(path.getPointAtLength((l0 - searchDl) % totLen), pt) >
dist(path.getPointAtLength((l0 + searchDl) % totLen), pt)) {
searchDir = searchDl;
} else {
searchDir = -searchDl;
}
l1 += searchDir;
dist1 = dist(path.getPointAtLength(l1 % totLen), pt);
while (dist1 < dist0) {
dist0 = dist1;
l1 += searchDir;
dist1 = dist(path.getPointAtLength(l1 % totLen), pt);
}
l1 -= searchDir;
return (l1 % totLen);
}
【问题讨论】:
-
是的..这是东西,我也在寻找。该函数适用于 SVG 中的任何给定路径。我也想重用它,但是解释起来很困难。
标签: javascript html svg raphael snap.svg