2013-07-15 20:57:22 +00:00
|
|
|
#ifndef slic3r_Line_hpp_
|
|
|
|
#define slic3r_Line_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2013-07-15 20:57:22 +00:00
|
|
|
#include "Point.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2013-11-06 22:08:03 +00:00
|
|
|
class Line;
|
2018-01-08 12:44:10 +00:00
|
|
|
class Line3;
|
2014-12-16 00:12:37 +00:00
|
|
|
class Linef3;
|
2013-11-21 14:12:06 +00:00
|
|
|
class Polyline;
|
2016-03-19 14:33:58 +00:00
|
|
|
class ThickLine;
|
2015-01-06 19:52:36 +00:00
|
|
|
typedef std::vector<Line> Lines;
|
2018-01-08 12:44:10 +00:00
|
|
|
typedef std::vector<Line3> Lines3;
|
2016-03-19 14:33:58 +00:00
|
|
|
typedef std::vector<ThickLine> ThickLines;
|
2013-11-06 22:08:03 +00:00
|
|
|
|
2018-08-28 07:03:03 +00:00
|
|
|
Linef3 transform(const Linef3& line, const Transform3d& t);
|
|
|
|
|
2013-07-15 20:57:22 +00:00
|
|
|
class Line
|
|
|
|
{
|
2017-06-08 09:02:29 +00:00
|
|
|
public:
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
Line() {}
|
2018-08-23 13:37:38 +00:00
|
|
|
Line(const Point& _a, const Point& _b) : a(_a), b(_b) {}
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
explicit operator Lines() const { Lines lines; lines.emplace_back(*this); return lines; }
|
|
|
|
void scale(double factor) { this->a *= factor; this->b *= factor; }
|
|
|
|
void translate(double x, double y) { Vector v(x, y); this->a += v; this->b += v; }
|
|
|
|
void rotate(double angle, const Point ¢er) { this->a.rotate(angle, center); this->b.rotate(angle, center); }
|
|
|
|
void reverse() { std::swap(this->a, this->b); }
|
|
|
|
double length() const { return (b - a).cast<double>().norm(); }
|
|
|
|
Point midpoint() const { return (this->a + this->b) / 2; }
|
|
|
|
bool intersection_infinite(const Line &other, Point* point) const;
|
2018-08-17 16:27:07 +00:00
|
|
|
bool operator==(const Line &rhs) const { return this->a == rhs.a && this->b == rhs.b; }
|
2014-04-24 14:40:10 +00:00
|
|
|
double distance_to(const Point &point) const;
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
double perp_distance_to(const Point &point) const;
|
|
|
|
bool parallel_to(double angle) const;
|
|
|
|
bool parallel_to(const Line &line) const { return this->parallel_to(line.direction()); }
|
2018-08-17 13:53:43 +00:00
|
|
|
double atan2_() const { return atan2(this->b(1) - this->a(1), this->b(0) - this->a(0)); }
|
2014-08-03 13:03:11 +00:00
|
|
|
double orientation() const;
|
2014-03-04 22:33:13 +00:00
|
|
|
double direction() const;
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
Vector vector() const { return this->b - this->a; }
|
2018-08-17 13:53:43 +00:00
|
|
|
Vector normal() const { return Vector((this->b(1) - this->a(1)), -(this->b(0) - this->a(0))); }
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
bool intersection(const Line& line, Point* intersection) const;
|
|
|
|
double ccw(const Point& point) const { return point.ccw(*this); }
|
|
|
|
|
|
|
|
Point a;
|
|
|
|
Point b;
|
2016-03-19 14:33:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ThickLine : public Line
|
|
|
|
{
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
public:
|
|
|
|
ThickLine() : a_width(0), b_width(0) {}
|
2018-08-23 13:37:38 +00:00
|
|
|
ThickLine(const Point& a, const Point& b) : Line(a, b), a_width(0), b_width(0) {}
|
|
|
|
ThickLine(const Point& a, const Point& b, double wa, double wb) : Line(a, b), a_width(wa), b_width(wb) {}
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
|
2018-08-23 13:37:38 +00:00
|
|
|
double a_width, b_width;
|
2013-07-15 20:57:22 +00:00
|
|
|
};
|
|
|
|
|
2018-01-08 12:44:10 +00:00
|
|
|
class Line3
|
|
|
|
{
|
|
|
|
public:
|
2018-08-21 20:14:47 +00:00
|
|
|
Line3() : a(Vec3crd::Zero()), b(Vec3crd::Zero()) {}
|
|
|
|
Line3(const Vec3crd& _a, const Vec3crd& _b) : a(_a), b(_b) {}
|
2018-01-08 12:44:10 +00:00
|
|
|
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
double length() const { return (this->a - this->b).cast<double>().norm(); }
|
2018-08-21 20:14:47 +00:00
|
|
|
Vec3crd vector() const { return this->b - this->a; }
|
2018-01-08 12:44:10 +00:00
|
|
|
|
2018-08-21 20:14:47 +00:00
|
|
|
Vec3crd a;
|
|
|
|
Vec3crd b;
|
2018-01-08 12:44:10 +00:00
|
|
|
};
|
|
|
|
|
2015-01-17 23:36:21 +00:00
|
|
|
class Linef
|
|
|
|
{
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
public:
|
2018-08-21 18:34:45 +00:00
|
|
|
Linef() : a(Vec2d::Zero()), b(Vec2d::Zero()) {}
|
2018-08-23 13:37:38 +00:00
|
|
|
Linef(const Vec2d& _a, const Vec2d& _b) : a(_a), b(_b) {}
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
|
2018-08-21 19:05:24 +00:00
|
|
|
Vec2d a;
|
|
|
|
Vec2d b;
|
2015-01-17 23:36:21 +00:00
|
|
|
};
|
|
|
|
|
2014-12-16 00:12:37 +00:00
|
|
|
class Linef3
|
|
|
|
{
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
public:
|
2018-08-23 13:37:38 +00:00
|
|
|
Linef3() : a(Vec3d::Zero()), b(Vec3d::Zero()) {}
|
|
|
|
Linef3(const Vec3d& _a, const Vec3d& _b) : a(_a), b(_b) {}
|
|
|
|
|
2018-08-21 15:43:05 +00:00
|
|
|
Vec3d intersect_plane(double z) const;
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
void scale(double factor) { this->a *= factor; this->b *= factor; }
|
2018-08-23 13:37:38 +00:00
|
|
|
Vec3d vector() const { return this->b - this->a; }
|
|
|
|
Vec3d unit_vector() const { return (length() == 0.0) ? Vec3d::Zero() : vector().normalized(); }
|
|
|
|
double length() const { return vector().norm(); }
|
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.
2018-08-17 12:14:24 +00:00
|
|
|
|
2018-08-21 15:43:05 +00:00
|
|
|
Vec3d a;
|
|
|
|
Vec3d b;
|
2014-12-16 00:12:37 +00:00
|
|
|
};
|
|
|
|
|
2016-12-08 14:16:09 +00:00
|
|
|
} // namespace Slic3r
|
2013-07-15 20:57:22 +00:00
|
|
|
|
2014-01-09 16:26:39 +00:00
|
|
|
// start Boost
|
2014-04-24 11:43:24 +00:00
|
|
|
#include <boost/polygon/polygon.hpp>
|
2014-01-09 16:26:39 +00:00
|
|
|
namespace boost { namespace polygon {
|
|
|
|
template <>
|
2016-12-08 14:16:09 +00:00
|
|
|
struct geometry_concept<Slic3r::Line> { typedef segment_concept type; };
|
2014-01-09 16:26:39 +00:00
|
|
|
|
|
|
|
template <>
|
2016-12-08 14:16:09 +00:00
|
|
|
struct segment_traits<Slic3r::Line> {
|
2014-01-09 16:26:39 +00:00
|
|
|
typedef coord_t coordinate_type;
|
2016-12-08 14:16:09 +00:00
|
|
|
typedef Slic3r::Point point_type;
|
2014-01-09 16:26:39 +00:00
|
|
|
|
2016-12-08 14:16:09 +00:00
|
|
|
static inline point_type get(const Slic3r::Line& line, direction_1d dir) {
|
2014-01-09 16:26:39 +00:00
|
|
|
return dir.to_int() ? line.b : line.a;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} }
|
|
|
|
// end Boost
|
|
|
|
|
2013-07-15 20:57:22 +00:00
|
|
|
#endif
|