ENH: fix compiling issue

Don't know why this file is missing when cherry-pick...

Signed-off-by: salt.wei <salt.wei@bambulab.com>
Change-Id: Iddfba50ef885fa08078bb9723a6ae2d5d5d0289d
This commit is contained in:
salt.wei 2023-03-10 17:35:24 +08:00 committed by Lane.Wei
parent c65a5f8bf5
commit ad43a54e3d
1 changed files with 29 additions and 2 deletions

View File

@ -54,11 +54,11 @@ double distance_to_squared(const L &line, const Vec<Dim<L>, Scalar<L>> &point, V
// We find projection of this point onto the line. // We find projection of this point onto the line.
// It falls where t = [(this-a) . (b-a)] / |b-a|^2 // It falls where t = [(this-a) . (b-a)] / |b-a|^2
const double t = va.dot(v) / l2; const double t = va.dot(v) / l2;
if (t < 0.0) { if (t <= 0.0) {
// beyond the 'a' end of the segment // beyond the 'a' end of the segment
*nearest_point = get_a(line); *nearest_point = get_a(line);
return va.squaredNorm(); return va.squaredNorm();
} else if (t > 1.0) { } else if (t >= 1.0) {
// beyond the 'b' end of the segment // beyond the 'b' end of the segment
*nearest_point = get_b(line); *nearest_point = get_b(line);
return (point - get_b(line)).template cast<double>().squaredNorm(); return (point - get_b(line)).template cast<double>().squaredNorm();
@ -120,6 +120,33 @@ double distance_to_infinite(const L &line, const Vec<Dim<L>, Scalar<L>> &point)
return std::sqrt(distance_to_infinite_squared(line, point)); return std::sqrt(distance_to_infinite_squared(line, point));
} }
template<class L> bool intersection(const L &l1, const L &l2, Vec<Dim<L>, Scalar<L>> *intersection_pt)
{
using Floating = typename std::conditional<std::is_floating_point<Scalar<L>>::value, Scalar<L>, double>::type;
using VecType = const Vec<Dim<L>, Floating>;
const VecType v1 = (l1.b - l1.a).template cast<Floating>();
const VecType v2 = (l2.b - l2.a).template cast<Floating>();
Floating denom = cross2(v1, v2);
if (fabs(denom) < EPSILON)
#if 0
// Lines are collinear. Return true if they are coincident (overlappign).
return ! (fabs(nume_a) < EPSILON && fabs(nume_b) < EPSILON);
#else
return false;
#endif
const VecType v12 = (l1.a - l2.a).template cast<Floating>();
Floating nume_a = cross2(v2, v12);
Floating nume_b = cross2(v1, v12);
Floating t1 = nume_a / denom;
Floating t2 = nume_b / denom;
if (t1 >= 0 && t1 <= 1.0f && t2 >= 0 && t2 <= 1.0f) {
// Get the intersection point.
(*intersection_pt) = (l1.a.template cast<Floating>() + t1 * v1).template cast<Scalar<L>>();
return true;
}
return false; // not intersecting
}
} // namespace line_alg } // namespace line_alg
class Line class Line