Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::line_alg Namespace Reference

Classes

struct  Traits
 

Typedefs

template<class L >
using Scalar = typename Traits< remove_cvref_t< L > >::Scalar
 

Functions

template<class L >
auto get_a (L &&l)
 
template<class L >
auto get_b (L &&l)
 
template<class L >
double distance_to_squared (const L &line, const Vec< Dim< L >, Scalar< L > > &point, Vec< Dim< L >, Scalar< L > > *nearest_point)
 
template<class L >
double distance_to_squared (const L &line, const Vec< Dim< L >, Scalar< L > > &point)
 
template<class L >
double distance_to (const L &line, const Vec< Dim< L >, Scalar< L > > &point)
 
template<class L >
double distance_to_infinite_squared (const L &line, const Vec< Dim< L >, Scalar< L > > &point, Vec< Dim< L >, Scalar< L > > *closest_point)
 
template<class L >
double distance_to_infinite_squared (const L &line, const Vec< Dim< L >, Scalar< L > > &point)
 
template<class L >
double distance_to_infinite (const L &line, const Vec< Dim< L >, Scalar< L > > &point)
 
template<class L >
bool intersection (const L &l1, const L &l2, Vec< Dim< L >, Scalar< L > > *intersection_pt)
 

Variables

template<class L >
const constexpr int Dim = Traits<remove_cvref_t<L>>::Dim
 

Typedef Documentation

◆ Scalar

template<class L >
using Slic3r::line_alg::Scalar = typedef typename Traits<remove_cvref_t<L> >::Scalar

Function Documentation

◆ distance_to()

template<class L >
double Slic3r::line_alg::distance_to ( const L line,
const Vec< Dim< L >, Scalar< L > > &  point 
)
83{
84 return std::sqrt(distance_to_squared(line, point));
85}
double distance_to_squared(const L &line, const Vec< Dim< L >, Scalar< L > > &point, Vec< Dim< L >, Scalar< L > > *nearest_point)
Definition Line.hpp:43

References distance_to_squared().

Referenced by Slic3r::ExtrusionQualityEstimator::estimate_speed_from_extrusion_quality().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ distance_to_infinite()

template<class L >
double Slic3r::line_alg::distance_to_infinite ( const L line,
const Vec< Dim< L >, Scalar< L > > &  point 
)
121{
122 return std::sqrt(distance_to_infinite_squared(line, point));
123}
double distance_to_infinite_squared(const L &line, const Vec< Dim< L >, Scalar< L > > &point, Vec< Dim< L >, Scalar< L > > *closest_point)
Definition Line.hpp:90

References distance_to_infinite_squared().

+ Here is the call graph for this function:

◆ distance_to_infinite_squared() [1/2]

template<class L >
double Slic3r::line_alg::distance_to_infinite_squared ( const L line,
const Vec< Dim< L >, Scalar< L > > &  point 
)
112{
114 return distance_to_infinite_squared<L>(line, point, &nearest_point);
115}
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
typename Traits< remove_cvref_t< L > >::Scalar Scalar
Definition Line.hpp:36
std::pair< Point, bool > nearest_point(const Points &points, const Point &pt)
Definition Point.hpp:266

References Slic3r::nearest_point().

+ Here is the call graph for this function:

◆ distance_to_infinite_squared() [2/2]

template<class L >
double Slic3r::line_alg::distance_to_infinite_squared ( const L line,
const Vec< Dim< L >, Scalar< L > > &  point,
Vec< Dim< L >, Scalar< L > > *  closest_point 
)
91{
92 const Vec<Dim<L>, double> v = (get_b(line) - get_a(line)).template cast<double>();
93 const Vec<Dim<L>, double> va = (point - get_a(line)).template cast<double>();
94 const double l2 = v.squaredNorm(); // avoid a sqrt
95 if (l2 == 0.) {
96 // a == b case
97 *closest_point = get_a(line);
98 return va.squaredNorm();
99 }
100 // Consider the line extending the segment, parameterized as a + t (b - a).
101 // We find projection of this point onto the line.
102 // It falls where t = [(this-a) . (b-a)] / |b-a|^2
103 const double t = va.dot(v) / l2;
104 *closest_point = (get_a(line).template cast<double>() + t * v).template cast<Scalar<L>>();
105 return (t * v - va).squaredNorm();
106}
EIGEN_DEVICE_FUNC CastXpr< NewType >::Type cast() const
Definition CommonCwiseUnaryOps.h:62
auto get_b(L &&l)
Definition Line.hpp:39
auto get_a(L &&l)
Definition Line.hpp:38
T l2(const boost::geometry::model::d2::point_xy< T > &v)
Definition ExtrusionSimulator.cpp:166

References cast(), get_a(), get_b(), and Slic3r::l2().

Referenced by distance_to_infinite(), Slic3r::Line::distance_to_infinite_squared(), and Slic3r::Line::distance_to_infinite_squared().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ distance_to_squared() [1/2]

