OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Point Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Point.hpp>

Inheritance diagram for Slic3r::Point:
Collaboration diagram for Slic3r::Point:

Public Types

using coord_type = coord_t

Public Member Functions

 Point ()
 Point (int32_t x, int32_t y)
 Point (int64_t x, int64_t y)
 Point (int64_t x, int32_t y)
 Point (int32_t x, int64_t y)
 Point (double x, double y)
 Point (const Vec2d &rhs)
template<typename OtherDerived>
 Point (const Eigen::MatrixBase< OtherDerived > &other)
template<typename OtherDerived>
Point & operator= (const Eigen::MatrixBase< OtherDerived > &other)
Point & operator+= (const Point &rhs)
Point & operator-= (const Point &rhs)
Point & operator*= (const double &rhs)
Point operator* (const double &rhs)
bool both_comp (const Point &rhs, const std::string &op)
bool any_comp (const Point &rhs, const std::string &op)
void rotate (double angle)
void rotate (double cos_a, double sin_a)
void rotate (double angle, const Point &center)
Point rotated (double angle) const
Point rotated (double cos_a, double sin_a) const
Point rotated (double angle, const Point &center) const
Point rotate_90_degree_ccw () const
int nearest_point_index (const Points &points) const
int nearest_point_index (const PointConstPtrs &points) const
int nearest_point_index (const PointPtrs &points) const
bool nearest_point (const Points &points, Point *point) const
double ccw (const Point &p1, const Point &p2) const
double ccw (const Line &line) const
double ccw_angle (const Point &p1, const Point &p2) const
Point projection_onto (const MultiPoint &poly) const
Point projection_onto (const Line &line) const
double distance_to (const Point &point) const

Static Public Member Functions

static Point new_scale (coordf_t x, coordf_t y)
template<typename OtherDerived>
static Point new_scale (const Eigen::MatrixBase< OtherDerived > &v)

Detailed Description

Member Typedef Documentation

◆ coord_type

Constructor & Destructor Documentation

◆ Point() [1/8]

Slic3r::Point::Point ( )
inline
203: Vec2crd(0, 0) {}
Eigen::Matrix< coord_t, 2, 1, Eigen::DontAlign > Vec2crd
Definition Point.hpp:52

Referenced by Slic3r::IntersectionPoint::IntersectionPoint(), Slic3r::IntersectionPoint::IntersectionPoint(), any_comp(), both_comp(), ccw(), ccw_angle(), distance_to(), nearest_point(), new_scale(), new_scale(), operator*(), operator*=(), operator+=(), operator-=(), operator=(), projection_onto(), projection_onto(), rotate(), rotate_90_degree_ccw(), rotated(), rotated(), and rotated().

Here is the caller graph for this function:

◆ Point() [2/8]

Slic3r::Point::Point ( int32_t x,
int32_t y )
inline
204: Vec2crd(coord_t(x), coord_t(y)) {}
int64_t coord_t
Definition libslic3r.h:48

◆ Point() [3/8]

Slic3r::Point::Point ( int64_t x,
int64_t y )
inline
205: Vec2crd(coord_t(x), coord_t(y)) {}

◆ Point() [4/8]

Slic3r::Point::Point ( int64_t x,
int32_t y )
inline
206: Vec2crd(coord_t(x), coord_t(y)) {}

◆ Point() [5/8]

Slic3r::Point::Point ( int32_t x,
int64_t y )
inline
207: Vec2crd(coord_t(x), coord_t(y)) {}

◆ Point() [6/8]

Slic3r::Point::Point ( double x,
double y )
inline
208: Vec2crd(coord_t(std::round(x)), coord_t(std::round(y))) {}

◆ Point() [7/8]

Slic3r::Point::Point ( const Vec2d & rhs)
inlineexplicit
209: Vec2crd(coord_t(std::round(rhs.x())), coord_t(std::round(rhs.y()))) {}

◆ Point() [8/8]

template<typename OtherDerived>
Slic3r::Point::Point ( const Eigen::MatrixBase< OtherDerived > & other)
inline
213: Vec2crd(other) {}

Member Function Documentation

◆ any_comp()

bool Slic3r::Point::any_comp ( const Point & rhs,
const std::string & op )
inline
238 {
239 if (op == ">")
240 return this->x() > rhs.x() || this->y() > rhs.y();
241 else if (op == "<")
242 return this->x() < rhs.x() || this->y() < rhs.y();
243 return false;
244 }

References Point().

Here is the call graph for this function:

◆ both_comp()

bool Slic3r::Point::both_comp ( const Point & rhs,
const std::string & op )
inline
230 {
231 if (op == ">")
232 return this->x() > rhs.x() && this->y() > rhs.y();
233 else if (op == "<")
234 return this->x() < rhs.x() && this->y() < rhs.y();
235 return false;
236 }

