Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::Line Class Reference

#include <src/libslic3r/Line.hpp>

+ Inheritance diagram for Slic3r::Line:

Public Types

using Scalar = Point::Scalar
 

Public Member Functions

 Line ()
 
 Line (const Point &_a, const Point &_b)
 
 operator Lines () const
 
void scale (double factor)
 
void translate (const Point &v)
 
void translate (double x, double y)
 
void rotate (double angle, const Point &center)
 
void reverse ()
 
double length () const
 
Point midpoint () const
 
bool intersection_infinite (const Line &other, Point *point) const
 
bool operator== (const Line &rhs) const
 
double distance_to_squared (const Point &point) const
 
double distance_to_squared (const Point &point, Point *closest_point) const
 
double distance_to (const Point &point) const
 
double distance_to_infinite_squared (const Point &point, Point *closest_point) const
 
double perp_distance_to (const Point &point) const
 
bool parallel_to (double angle) const
 
bool parallel_to (const Line &line) const
 
bool perpendicular_to (double angle) const
 
bool perpendicular_to (const Line &line) const
 
double atan2_ () const
 
double orientation () const
 
double direction () const
 
Vector vector () const
 
Vector normal () const
 
bool intersection (const Line &line, Point *intersection) const
 
bool clip_with_bbox (const BoundingBox &bbox)
 
void extend (double offset)
 

Static Public Member Functions

static double distance_to_squared (const Point &point, const Point &a, const Point &b)
 
static double distance_to (const Point &point, const Point &a, const Point &b)
 
static double distance_to_infinite_squared (const Point &point, const Point &a, const Point &b)
 
static double distance_to_infinite (const Point &point, const Point &a, const Point &b)
 

Public Attributes

Point a
 
Point b
 

Static Public Attributes

static const constexpr int Dim = 2
 

Detailed Description

Member Typedef Documentation

◆ Scalar

using Slic3r::Line::Scalar = Point::Scalar

Constructor & Destructor Documentation

◆ Line() [1/2]

Slic3r::Line::Line ( )
inline
157{}

◆ Line() [2/2]

Slic3r::Line::Line ( const Point _a,
const Point _b 
)
inline
158: a(_a), b(_b) {}
Vector vector() const
Definition Line.hpp:181
Point b
Definition Line.hpp:198
Point a
Definition Line.hpp:197

Member Function Documentation

◆ atan2_()

double Slic3r::Line::atan2_ ( ) const
inline
178{ return atan2(this->b(1) - this->a(1), this->b(0) - this->a(0)); }

References a, b, and vector().

Referenced by direction(), and orientation().

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

◆ clip_with_bbox()

bool Slic3r::Line::clip_with_bbox ( const BoundingBox bbox)
98{
100 bool result = Geometry::liang_barsky_line_clipping<double>(this->a.cast<double>(), this->b.cast<double>(), BoundingBoxf(bbox.min.cast<double>(), bbox.max.cast<double>()), x0clip, x1clip);
101 if (result) {
102 this->a = x0clip.cast<coord_t>();
103 this->b = x1clip.cast<coord_t>();
104 }
105 return result;
106}
int32_t coord_t
Definition libslic3r.h:39
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:51

References a, b, Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, and vector().

+ Here is the call graph for this function:

◆ direction()

double Slic3r::Line::direction ( ) const
61{
62 double atan2 = this->atan2_();
63 return (fabs(atan2 - PI) < EPSILON) ? 0
64 : (atan2 < 0) ? (atan2 + PI)
65 : atan2;
66}
double atan2_() const
Definition Line.hpp:178
static constexpr double PI
Definition libslic3r.h:58
static constexpr double EPSILON
Definition libslic3r.h:51

References atan2_(), EPSILON, PI, and vector().

Referenced by Slic3r::BridgeDetector::bridge_direction_candidates(), Slic3r::Polyline::is_straight(), parallel_to(), and perpendicular_to().

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

◆ distance_to() [1/2]

double Slic3r::Line::distance_to ( const Point point) const
inline
171{ return distance_to(point, this->a, this->b); }
double distance_to(const Point &point) const
Definition Line.hpp:171

References a, b, and distance_to().

Referenced by distance_to(), Slic3r::remove_collinear(), and Slic3r::Geometry::MedialAxis::validate_edge().

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

◆ distance_to() [2/2]

static double Slic3r::Line::distance_to ( const Point point,
const Point a,
const Point b 
)
inlinestatic
190{ return sqrt(distance_to_squared(point, a, b)); }
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition ArrayCwiseUnaryOps.h:152
double distance_to_squared(const Point &point) const
Definition Line.hpp:169