template<class L >
double Slic3r::line_alg::distance_to_squared ( const L line,
const Vec< Dim< L >, Scalar< L > > &  point 
)
76{
78 return distance_to_squared<L>(line, point, &nearest_point);
79}

References Slic3r::nearest_point().

+ Here is the call graph for this function:

◆ distance_to_squared() [2/2]

template<class L >
double Slic3r::line_alg::distance_to_squared ( const L line,
const Vec< Dim< L >, Scalar< L > > &  point,
Vec< Dim< L >, Scalar< L > > *  nearest_point 
)
inline
44{
45 using VecType = Vec<Dim<L>, double>;
46 const VecType v = (get_b(line) - get_a(line)).template cast<double>();
47 const VecType va = (point - get_a(line)).template cast<double>();
48 const double l2 = v.squaredNorm();
49 if (l2 == 0.0) {
50 // a == b case
51 *nearest_point = get_a(line);
52 return va.squaredNorm();
53 }
54 // Consider the line extending the segment, parameterized as a + t (b - a).
55 // We find projection of this point onto the line.
56 // It falls where t = [(this-a) . (b-a)] / |b-a|^2
57 const double t = va.dot(v);
58 if (t <= 0.0) {
59 // beyond the 'a' end of the segment
60 *nearest_point = get_a(line);
61 return va.squaredNorm();
62 } else if (t >= l2) {
63 // beyond the 'b' end of the segment
64 *nearest_point = get_b(line);
65 return (point - get_b(line)).template cast<double>().squaredNorm();
66 }
67
68 const VecType w = ((t / l2) * v).eval();
69 *nearest_point = (get_a(line).template cast<double>() + w).template cast<Scalar<L>>();
70 return (w - va).squaredNorm();
71}

References cast(), get_a(), get_b(), Slic3r::l2(), and Slic3r::nearest_point().

Referenced by Slic3r::clip_extrusion(), Slic3r::AABBTreeLines::detail::IndexedLinesDistancer< ALineType, ATreeType, AVectorType >::closest_point_to_origin(), Slic3r::FillAdaptive::connect_lines_using_hooks(), distance_to(), Slic3r::Line::distance_to_squared(), Slic3r::Line::distance_to_squared(), Slic3r::foot_pt(), Slic3r::FillLightning::Layer::getBestGroundingLocation(), Slic3r::line_rounded_thick_segment_collision(), Slic3r::mark_boundary_segments_overlapping_infill(), Slic3r::MinDistanceVisitor::operator()(), and Slic3r::Polyline::split_at().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_a()

template<class L >
auto Slic3r::line_alg::get_a ( L &&  l)
38{ return Traits<remove_cvref_t<L>>::get_a(l); }
Definition Line.hpp:25

References get_a().

Referenced by distance_to_infinite_squared(), distance_to_squared(), and get_a().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_b()

template<class L >
auto Slic3r::line_alg::get_b ( L &&  l)
39{ return Traits<remove_cvref_t<L>>::get_b(l); }

References get_b().

Referenced by distance_to_infinite_squared(), distance_to_squared(), and get_b().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ intersection()

template<class L >
bool Slic3r::line_alg::intersection ( const L l1,
const L l2,
Vec< Dim< L >, Scalar< L > > *  intersection_pt 
)
126{
127 using Floating = typename std::conditional<std::is_floating_point<Scalar<L>>::value, Scalar<L>, double>::type;
128 using VecType = const Vec<Dim<L>, Floating>;
129 const VecType v1 = (l1.b - l1.a).template cast<Floating>();
130 const VecType v2 = (l2.b - l2.a).template cast<Floating>();
131 Floating denom = cross2(v1, v2);
132 if (fabs(denom) < EPSILON)
133#if 0
134 // Lines are collinear. Return true if they are coincident (overlappign).
135 return ! (fabs(nume_a) < EPSILON && fabs(nume_b) < EPSILON);
136#else
137 return false;
138#endif
139 const VecType v12 = (l1.a - l2.a).template cast<Floating>();
140 Floating nume_a = cross2(v2, v12);
141 Floating nume_b = cross2(v1, v12);
142 Floating t1 = nume_a / denom;
143 Floating t2 = nume_b / denom;
144 if (t1 >= 0 && t1 <= 1.0f && t2 >= 0 && t2 <= 1.0f) {
145 // Get the intersection point.
146 (*intersection_pt) = (l1.a.template cast<Floating>() + t1 * v1).template cast<Scalar<L>>();
147 return true;
148 }
149 return false; // not intersecting
150}
static constexpr double EPSILON
Definition libslic3r.h:51
Derived::Scalar cross2(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:93

References cast(), Slic3r::cross2(), EPSILON, and Slic3r::l2().

Referenced by Slic3r::AABBTreeLines::detail::get_intersections_with_line(), and Slic3r::Line::intersection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ Dim

template<class L >
const constexpr int Slic3r::line_alg::Dim = Traits<remove_cvref_t<L>>::Dim
constexpr