mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 21:58:03 -06:00
Add dedicated tests for support point generation
This commit is contained in:
parent
1172dfcb40
commit
4ef52af906
10 changed files with 285 additions and 21 deletions
|
@ -33,24 +33,6 @@ bool Line::intersection_infinite(const Line &other, Point* point) const
|
|||
return true;
|
||||
}
|
||||
|
||||
// Distance to the closest point of line.
|
||||
double Line::distance_to_squared(const Point &point, const Point &a, const Point &b)
|
||||
{
|
||||
const Vec2d v = (b - a).cast<double>();
|
||||
const Vec2d va = (point - a).cast<double>();
|
||||
const double l2 = v.squaredNorm(); // avoid a sqrt
|
||||
if (l2 == 0.0)
|
||||
// a == b case
|
||||
return va.squaredNorm();
|
||||
// Consider the line extending the segment, parameterized as a + t (b - a).
|
||||
// We find projection of this point onto the line.
|
||||
// It falls where t = [(this-a) . (b-a)] / |b-a|^2
|
||||
const double t = va.dot(v) / l2;
|
||||
if (t < 0.0) return va.squaredNorm(); // beyond the 'a' end of the segment
|
||||
else if (t > 1.0) return (point - b).cast<double>().squaredNorm(); // beyond the 'b' end of the segment
|
||||
return (t * v - va).squaredNorm();
|
||||
}
|
||||
|
||||
double Line::perp_distance_to(const Point &point) const
|
||||
{
|
||||
const Line &line = *this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue