本文整理汇总了C++中SkDPoint::distanceSquared方法的典型用法代码示例。如果您正苦于以下问题:C++ SkDPoint::distanceSquared方法的具体用法?C++ SkDPoint::distanceSquared怎么用?C++ SkDPoint::distanceSquared使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkDPoint
的用法示例。
在下文中一共展示了SkDPoint::distanceSquared方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nearestT
// from http://blog.gludion.com/2009/08/distance-to-quadratic-bezier-curve.html
// (currently only used by testing)
double SkDQuad::nearestT(const SkDPoint& pt) const {
SkDVector pos = fPts[0] - pt;
// search points P of bezier curve with PM.(dP / dt) = 0
// a calculus leads to a 3d degree equation :
SkDVector A = fPts[1] - fPts[0];
SkDVector B = fPts[2] - fPts[1];
B -= A;
double a = B.dot(B);
double b = 3 * A.dot(B);
double c = 2 * A.dot(A) + pos.dot(B);
double d = pos.dot(A);
double ts[3];
int roots = SkDCubic::RootsValidT(a, b, c, d, ts);
double d0 = pt.distanceSquared(fPts[0]);
double d2 = pt.distanceSquared(fPts[2]);
double distMin = SkTMin(d0, d2);
int bestIndex = -1;
for (int index = 0; index < roots; ++index) {
SkDPoint onQuad = ptAtT(ts[index]);
double dist = pt.distanceSquared(onQuad);
if (distMin > dist) {
distMin = dist;
bestIndex = index;
}
}
if (bestIndex >= 0) {
return ts[bestIndex];
}
return d0 < d2 ? 0 : 1;
}
示例2: closestTo
int SkIntersections::closestTo(double rangeStart, double rangeEnd, const SkDPoint& testPt,
double* closestDist) const {
int closest = -1;
*closestDist = SK_ScalarMax;
for (int index = 0; index < fUsed; ++index) {
if (!between(rangeStart, fT[0][index], rangeEnd)) {
continue;
}
const SkDPoint& iPt = fPt[index];
double dist = testPt.distanceSquared(iPt);
if (*closestDist > dist) {
*closestDist = dist;
closest = index;
}
}
return closest;
}