本文整理汇总了C++中Point2D::distanceSquaredTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2D::distanceSquaredTo方法的具体用法?C++ Point2D::distanceSquaredTo怎么用?C++ Point2D::distanceSquaredTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2D
的用法示例。
在下文中一共展示了Point2D::distanceSquaredTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nearest
Point2D KdTree::nearest(Node* x, const Point2D& p, Point2D& champ, double d, bool HNode) {
if (x == NULL) return champ;
if (d < x->rect_.distanceSquaredTo(p)) return champ;
double distance = x->p_.distanceSquaredTo(p);
if (distance < d) {
d = distance;
champ = x->p_;
}
// Decide if vertical or horizontal node
int cmp;
if (!HNode) cmp = x->comparebyX(p);
else cmp = x->comparebyY(p);
Point2D rchamp = champ;
double rd;
if (cmp < 0) {
rchamp = nearest(x->lb, p, champ, d, !HNode);
rd = rchamp.distanceSquaredTo(p);
if (rd < d) {
champ = rchamp;
d = rd;
}
champ = nearest(x->rt, p, champ, d, !HNode);
}
else { //if (cmp > 0) {
rchamp = nearest(x->rt, p, champ, d, !HNode);
rd = rchamp.distanceSquaredTo(p);
if (rd < d) {
champ = rchamp;
d = rd;
}
champ = nearest(x->lb, p, champ, d, !HNode);
}
return champ;
}