OrcaSlicer latest
OrcaSlicer
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 = 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 )
84{
85 return std::sqrt(distance_to_squared(line, point));
86}
double distance_to_squared(const L &line, const Vec< Dim< L >, Scalar< L > > &point, Vec< Dim< L >, Scalar< L > > *nearest_point)
Definition Line.hpp:46

References Dim, distance_to_squared(), and L.

Referenced by Slic3r::create_exclude_mask(), Slic3r::evaluate_support_arch_cost(), and Slic3r::FillAdaptive::multiline_paths().

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 )
122{
123 return std::sqrt(distance_to_infinite_squared(line, point));
124}
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:91

References Dim, distance_to_infinite_squared(), and L.

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 )
113{
114 Vec<Dim<L>, Scalar<L>> nearest_point;
115 return distance_to_infinite_squared<L>(line, point, &nearest_point);
116}
typename Traits< remove_cvref_t< L > >::Scalar Scalar
Definition Line.hpp:39
Mat< N, 1, T > Vec
Definition Point.hpp:48

References Dim, distance_to_infinite_squared(), and L.

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 )
92{
93 const Vec<Dim<L>, double> v = (get_b(line) - get_a(line)).template cast<double>();
94 const Vec<Dim<L>, double> va = (point - get_a(line)).template cast<double>();
95 const double l2 = v.squaredNorm(); // avoid a sqrt
96 if (l2 == 0.) {
97 // a == b case
98 *closest_point = get_a(line);
99 return va.squaredNorm();
100 }
101 // Consider the line extending the segment, parameterized as a + t (b - a).
102 // We find projection of this point onto the line.
103 // It falls where t = [(this-a) . (b-a)] / |b-a|^2
104 const double t = va.dot(v) / l2;
105 *closest_point = (get_a(line).template cast<double>() + t * v).template cast<Scalar<L>>();
106 return (t * v - va).squaredNorm();
107}
auto get_b(L &&l)
Definition Line.hpp:42
auto get_a(L &&l)
Definition Line.hpp:41
T l2(const boost::geometry::model::d2::point_xy< T > &v)
Definition ExtrusionSimulator.cpp:177
auto cast(const BoundingBoxBase< Tin > &b)
Definition BoundingBox.hpp:299

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

Referenced by distance_to_infinite(), Slic3r::Line::distance_to_infinite_squared(), Slic3r::Line::distance_to_infinite_squared(), and 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 )
77{
78 Vec<Dim<L>, Scalar<L>> nearest_point;
79 return distance_to_squared<L>(line, point, &nearest_point);
80}

References Dim, distance_to_squared(), and L.

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

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

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

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)
Definition Line.hpp:28

References get_a(), and L.

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)

References get_b(), and L.

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 )
127{
128 using Floating = typename std::conditional<std::is_floating_point<Scalar<L>>::value, Scalar<L>, double>::type;
129 using VecType = const Vec<Dim<L>, Floating>;
130 const VecType v1 = (l1.b - l1.a).template cast<Floating>();
131 const VecType v2 = (l2.b - l2.a).template cast<Floating>();
132 Floating denom = cross2(v1, v2);
133 if (fabs(denom) < EPSILON)
134#if 0
135 // Lines are collinear. Return true if they are coincident (overlappign).
136 return ! (fabs(nume_a) < EPSILON && fabs(nume_b) < EPSILON);
137#else
138 return false;
139#endif
140 const VecType v12 = (l1.a - l2.a).template cast<Floating>();
141 Floating nume_a = cross2(v2, v12);
142 Floating nume_b = cross2(v1, v12);
143 Floating t1 = nume_a / denom;
144 Floating t2 = nume_b / denom;
145 if (t1 >= 0 && t1 <= 1.0f && t2 >= 0 && t2 <= 1.0f) {
146 // Get the intersection point.
147 (*intersection_pt) = (l1.a.template cast<Floating>() + t1 * v1).template cast<Scalar<L>>();
148 return true;
149 }
150 return false; // not intersecting
151}
#define EPSILON
Definition ColorUtils.cpp:64
int32_t cross2(const Eigen::MatrixBase< Eigen::Matrix< int32_t, 2, 1, Options > > &v1, const Eigen::MatrixBase< Eigen::Matrix< int32_t, 2, 1, Options > > &v2)=delete

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

Referenced by Slic3r::WipeTowerIntegration::generate_path_to_wipe_tower(), 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