References a, b, distance_to_squared(), and sqrt().

+ Here is the call graph for this function:

◆ distance_to_infinite()

static double Slic3r::Line::distance_to_infinite ( const Point point,
const Point a,
const Point b 
)
inlinestatic
195{ return sqrt(distance_to_infinite_squared(point, a, b)); }
double distance_to_infinite_squared(const Point &point, Point *closest_point) const
Definition Line.hpp:172

References a, b, distance_to_infinite_squared(), and sqrt().

Referenced by Slic3r::Arachne::ExtrusionLine::simplify(), and Slic3r::Arachne::simplify().

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

◆ distance_to_infinite_squared() [1/2]

static double Slic3r::Line::distance_to_infinite_squared ( const Point point,
const Point a,
const Point b 
)
inlinestatic
Line()
Definition Line.hpp:157
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 a, b, and Slic3r::line_alg::distance_to_infinite_squared().

+ Here is the call graph for this function:

◆ distance_to_infinite_squared() [2/2]

double Slic3r::Line::distance_to_infinite_squared ( const Point point,
Point closest_point 
) const
inline
172{ return line_alg::distance_to_infinite_squared(*this, point, closest_point); }

References Slic3r::line_alg::distance_to_infinite_squared().

Referenced by Slic3r::Arachne::VoronoiUtils::discretizeParabola(), distance_to_infinite(), Slic3r::Arachne::SkeletalTrapezoidationGraph::makeRib(), Slic3r::Arachne::ExtrusionLine::simplify(), and Slic3r::Arachne::simplify().

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

◆ distance_to_squared() [1/3]

double Slic3r::Line::distance_to_squared ( const Point point) const
inline
169{ return distance_to_squared(point, this->a, this->b); }

References a, b, and distance_to_squared().

Referenced by Slic3r::FillAdaptive::connect_lines_using_hooks(), distance_to(), distance_to_squared(), Slic3r::Arachne::SkeletalTrapezoidationGraph::insertRib(), Slic3r::PaintedLineVisitor::operator()(), and Slic3r::FillLightning::Node::straighten().

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

◆ distance_to_squared() [2/3]

static double Slic3r::Line::distance_to_squared ( const Point point,
const Point a,
const Point b 
)
inlinestatic
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 a, b, and Slic3r::line_alg::distance_to_squared().

+ Here is the call graph for this function:

◆ distance_to_squared() [3/3]

double Slic3r::Line::distance_to_squared ( const Point point,
Point closest_point 
) const
inline
170{ return line_alg::distance_to_squared(*this, point, closest_point); }

References Slic3r::line_alg::distance_to_squared().

+ Here is the call graph for this function:

◆ extend()

void Slic3r::Line::extend ( double  offset)
109{
110 Vector offset_vector = (offset * this->vector().cast<double>().normalized()).cast<coord_t>();
111 this->a -= offset_vector;
112 this->b += offset_vector;
113}
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:416
Point Vector
Definition Point.hpp:24

References a, b, Slic3r::offset(), and vector().

Referenced by Slic3r::FillAdaptive::create_offset_line(), and Slic3r::line_intersection_with_epsilon().

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

◆ intersection()

bool Slic3r::Line::intersection ( const Line line,
Point intersection 
) const
93{
95}
bool intersection(const Line &line, Point *intersection) const
Definition Line.cpp:92
bool intersection(const L &l1, const L &l2, Vec< Dim< L >, Scalar< L > > *intersection_pt)
Definition Line.hpp:125
T l2(const boost::geometry::model::d2::point_xy< T > &v)
Definition ExtrusionSimulator.cpp:166

References Slic3r::line_alg::intersection(), intersection(), and Slic3r::l2().

Referenced by priv::compute_intersections(), Slic3r::FillAdaptive::connect_lines_using_hooks(), Slic3r::Polygon::first_intersection(), intersection(), Slic3r::Polygon::intersection(), Slic3r::Polygon::intersections(), Slic3r::ConflictChecker::line_intersect(), Slic3r::line_intersection_with_epsilon(), and Slic3r::AllIntersectionsVisitor::operator()().

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

◆ intersection_infinite()

