Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2018-08-17 15:14:24 +0300
committerbubnikv <bubnikv@gmail.com>2018-08-17 15:14:24 +0300
commit1ba64da3fee97433d6b580aae8fc8e9875143a66 (patch)
treeb8c8c5239ed3ea9190cafa18afd5a95f38b80a09 /xs/src/libslic3r/Point.hpp
parent3b89717149664e5702fa1e0a153e54824e2793ff (diff)
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(), translate(), distance_to() etc, replaced with the Eigen equivalents.
Diffstat (limited to 'xs/src/libslic3r/Point.hpp')
-rw-r--r--xs/src/libslic3r/Point.hpp98
1 files changed, 19 insertions, 79 deletions
diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp
index 1de8c22bc..affe1e80e 100644
--- a/xs/src/libslic3r/Point.hpp
+++ b/xs/src/libslic3r/Point.hpp
@@ -35,6 +35,8 @@ typedef std::vector<Pointf3> Pointf3s;
// Vector types with a fixed point coordinate base type.
typedef Eigen::Matrix<coord_t, 2, 1, Eigen::DontAlign> Vec2crd;
typedef Eigen::Matrix<coord_t, 3, 1, Eigen::DontAlign> Vec3crd;
+typedef Eigen::Matrix<int64_t, 2, 1, Eigen::DontAlign> Vec2i64;
+typedef Eigen::Matrix<int64_t, 3, 1, Eigen::DontAlign> Vec3i64;
// Vector types with a double coordinate base type.
typedef Eigen::Matrix<float, 2, 1, Eigen::DontAlign> Vec2f;
@@ -47,6 +49,11 @@ typedef Eigen::Transform<double, 2, Eigen::Affine, Eigen::DontAlign> Transform2d
typedef Eigen::Transform<float, 3, Eigen::Affine, Eigen::DontAlign> Transform3f;
typedef Eigen::Transform<double, 3, Eigen::Affine, Eigen::DontAlign> Transform3d;
+inline int64_t cross2(const Vec2i64 &v1, const Vec2i64 &v2) { return v1.x() * v2.y() - v1.y() * v2.x(); }
+inline coord_t cross2(const Vec2crd &v1, const Vec2crd &v2) { return v1.x() * v2.y() - v1.y() * v2.x(); }
+inline float cross2(const Vec2f &v1, const Vec2f &v2) { return v1.x() * v2.y() - v1.y() * v2.x(); }
+inline double cross2(const Vec2d &v1, const Vec2d &v2) { return v1.x() * v2.y() - v1.y() * v2.x(); }
+
class Point : public Vec2crd
{
public:
@@ -66,7 +73,7 @@ public:
template<typename OtherDerived>
Point& operator=(const Eigen::MatrixBase<OtherDerived> &other)
{
- this->Point::operator=(other);
+ this->Vec2crd::operator=(other);
return *this;
}
@@ -81,51 +88,33 @@ public:
Point& operator+=(const Point& rhs) { this->x() += rhs.x(); this->y() += rhs.y(); return *this; }
Point& operator-=(const Point& rhs) { this->x() -= rhs.x(); this->y() -= rhs.y(); return *this; }
- Point& operator*=(const coord_t& rhs) { this->x() *= rhs; this->y() *= rhs; return *this; }
+ Point& operator*=(const double &rhs) { this->x() *= rhs; this->y() *= rhs; return *this; }
std::string wkt() const;
std::string dump_perl() const;
- void scale(double factor) { *this *= factor; }
- void translate(double x, double y) { *this += Vector(x, y); }
- void translate(const Vector &vector) { *this += vector; }
void rotate(double angle);
void rotate(double angle, const Point &center);
Point rotated(double angle) const { Point res(*this); res.rotate(angle); return res; }
Point rotated(double angle, const Point &center) const { Point res(*this); res.rotate(angle, center); return res; }
- bool coincides_with(const Point &rhs) const { return *this == rhs; }
bool coincides_with_epsilon(const Point &point) 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 distance_to(const Point &point) const { return (point - *this).norm(); }
- double distance_to_sq(const Point &point) const { return (point - *this).squaredNorm(); }
- double distance_to(const Line &line) const;
- double perp_distance_to(const Line &line) 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;
- Point negative() const { return Point(- *this); }
- Vector vector_to(const Point &point) const { return Vector(point - *this); }
};
-inline Point operator+(const Point& point1, const Point& point2) { return Point(point1.x() + point2.x(), point1.y() + point2.y()); }
-inline Point operator-(const Point& point1, const Point& point2) { return Point(point1.x() - point2.x(), point1.y() - point2.y()); }
-inline Point operator*(double scalar, const Point& point2) { return Point(scalar * point2.x(), scalar * point2.y()); }
-inline int64_t cross(const Point &v1, const Point &v2) { return int64_t(v1.x()) * int64_t(v2.y()) - int64_t(v1.y()) * int64_t(v2.x()); }
-inline int64_t dot(const Point &v1, const Point &v2) { return int64_t(v1.x()) * int64_t(v2.x()) + int64_t(v1.y()) * int64_t(v2.y()); }
-
namespace int128 {
-
-// Exact orientation predicate,
-// returns +1: CCW, 0: collinear, -1: CW.
-int orient(const Point &p1, const Point &p2, const Point &p3);
-
-// Exact orientation predicate,
-// returns +1: CCW, 0: collinear, -1: CW.
-int cross(const Point &v1, const Slic3r::Point &v2);
+ // Exact orientation predicate,
+ // returns +1: CCW, 0: collinear, -1: CW.
+ int orient(const Point &p1, const Point &p2, const Point &p3);
+ // Exact orientation predicate,
+ // returns +1: CCW, 0: collinear, -1: CW.
+ int cross(const Point &v1, const Slic3r::Point &v2);
}
// To be used by std::unordered_map, std::unordered_multimap and friends.
@@ -204,7 +193,7 @@ public:
const ValueType &value = it->second;
const Point *pt2 = m_point_accessor(value);
if (pt2 != nullptr) {
- const double d2 = pt.distance_to_sq(*pt2);
+ const double d2 = (pt - *pt2).squaredNorm();
if (d2 < dist_min) {
dist_min = d2;
value_min = &value;
@@ -243,7 +232,7 @@ public:
template<typename OtherDerived>
Point3& operator=(const Eigen::MatrixBase<OtherDerived> &other)
{
- this->Point3::operator=(other);
+ this->Vec3crd::operator=(other);
return *this;
}
@@ -268,7 +257,6 @@ public:
typedef coordf_t coord_type;
explicit Pointf() { (*this)(0) = (*this)(1) = 0.; }
-// explicit Pointf(double x, double y) { (*this)(0) = x; (*this)(1) = y; }
explicit Pointf(coordf_t x, coordf_t y) { (*this)(0) = x; (*this)(1) = y; }
// This constructor allows you to construct Pointf from Eigen expressions
template<typename OtherDerived>
@@ -280,7 +268,7 @@ public:
template<typename OtherDerived>
Pointf& operator=(const Eigen::MatrixBase<OtherDerived> &other)
{
- this->Pointf::operator=(other);
+ this->Vec2d::operator=(other);
return *this;
}
@@ -291,13 +279,8 @@ public:
std::string wkt() const;
std::string dump_perl() const;
- void scale(double factor) { *this *= factor; }
- void translate(double x, double y) { *this += Vec2d(x, y); }
- void translate(const Vectorf &vector) { *this += vector; }
void rotate(double angle);
void rotate(double angle, const Pointf &center);
- Pointf negative() const { return Pointf(- *this); }
- Vectorf vector_to(const Pointf &point) const { return point - *this; }
Pointf& operator+=(const Pointf& rhs) { this->x() += rhs.x(); this->y() += rhs.y(); return *this; }
Pointf& operator-=(const Pointf& rhs) { this->x() -= rhs.x(); this->y() -= rhs.y(); return *this; }
Pointf& operator*=(const coordf_t& rhs) { this->x() *= rhs; this->y() *= rhs; return *this; }
@@ -307,21 +290,6 @@ public:
bool operator< (const Pointf& rhs) const { return this->x() < rhs.x() || (this->x() == rhs.x() && this->y() < rhs.y()); }
};
-inline Pointf operator+(const Pointf& point1, const Pointf& point2) { return Pointf(point1.x() + point2.x(), point1.y() + point2.y()); }
-inline Pointf operator-(const Pointf& point1, const Pointf& point2) { return Pointf(point1.x() - point2.x(), point1.y() - point2.y()); }
-inline Pointf operator*(double scalar, const Pointf& point2) { return Pointf(scalar * point2.x(), scalar * point2.y()); }
-inline Pointf operator*(const Pointf& point2, double scalar) { return Pointf(scalar * point2.x(), scalar * point2.y()); }
-inline coordf_t cross(const Pointf &v1, const Pointf &v2) { return v1.x() * v2.y() - v1.y() * v2.x(); }
-inline coordf_t dot(const Pointf &v1, const Pointf &v2) { return v1.x() * v2.x() + v1.y() * v2.y(); }
-inline coordf_t dot(const Pointf &v) { return v.x() * v.x() + v.y() * v.y(); }
-inline double length(const Vectorf &v) { return sqrt(dot(v)); }
-inline double l2(const Vectorf &v) { return dot(v); }
-inline Vectorf normalize(const Vectorf& v)
-{
- coordf_t len = ::sqrt(sqr(v.x()) + sqr(v.y()));
- return (len != 0.0) ? 1.0 / len * v : Vectorf(0.0, 0.0);
-}
-
class Pointf3 : public Vec3d
{
public:
@@ -340,7 +308,7 @@ public:
template<typename OtherDerived>
Pointf3& operator=(const Eigen::MatrixBase<OtherDerived> &other)
{
- this->Pointf3::operator=(other);
+ this->Vec3d::operator=(other);
return *this;
}
@@ -351,40 +319,12 @@ public:
const coordf_t& z() const { return (*this)(2); }
coordf_t& z() { return (*this)(2); }
- void scale(double factor) { *this *= factor; }
- void translate(const Vectorf3 &vector) { *this += vector; }
- void translate(double x, double y, double z) { *this += Vec3d(x, y, z); }
- double distance_to(const Pointf3 &point) const { return (point - *this).norm(); }
- Pointf3 negative() const { return Pointf3(- *this); }
- Vectorf3 vector_to(const Pointf3 &point) const { return point - *this; }
-
bool operator==(const Pointf3 &rhs) const { return this->x() == rhs.x() && this->y() == rhs.y() && this->z() == rhs.z(); }
bool operator!=(const Pointf3 &rhs) const { return ! (*this == rhs); }
Pointf xy() const { return Pointf(this->x(), this->y()); }
};
-inline Pointf3 operator+(const Pointf3& p1, const Pointf3& p2) { return Pointf3(p1.x() + p2.x(), p1.y() + p2.y(), p1.z() + p2.z()); }
-inline Pointf3 operator-(const Pointf3& p1, const Pointf3& p2) { return Pointf3(p1.x() - p2.x(), p1.y() - p2.y(), p1.z() - p2.z()); }
-inline Pointf3 operator-(const Pointf3& p) { return Pointf3(-p.x(), -p.y(), -p.z()); }
-inline Pointf3 operator*(double scalar, const Pointf3& p) { return Pointf3(scalar * p.x(), scalar * p.y(), scalar * p.z()); }
-inline Pointf3 operator*(const Pointf3& p, double scalar) { return Pointf3(scalar * p.x(), scalar * p.y(), scalar * p.z()); }
-inline Pointf3 cross(const Pointf3& v1, const Pointf3& v2) { return Pointf3(v1.y() * v2.z() - v1.z() * v2.y(), v1.z() * v2.x() - v1.x() * v2.z(), v1.x() * v2.y() - v1.y() * v2.x()); }
-inline coordf_t dot(const Pointf3& v1, const Pointf3& v2) { return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z(); }
-inline coordf_t dot(const Pointf3& v) { return v.x() * v.x() + v.y() * v.y() + v.z() * v.z(); }
-inline double length(const Vectorf3 &v) { return sqrt(dot(v)); }
-inline double l2(const Vectorf3 &v) { return dot(v); }
-inline Pointf3 normalize(const Pointf3& v)
-{
- coordf_t len = ::sqrt(sqr(v.x()) + sqr(v.y()) + sqr(v.z()));
- return (len != 0.0) ? 1.0 / len * v : Pointf3(0.0, 0.0, 0.0);
-}
-
-template<typename TO> inline TO convert_to(const Point &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y())); }
-template<typename TO> inline TO convert_to(const Pointf &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y())); }
-template<typename TO> inline TO convert_to(const Point3 &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y()), typename TO::coord_type(src.z())); }
-template<typename TO> inline TO convert_to(const Pointf3 &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y()), typename TO::coord_type(src.z())); }
-
} // namespace Slic3r
// start Boost