References Point().

Here is the call graph for this function:

◆ ccw() [1/2]

double Slic3r::Point::ccw ( const Line & line) const
82{
83 return this->ccw(line.a, line.b);
84}
double ccw(const Point &p1, const Point &p2) const
Definition Point.cpp:74

References Slic3r::Line::a, Slic3r::Line::b, and ccw().

Here is the call graph for this function:

◆ ccw() [2/2]

double Slic3r::Point::ccw ( const Point & p1,
const Point & p2 ) const
75{
76 // static_assert(sizeof(coord_t) == 4, "Point::ccw() requires a 32 bit coord_t");
77 // return cross2((p2 - p1).cast<int64_t>(), (*this - p1).cast<int64_t>());
78 return cross2((p2 - p1).cast<double>(), (*this - p1).cast<double>());
79}
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
auto cast(const BoundingBoxBase< Tin > &b)
Definition BoundingBox.hpp:299

References Point(), Slic3r::cast(), and Slic3r::cross2().

Referenced by Slic3r::Point3::ccw(), Slic3r::Point3::ccw(), and ccw().

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

◆ ccw_angle()

double Slic3r::Point::ccw_angle ( const Point & p1,
const Point & p2 ) const
89{
90 //FIXME this calculates an atan2 twice! Project one vector into the other!
91 double angle = atan2(p1.x() - (*this).x(), p1.y() - (*this).y())
92 - atan2(p2.x() - (*this).x(), p2.y() - (*this).y());
93 // we only want to return only positive angles
94 return angle <= 0 ? angle + 2*PI : angle;
95}
static constexpr double PI
Definition libslic3r.h:81
double angle(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:138

References Point(), and Slic3r::angle().

Referenced by Slic3r::Point3::ccw_angle(), Slic3r::GCode::extrude_loop(), and Slic3r::wipe_on_loops_destination().

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

◆ distance_to()

double Slic3r::Point::distance_to ( const Point & point) const
inline
269{ return (point - *this).cast<double>().norm(); }

References Point().

Referenced by Slic3r::generate_spiral_insets(), and Slic3r::remove_overlapped().

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

◆ nearest_point()

bool Slic3r::Point::nearest_point ( const Points & points,
Point * point ) const
241{
242 int idx = this->nearest_point_index(points);
243 if (idx == -1) return false;
244 *point = points.at(idx);
245 return true;
246}
int nearest_point_index(const Points &points) const
Definition Point.cpp:197

References Point(), and nearest_point_index().

Referenced by Slic3r::Point3::nearest_point().

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

◆ nearest_point_index() [1/3]

int Slic3r::Point::nearest_point_index ( const PointConstPtrs & points) const
207{
208 int idx = -1;
209 double distance = -1; // double because long is limited to 2147483647 on some platforms and it's not enough
210
211 for (PointConstPtrs::const_iterator it = points.begin(); it != points.end(); ++it) {
212 /* If the X distance of the candidate is > than the total distance of the
213 best previous candidate, we know we don't want it */
214 double d = sqr<double>((*this)(0) - (*it)->x());
215 if (distance != -1 && d > distance) continue;
216
217 /* If the Y distance of the candidate is > than the total distance of the
218 best previous candidate, we know we don't want it */
219 d += sqr<double>((*this)(1) - (*it)->y());
220 if (distance != -1 && d > distance) continue;
221
222 idx = it - points.begin();
223 distance = d;
224
225 if (distance < EPSILON) break;
226 }
227
228 return idx;
229}
#define EPSILON
Definition ColorUtils.cpp:64
float distance(SpiralVase::SpiralPoint a, SpiralVase::SpiralPoint b)
Definition SpiralVase.cpp:19
constexpr T sqr(T x)
Definition libslic3r.h:301

References EPSILON, and Slic3r::sqr().

Here is the call graph for this function:

◆ nearest_point_index() [2/3]

int Slic3r::Point::nearest_point_index ( const PointPtrs & points) const
232{
234 p.reserve(points.size());
235 for (PointPtrs::const_iterator it = points.begin(); it != points.end(); ++it)
236 p.push_back(*it);
237 return this->nearest_point_index(p);
238}
std::vector< const Point * > PointConstPtrs
Definition Point.hpp:75

References nearest_point_index().

Here is the call graph for this function:

◆ nearest_point_index() [3/3]

int Slic3r::Point::nearest_point_index ( const Points & points) const
198{
200 p.reserve(points.size());
201 for (Points::const_iterator it = points.begin(); it != points.end(); ++it)
202 p.push_back(&*it);
203 return this->nearest_point_index(p);
204}

References nearest_point_index().

Referenced by Slic3r::FillConcentric::_fill_surface_single(), Slic3r::FillConcentric::_fill_surface_single(), Slic3r::FillConcentricInternal::fill_surface_extrusion(), Slic3r::generate_spiral_insets(), nearest_point(), Slic3r::Point3::nearest_point_index(), nearest_point_index(), and nearest_point_index().

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

◆ new_scale() [1/2]

template<typename OtherDerived>
Point Slic3r::Point::new_scale ( const Eigen::MatrixBase< OtherDerived > & v)
inlinestatic
216{ return Point(coord_t(scale_(v.x())), coord_t(scale_(v.y()))); }
Point()
Definition Point.hpp:203
#define scale_(val)
Definition libslic3r.h:106

References Point(), and scale_.

Here is the call graph for this function:

◆ new_scale() [2/2]

Point Slic3r::Point::new_scale ( coordf_t x,
coordf_t y )
inlinestatic
214{ return Point(coord_t(scale_(x)), coord_t(scale_(y))); }

References Point(), and scale_.

Referenced by Slic3r::PrintObject::PrintObject(), Slic3r::Geometry::circle_center_taubin_newton(), Slic3r::WipeTower2::cone_base_polygon(), libvgcode::convert_wipe_tower_to_vertices(), Slic3r::Geometry::convex_hull(), Slic3r::TriangleMesh::convex_hull(), Slic3r::detect_overhangs(), Slic3r::SupportSpotsGenerator::estimate_malformations(), Slic3r::WipeTower2::finish_layer(), Slic3r::FillAdaptive::generate_infill_lines_recursive(), Slic3r::WipeTower2::generate_rib_polygon(), Slic3r::WipeTower::generate_rib_polygon(), Slic3r::WipeTower2::generate_support_cone_wall(), Slic3r::FakeWipeTower::getFakeExtrusionPathsFromWipeTower2(), Slic3r::GUI::MeshClipper::is_projection_inside_cut(), Slic3r::GUI::Plater::priv::load_model_objects(), Slic3r::GCode::needs_retraction(), Slic3r::Polygon::new_scale(), Slic3r::Polyline::new_scale(), Slic3r::SeamPlacer::place_seam(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::place_wipe_tower(), Slic3r::GUI::MeshClipper::point_per_contour(), Slic3r::print_objects_from_model_object(), Slic3r::GUI::PartPlateList::set_default_wipe_tower_pos_for_plate(), Slic3r::sla_instances(), Slic3r::GCodeWriter::spiral_lift_fits_printable_area(), Slic3r::WipeTower2::toolchange_Change(), and Slic3r::AvoidCrossingPerimeters::travel_to().

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

◆ operator*()

Point Slic3r::Point::operator* ( const double & rhs)
inline
229{ return Point(this->x() * rhs, this->y() * rhs); }

References Point().

Here is the call graph for this function:

◆ operator*=()

Point & Slic3r::Point::operator*= ( const double & rhs)
inline
228{ this->x() = coord_t(this->x() * rhs); this->y() = coord_t(this->y() * rhs); return *this; }

References Point().

Here is the call graph for this function:

◆ operator+=()

Point & Slic3r::Point::operator+= ( const Point & rhs)
inline
226{ this->x() += rhs.x(); this->y() += rhs.y(); return *this; }

References Point().

Here is the call graph for this function:

◆ operator-=()

Point & Slic3r::Point::operator-= ( const Point & rhs)
inline
227{ this->x() -= rhs.x(); this->y() -= rhs.y(); return *this; }

References Point().

Here is the call graph for this function:

◆ operator=()

template<typename OtherDerived>
Point & Slic3r::Point::operator= ( const Eigen::MatrixBase< OtherDerived > & other)
inline
221 {
222 this->Vec2crd::operator=(other);
223 return *this;
224 }

References Point().

Here is the call graph for this function:

◆ projection_onto() [1/2]

Point Slic3r::Point::projection_onto ( const Line & line) const
114{
115 if (line.a == line.b) return line.a;
116
117 /*
118 (Ported from VisiLibity by Karl J. Obermeyer)
119 The projection of point_temp onto the line determined by
120 line_segment_temp can be represented as an affine combination
121 expressed in the form projection of
122 Point = theta*line_segment_temp.first + (1.0-theta)*line_segment_temp.second.
123 If theta is outside the interval [0,1], then one of the Line_Segment's endpoints
124 must be closest to calling Point.
125 */
126 double lx = (double)(line.b(0) - line.a(0));
127 double ly = (double)(line.b(1) - line.a(1));
128 double theta = ( (double)(line.b(0) - (*this)(0))*lx + (double)(line.b(1)- (*this)(1))*ly )
129 / ( sqr<double>(lx) + sqr<double>(ly) );
130
131 if (0.0 <= theta && theta <= 1.0)
132 return (theta * line.a.cast<coordf_t>() + (1.0-theta) * line.b.cast<coordf_t>()).cast<coord_t>();
133
134 // Else pick closest endpoint.
135 return ((line.a - *this).cast<double>().squaredNorm() < (line.b - *this).cast<double>().squaredNorm()) ? line.a : line.b;
136}
double coordf_t
Definition GUI_ObjectList.hpp:46

References Point(), Slic3r::Line::a, Slic3r::Line::b, and Slic3r::sqr().

Here is the call graph for this function:

◆ projection_onto() [2/2]

Point Slic3r::Point::projection_onto ( const MultiPoint & poly) const
98{
99 Point running_projection = poly.first_point();
100 double running_min = (running_projection - *this).cast<double>().norm();
101
102 Lines lines = poly.lines();
103 for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
104 Point point_temp = this->projection_onto(*line);
105 if ((point_temp - *this).cast<double>().norm() < running_min) {
106 running_projection = point_temp;
107 running_min = (running_projection - *this).cast<double>().norm();
108 }
109 }
110 return running_projection;
111}
Point projection_onto(const MultiPoint &poly) const
Definition Point.cpp:97
void poly(std::vector< std::pair< Vec2d, Vec2d > > &out, std::initializer_list< Vec2d > p)
Definition DesignSketchTool.cpp:7751
std::vector< Line > Lines
Definition Line.hpp:20

References Point(), Slic3r::cast(), and projection_onto().

Referenced by Slic3r::clip_extrusion(), Slic3r::foot_pt(), Slic3r::MultiPoint::has_boundary_point(), Slic3r::Point3::projection_onto(), projection_onto(), Slic3r::projection_onto(), Slic3r::Polyline3::split_at(), and Slic3r::Polyline::split_at().

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

◆ rotate() [1/3]

void Slic3r::Point::rotate ( double angle)
inline
246{ this->rotate(std::cos(angle), std::sin(angle)); }
void rotate(double angle)
Definition Point.hpp:246

References Slic3r::angle(), and rotate().

Referenced by Slic3r::GCode::extrude_loop(), Slic3r::FillSupportBase::fill_surface(), Slic3r::TreeSupport::generate_contact_points(), rotate(), rotated(), rotated(), rotated(), and Slic3r::wipe_on_loops_destination().

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

◆ rotate() [2/3]

void Slic3r::Point::rotate ( double angle,
const Point & center )
58{
59 Vec2d cur = this->cast<double>();
60 double s = ::sin(angle);
61 double c = ::cos(angle);
62 Vec2d d = cur - center.cast<double>();
63 this->x() = fast_round_up<coord_t>(center.x() + c * d.x() - s * d.y());
64 this->y() = fast_round_up<coord_t>(center.y() + s * d.x() + c * d.y());
65}
void center(ExPolygonsWithIds &e)
Definition Emboss.cpp:1382
IntegerOnly< I, I > fast_round_up(double a)
Definition libslic3r.h:428
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References Point(), Slic3r::angle(), Slic3r::cast(), Slic3r::center(), and Slic3r::fast_round_up().

Here is the call graph for this function:

◆ rotate() [3/3]

void Slic3r::Point::rotate ( double cos_a,
double sin_a )
inline
247 {
248 double cur_x = (double)this->x();
249 double cur_y = (double)this->y();
250 this->x() = (coord_t)round(cos_a * cur_x - sin_a * cur_y);
251 this->y() = (coord_t)round(cos_a * cur_y + sin_a * cur_x);
252 }

◆ rotate_90_degree_ccw()

Point Slic3r::Point::rotate_90_degree_ccw ( ) const
inline
258{ return Point(-this->y(), this->x()); }

References Point().

Here is the call graph for this function:

◆ rotated() [1/3]

Point Slic3r::Point::rotated ( double angle) const
inline
255{ Point res(*this); res.rotate(angle); return res; }

References Point(), Slic3r::angle(), and rotate().

Referenced by Slic3r::Geometry::VoronoiUtils::discretize_parabola(), Slic3r::FillRectilinear::fill_surface_by_lines(), and Slic3r::make_fill_lines().

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

◆ rotated() [2/3]

Point Slic3r::Point::rotated ( double angle,
const Point & center ) const
inline
257{ Point res(*this); res.rotate(angle, center); return res; }

References Point(), Slic3r::angle(), Slic3r::center(), and rotate().

Here is the call graph for this function:

◆ rotated() [3/3]

Point Slic3r::Point::rotated ( double cos_a,
double sin_a ) const
inline
256{ Point res(*this); res.rotate(cos_a, sin_a); return res; }

References Point(), and rotate().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Point.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Point.cpp