bool Slic3r::Line::intersection_infinite ( const Line other,
Point point 
) const
23{
24 Vec2d a1 = this->a.cast<double>();
25 Vec2d v12 = (other.a - this->a).cast<double>();
26 Vec2d v1 = (this->b - this->a).cast<double>();
27 Vec2d v2 = (other.b - other.a).cast<double>();
28 double denom = cross2(v1, v2);
29 if (std::fabs(denom) < EPSILON)
30 return false;
31 double t1 = cross2(v12, v2) / denom;
32 Vec2d result = (a1 + t1 * v1);
33 if (result.x() > std::numeric_limits<coord_t>::max() || result.x() < std::numeric_limits<coord_t>::lowest() ||
34 result.y() > std::numeric_limits<coord_t>::max() || result.y() < std::numeric_limits<coord_t>::lowest()) {
35 // Intersection has at least one of the coordinates much bigger (or smaller) than coord_t maximum value (or minimum).
36 // So it can not be stored into the Point without integer overflows. That could mean that input lines are parallel or near parallel.
37 return false;
38 }
39 *point = (result).cast<coord_t>();
40 return true;
41}
Derived::Scalar cross2(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:93

References a, b, Slic3r::cross2(), EPSILON, and vector().

Referenced by Slic3r::Arachne::ExtrusionLine::simplify(), and Slic3r::Arachne::simplify().

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

◆ length()

double Slic3r::Line::length ( ) const
inline
165{ return (b - a).cast<double>().norm(); }

References a, and b.

Referenced by Slic3r::sla::ConcaveHull::add_connector_rectangles(), Slic3r::BridgeDetector::detect_angle(), Slic3r::filter_colorized_polygon(), Slic3r::filter_painted_lines(), Slic3r::make_fill_polylines(), Slic3r::PaintedLineVisitor::operator()(), Slic3r::thick_lines_to_geometry(), Slic3r::PerimeterGenerator::thick_polyline_to_multi_path(), and Slic3r::AvoidCrossingPerimeters::travel_to().

+ Here is the caller graph for this function:

◆ midpoint()

Point Slic3r::Line::midpoint ( ) const
inline
166{ return (this->a + this->b) / 2; }

References a, and b.

◆ normal()

Vector Slic3r::Line::normal ( ) const
inline
182{ return Vector((this->b(1) - this->a(1)), -(this->b(0) - this->a(0))); }

References a, and b.

Referenced by Slic3r::avoid_perimeters_inner(), and Slic3r::thick_lines_to_geometry().

+ Here is the caller graph for this function:

◆ operator Lines()

Slic3r::Line::operator Lines ( ) const
inlineexplicit
159{ Lines lines; lines.emplace_back(*this); return lines; }
std::vector< Line > Lines
Definition Line.hpp:17

◆ operator==()

bool Slic3r::Line::operator== ( const Line rhs) const
inline
168{ return this->a == rhs.a && this->b == rhs.b; }

References a, and b.

◆ orientation()

double Slic3r::Line::orientation ( ) const
54{
55 double angle = this->atan2_();
56 if (angle < 0) angle = 2*PI + angle;
57 return angle;
58}
double angle(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:112

References Slic3r::angle(), atan2_(), and PI.

Referenced by Slic3r::Geometry::MedialAxis::validate_edge().

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

◆ parallel_to() [1/2]

bool Slic3r::Line::parallel_to ( const Line line) const
74{
75 const Vec2d v1 = (this->b - this->a).cast<double>();
76 const Vec2d v2 = (line.b - line.a).cast<double>();
77 return sqr(cross2(v1, v2)) < sqr(EPSILON) * v1.squaredNorm() * v2.squaredNorm();
78}
constexpr T sqr(T x)
Definition libslic3r.h:258

References a, b, Slic3r::cross2(), EPSILON, Slic3r::sqr(), and vector().

+ Here is the call graph for this function:

◆ parallel_to() [2/2]

bool Slic3r::Line::parallel_to ( double  angle) const
69{
71}
double direction() const
Definition Line.cpp:60
bool directions_parallel(double angle1, double angle2, double max_diff)
Definition Geometry.cpp:29

References direction(), and Slic3r::Geometry::directions_parallel().

+ Here is the call graph for this function:

◆ perp_distance_to()

double Slic3r::Line::perp_distance_to ( const Point point) const
44{
45 const Line &line = *this;
46 const Vec2d v = (line.b - line.a).cast<double>();
47 const Vec2d va = (point - line.a).cast<double>();
48 if (line.a == line.b)
49 return va.norm();
50 return std::abs(cross2(v, va)) / v.norm();
51}

References a, b, Slic3r::cross2(), and vector().

+ Here is the call graph for this function:

◆ perpendicular_to() [1/2]

bool Slic3r::Line::perpendicular_to ( const Line line) const
86{
87 const Vec2d v1 = (this->b - this->a).cast<double>();
88 const Vec2d v2 = (line.b - line.a).cast<double>();
89 return sqr(v1.dot(v2)) < sqr(EPSILON) * v1.squaredNorm() * v2.squaredNorm();
90}

References a, b, EPSILON, Slic3r::sqr(), and vector().

+ Here is the call graph for this function:

◆ perpendicular_to() [2/2]

bool Slic3r::Line::perpendicular_to ( double  angle) const
81{
83}
bool directions_perpendicular(double angle1, double angle2, double max_diff)
Definition Geometry.cpp:36

References direction(), and Slic3r::Geometry::directions_perpendicular().

+ Here is the call graph for this function:

◆ reverse()

void Slic3r::Line::reverse ( )
inline
164{ std::swap(this->a, this->b); }

References a, and b.

Referenced by Slic3r::PaintedLineVisitor::operator()().

+ Here is the caller graph for this function:

◆ rotate()

void Slic3r::Line::rotate ( double  angle,
const Point center 
)
inline
163{ this->a.rotate(angle, center); this->b.rotate(angle, center); }
void rotate(double angle)
Definition Point.hpp:188

References a, b, and Slic3r::Point::rotate().

+ Here is the call graph for this function:

◆ scale()

void Slic3r::Line::scale ( double  factor)
inline
160{ this->a *= factor; this->b *= factor; }

References a, and b.

◆ translate() [1/2]

void Slic3r::Line::translate ( const Point v)
inline
161{ this->a += v; this->b += v; }

References a, and b.

Referenced by Slic3r::FillAdaptive::connect_lines_using_hooks(), and Slic3r::FillAdaptive::create_offset_line().

+ Here is the caller graph for this function:

◆ translate() [2/2]

void Slic3r::Line::translate ( double  x,
double  y 
)
inline
162{ this->translate(Point(x, y)); }
void translate(const Point &v)
Definition Line.hpp:161
Kernel::Point_2 Point
Definition point_areas.cpp:20

References translate().

Referenced by translate().

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

◆ vector()

Vector Slic3r::Line::vector ( ) const
inline
181{ return this->b - this->a; }

References a, and b.

Referenced by atan2_(), clip_with_bbox(), Slic3r::FillAdaptive::connect_lines_using_hooks(), Slic3r::contours_simplified(), Slic3r::EdgeGrid::Grid::contours_simplified(), direction(), extend(), intersection_infinite(), Slic3r::PaintedLineVisitor::operator()(), parallel_to(), perp_distance_to(), perpendicular_to(), Slic3r::IntersectionLine::set_no_seed(), and Slic3r::thick_lines_to_geometry().

+ Here is the caller graph for this function:

Member Data Documentation

◆ a

Point Slic3r::Line::a

Referenced by Slic3r::JPSPathFinder::add_obstacles(), Slic3r::Voronoi::annotate_inside_outside(), Slic3r::any_expolygon_contains(), atan2_(), Slic3r::chain_lines(), Slic3r::chain_lines_by_triangle_connectivity(), clip_with_bbox(), Slic3r::colorize_line(), priv::compute_intersections(), Slic3r::FillAdaptive::connect_lines_using_hooks(), Slic3r::ExPolygon::contains(), Slic3r::Voronoi::contour_point(), Slic3r::Voronoi::contour_point(), Slic3r::cut_mesh(), Slic3r::BridgeDetector::detect_angle(), Slic3r::Voronoi::detail::dist_to_site(), distance_to(), distance_to(), distance_to_infinite(), distance_to_infinite_squared(), distance_to_squared(), distance_to_squared(), Slic3r::SVG::draw(), Slic3r::SVG::draw(), Slic3r::Voronoi::edge_offset_contour_intersections(), Slic3r::ExtrusionQualityEstimator::estimate_speed_from_extrusion_quality(), extend(), Slic3r::filter_painted_lines(), Slic3r::Polygon::first_intersection(), Slic3r::Geometry::foot_pt(), Slic3r::FillAdaptive::generate_infill_lines_recursive(), boost::polygon::segment_traits< Slic3r::ColoredLine >::get(), boost::polygon::segment_traits< Slic3r::Line >::get(), Slic3r::FillAdaptive::Intersection::intersect_line_dir(), intersection_infinite(), Slic3r::Polygon::intersections(), Slic3r::is_point_closer_to_beginning_of_line(), length(), Slic3r::ConflictChecker::line_intersect(), Slic3r::Voronoi::detail::line_point_equal_distance_points(), Slic3r::RasterizationImpl::line_rasterization(), Slic3r::make_fill_polylines(), midpoint(), Slic3r::FillAdaptive::mk_rtree_seg(), Slic3r::need_wipe(), normal(), Slic3r::Voronoi::offset(), Slic3r::Voronoi::detail::on_site(), Slic3r::PaintedLineVisitor::operator()(), operator==(), Slic3r::Geometry::orientation_of_two_edges(), parallel_to(), perp_distance_to(), perpendicular_to(), Slic3r::Voronoi::detail::point_segment_dr_dl_thresholds(), Slic3r::Voronoi::detail::point_segment_skeleton_thresholds(), Slic3r::points_inside(), Slic3r::FillLightning::polygonCollidesWithLineSegment(), Slic3r::post_process_painted_lines(), Slic3r::project_line_on_line(), reverse(), Slic3r::IntersectionLine::reverse(), rotate(), scale(), Slic3r::Voronoi::signed_vertex_distances(), Slic3r::Voronoi::skeleton_edges_rough(), Slic3r::slice_facet(), Slic3r::slice_facet_with_slabs(), Slic3r::thick_lines_to_geometry(), Slic3r::PerimeterGenerator::thick_polyline_to_multi_path(), translate(), Slic3r::Geometry::MedialAxis::validate_edge(), vector(), and Slic3r::Voronoi::debug::verify_twin_halfedges_successive().

◆ b

Point Slic3r::Line::b

Referenced by Slic3r::FillAdaptive::Intersection::Intersection(), Slic3r::Voronoi::annotate_inside_outside(), Slic3r::any_expolygon_contains(), atan2_(), Slic3r::chain_lines(), Slic3r::chain_lines_by_triangle_connectivity(), clip_with_bbox(), priv::compute_intersections(), Slic3r::FillAdaptive::connect_lines_using_hooks(), Slic3r::ExPolygon::contains(), Slic3r::Voronoi::contour_point(), Slic3r::Voronoi::contour_point(), Slic3r::cut_mesh(), Slic3r::BridgeDetector::detect_angle(), Slic3r::Voronoi::detail::dist_to_site(), distance_to(), distance_to(), distance_to_infinite(), distance_to_infinite_squared(), distance_to_squared(), distance_to_squared(), Slic3r::SVG::draw(), Slic3r::SVG::draw(), Slic3r::Voronoi::edge_offset_contour_intersections(), Slic3r::ExtrusionQualityEstimator::estimate_speed_from_extrusion_quality(), extend(), Slic3r::filter_painted_lines(), Slic3r::Polygon::first_intersection(), Slic3r::Geometry::foot_pt(), Slic3r::FillAdaptive::generate_infill_lines_recursive(), boost::polygon::segment_traits< Slic3r::ColoredLine >::get(), boost::polygon::segment_traits< Slic3r::Line >::get(), Slic3r::FillAdaptive::Intersection::intersect_line_dir(), intersection_infinite(), Slic3r::Polygon::intersections(), Slic3r::is_point_closer_to_beginning_of_line(), length(), Slic3r::ConflictChecker::line_intersect(), Slic3r::Voronoi::detail::line_point_equal_distance_points(), Slic3r::RasterizationImpl::line_rasterization(), Slic3r::make_fill_polylines(), midpoint(), Slic3r::FillAdaptive::mk_rtree_seg(), Slic3r::need_wipe(), normal(), Slic3r::Voronoi::offset(), Slic3r::Voronoi::detail::on_site(), Slic3r::PaintedLineVisitor::operator()(), operator==(), Slic3r::Geometry::orientation_of_two_edges(), parallel_to(), perp_distance_to(), perpendicular_to(), Slic3r::Voronoi::detail::point_segment_dr_dl_thresholds(), Slic3r::Voronoi::detail::point_segment_skeleton_thresholds(), Slic3r::points_inside(), Slic3r::FillLightning::polygonCollidesWithLineSegment(), Slic3r::post_process_painted_lines(), Slic3r::project_line_on_line(), reverse(), Slic3r::IntersectionLine::reverse(), rotate(), scale(), Slic3r::Voronoi::signed_vertex_distances(), Slic3r::Voronoi::skeleton_edges_rough(), Slic3r::slice_facet(), Slic3r::slice_facet_with_slabs(), Slic3r::thick_lines_to_geometry(), Slic3r::PerimeterGenerator::thick_polyline_to_multi_path(), translate(), Slic3r::Geometry::MedialAxis::validate_edge(), vector(), and Slic3r::Voronoi::debug::verify_twin_halfedges_successive().

◆ Dim

const constexpr int Slic3r::Line::Dim = 2
staticconstexpr

The documentation for this class was generated from the following files: