Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types:
Changed the Point3 / Pointf3 to derive from the Eigen Vec3crd / Vec3d. Replaced the Point::concide_with() method calls with == operator. Reduced some compiler warnings.
This commit is contained in:
parent
f34252a27b
commit
3b89717149
@ -182,9 +182,9 @@ std::vector<double> BridgeDetector::bridge_direction_candidates() const
|
||||
|
||||
/* we also test angles of each open supporting edge
|
||||
(this finds the optimal angle for C-shaped supports) */
|
||||
for (Polylines::const_iterator edge = this->_edges.begin(); edge != this->_edges.end(); ++edge)
|
||||
if (! edge->first_point().coincides_with(edge->last_point()))
|
||||
angles.push_back(Line(edge->first_point(), edge->last_point()).direction());
|
||||
for (const Polyline &edge : this->_edges)
|
||||
if (edge.first_point() != edge.last_point())
|
||||
angles.push_back(Line(edge.first_point(), edge.last_point()).direction());
|
||||
|
||||
// remove duplicates
|
||||
double min_resolution = PI/180.0; // 1 degree
|
||||
|
@ -595,26 +595,26 @@ Polylines _clipper_pl(ClipperLib::ClipType clipType, const Polygons &subject, co
|
||||
to recombine continuous polylines. */
|
||||
for (size_t i = 0; i < retval.size(); ++i) {
|
||||
for (size_t j = i+1; j < retval.size(); ++j) {
|
||||
if (retval[i].points.back().coincides_with(retval[j].points.front())) {
|
||||
if (retval[i].points.back() == retval[j].points.front()) {
|
||||
/* If last point of i coincides with first point of j,
|
||||
append points of j to i and delete j */
|
||||
retval[i].points.insert(retval[i].points.end(), retval[j].points.begin()+1, retval[j].points.end());
|
||||
retval.erase(retval.begin() + j);
|
||||
--j;
|
||||
} else if (retval[i].points.front().coincides_with(retval[j].points.back())) {
|
||||
} else if (retval[i].points.front() == retval[j].points.back()) {
|
||||
/* If first point of i coincides with last point of j,
|
||||
prepend points of j to i and delete j */
|
||||
retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1);
|
||||
retval.erase(retval.begin() + j);
|
||||
--j;
|
||||
} else if (retval[i].points.front().coincides_with(retval[j].points.front())) {
|
||||
} else if (retval[i].points.front() == retval[j].points.front()) {
|
||||
/* Since Clipper does not preserve orientation of polylines,
|
||||
also check the case when first point of i coincides with first point of j. */
|
||||
retval[j].reverse();
|
||||
retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1);
|
||||
retval.erase(retval.begin() + j);
|
||||
--j;
|
||||
} else if (retval[i].points.back().coincides_with(retval[j].points.back())) {
|
||||
} else if (retval[i].points.back() == retval[j].points.back()) {
|
||||
/* Since Clipper does not preserve orientation of polylines,
|
||||
also check the case when last point of i coincides with last point of j. */
|
||||
retval[j].reverse();
|
||||
|
@ -294,14 +294,14 @@ ExPolygon::medial_axis(double max_width, double min_width, ThickPolylines* polyl
|
||||
// find another polyline starting here
|
||||
for (size_t j = i+1; j < pp.size(); ++j) {
|
||||
ThickPolyline& other = pp[j];
|
||||
if (polyline.last_point().coincides_with(other.last_point())) {
|
||||
if (polyline.last_point() == other.last_point()) {
|
||||
other.reverse();
|
||||
} else if (polyline.first_point().coincides_with(other.last_point())) {
|
||||
} else if (polyline.first_point() == other.last_point()) {
|
||||
polyline.reverse();
|
||||
other.reverse();
|
||||
} else if (polyline.first_point().coincides_with(other.first_point())) {
|
||||
} else if (polyline.first_point() == other.first_point()) {
|
||||
polyline.reverse();
|
||||
} else if (!polyline.last_point().coincides_with(other.first_point())) {
|
||||
} else if (polyline.last_point() != other.first_point()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2213,7 +2213,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
|
||||
std::string gcode;
|
||||
|
||||
// go to first point of extrusion path
|
||||
if (!m_last_pos_defined || !m_last_pos.coincides_with(path.first_point())) {
|
||||
if (!m_last_pos_defined || m_last_pos != path.first_point()) {
|
||||
gcode += this->travel_to(
|
||||
path.first_point(),
|
||||
path.role(),
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
xy out(0,0);
|
||||
float temp_x = x - width / 2.f;
|
||||
float temp_y = y - depth / 2.f;
|
||||
angle *= M_PI/180.;
|
||||
angle *= float(M_PI/180.);
|
||||
out.x += (temp_x - origin.x) * cos(angle) - (temp_y - origin.y) * sin(angle);
|
||||
out.y += (temp_x - origin.x) * sin(angle) + (temp_y - origin.y) * cos(angle);
|
||||
return out + origin;
|
||||
|
@ -229,7 +229,7 @@ convex_hull(Points points)
|
||||
|
||||
hull.points.resize(k);
|
||||
|
||||
assert( hull.points.front().coincides_with(hull.points.back()) );
|
||||
assert( hull.points.front() == hull.points.back() );
|
||||
hull.points.pop_back();
|
||||
}
|
||||
|
||||
@ -910,7 +910,7 @@ MedialAxis::build(ThickPolylines* polylines)
|
||||
assert(polyline.width.size() == polyline.points.size()*2 - 2);
|
||||
|
||||
// prevent loop endpoints from being extended
|
||||
if (polyline.first_point().coincides_with(polyline.last_point())) {
|
||||
if (polyline.first_point() == polyline.last_point()) {
|
||||
polyline.endpoints.first = false;
|
||||
polyline.endpoints.second = false;
|
||||
}
|
||||
@ -1003,7 +1003,7 @@ MedialAxis::validate_edge(const VD::edge_type* edge)
|
||||
// this could maybe be optimized (checking inclusion of the endpoints
|
||||
// might give false positives as they might belong to the contour itself)
|
||||
if (this->expolygon != NULL) {
|
||||
if (line.a.coincides_with(line.b)) {
|
||||
if (line.a == line.b) {
|
||||
// in this case, contains(line) returns a false positive
|
||||
if (!this->expolygon->contains(line.a)) return false;
|
||||
} else {
|
||||
|
@ -109,7 +109,7 @@ Line::intersection_infinite(const Line &other, Point* point) const
|
||||
bool
|
||||
Line::coincides_with(const Line &line) const
|
||||
{
|
||||
return this->a.coincides_with(line.a) && this->b.coincides_with(line.b);
|
||||
return this->a == line.a && this->b == line.b;
|
||||
}
|
||||
|
||||
double
|
||||
@ -220,22 +220,19 @@ Line::ccw(const Point& point) const
|
||||
|
||||
double Line3::length() const
|
||||
{
|
||||
return (b.data - a.data).norm();
|
||||
return (b - a).norm();
|
||||
}
|
||||
|
||||
Vector3 Line3::vector() const
|
||||
{
|
||||
return Vector3(b.data - a.data);
|
||||
return Vector3(b - a);
|
||||
}
|
||||
|
||||
Pointf3
|
||||
Linef3::intersect_plane(double z) const
|
||||
Pointf3 Linef3::intersect_plane(double z) const
|
||||
{
|
||||
return Pointf3(
|
||||
this->a.x() + (this->b.x() - this->a.x()) * (z - this->a.z()) / (this->b.z() - this->a.z()),
|
||||
this->a.y() + (this->b.y() - this->a.y()) * (z - this->a.z()) / (this->b.z() - this->a.z()),
|
||||
z
|
||||
);
|
||||
Vec3d v = this->b - this->a;
|
||||
double t = (z - this->a.z()) / v.z();
|
||||
return Pointf3(this->a.x() + v.x() * t, this->a.y() + v.y() * t, z);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -210,6 +210,7 @@ public:
|
||||
|
||||
friend class ModelObject;
|
||||
|
||||
// Transform3d transform;
|
||||
double rotation; // Rotation around the Z axis, in radians around mesh center point
|
||||
double scaling_factor;
|
||||
Pointf offset; // in unscaled coordinates
|
||||
|
@ -40,9 +40,9 @@ void MultiPoint::rotate(double angle, const Point ¢er)
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
for (Point &pt : points) {
|
||||
Vec2crd dif(pt.data - center.data);
|
||||
pt.x() = (coord_t)round(double(center.x()) + c * dif[0] - s * dif[1]);
|
||||
pt.y() = (coord_t)round(double(center.y()) + c * dif[1] + s * dif[0]);
|
||||
Vec2crd v(pt - center);
|
||||
pt.x() = (coord_t)round(double(center.x()) + c * v[0] - s * v[1]);
|
||||
pt.y() = (coord_t)round(double(center.y()) + c * v[1] + s * v[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,9 +70,9 @@ MultiPoint::length() const
|
||||
int
|
||||
MultiPoint::find_point(const Point &point) const
|
||||
{
|
||||
for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
|
||||
if (it->coincides_with(point)) return it - this->points.begin();
|
||||
}
|
||||
for (const Point &pt : this->points)
|
||||
if (pt == point)
|
||||
return &pt - &this->points.front();
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ bool
|
||||
MultiPoint::has_duplicate_points() const
|
||||
{
|
||||
for (size_t i = 1; i < points.size(); ++i)
|
||||
if (points[i-1].coincides_with(points[i]))
|
||||
if (points[i-1] == points[i])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@ -103,7 +103,7 @@ MultiPoint::remove_duplicate_points()
|
||||
{
|
||||
size_t j = 0;
|
||||
for (size_t i = 1; i < points.size(); ++i) {
|
||||
if (points[j].coincides_with(points[i])) {
|
||||
if (points[j] == points[i]) {
|
||||
// Just increase index i.
|
||||
} else {
|
||||
++ j;
|
||||
@ -234,15 +234,11 @@ BoundingBox3 MultiPoint3::bounding_box() const
|
||||
bool MultiPoint3::remove_duplicate_points()
|
||||
{
|
||||
size_t j = 0;
|
||||
for (size_t i = 1; i < points.size(); ++i)
|
||||
{
|
||||
if (points[j].coincides_with(points[i]))
|
||||
{
|
||||
for (size_t i = 1; i < points.size(); ++i) {
|
||||
if (points[j] == points[i]) {
|
||||
// Just increase index i.
|
||||
}
|
||||
else
|
||||
{
|
||||
++j;
|
||||
} else {
|
||||
++ j;
|
||||
if (j < i)
|
||||
points[j] = points[i];
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ ExtrusionEntityCollection PerimeterGenerator::_variable_width(const ThickPolylin
|
||||
paths.emplace_back(std::move(path));
|
||||
// Append paths to collection.
|
||||
if (! paths.empty()) {
|
||||
if (paths.front().first_point().coincides_with(paths.back().last_point()))
|
||||
if (paths.front().first_point() == paths.back().last_point())
|
||||
coll.append(ExtrusionLoop(paths));
|
||||
else
|
||||
coll.append(paths);
|
||||
|
@ -24,8 +24,8 @@ void Point::rotate(double angle)
|
||||
{
|
||||
double cur_x = (double)this->x();
|
||||
double cur_y = (double)this->y();
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
double s = ::sin(angle);
|
||||
double c = ::cos(angle);
|
||||
this->x() = (coord_t)round(c * cur_x - s * cur_y);
|
||||
this->y() = (coord_t)round(c * cur_y + s * cur_x);
|
||||
}
|
||||
@ -34,8 +34,8 @@ void Point::rotate(double angle, const Point ¢er)
|
||||
{
|
||||
double cur_x = (double)this->x();
|
||||
double cur_y = (double)this->y();
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
double s = ::sin(angle);
|
||||
double c = ::cos(angle);
|
||||
double dx = cur_x - (double)center.x();
|
||||
double dy = cur_y - (double)center.y();
|
||||
this->x() = (coord_t)round( (double)center.x() + c * dx - s * dy );
|
||||
@ -122,7 +122,7 @@ double Point::distance_to(const Line &line) const
|
||||
|
||||
double Point::perp_distance_to(const Line &line) const
|
||||
{
|
||||
if (line.a.coincides_with(line.b)) return this->distance_to(line.a);
|
||||
if (line.a == line.b) return this->distance_to(line.a);
|
||||
|
||||
double n = (double)(line.b.x() - line.a.x()) * (double)(line.a.y() - this->y())
|
||||
- (double)(line.a.x() - this->x()) * (double)(line.b.y() - line.a.y());
|
||||
@ -176,7 +176,7 @@ Point Point::projection_onto(const MultiPoint &poly) const
|
||||
|
||||
Point Point::projection_onto(const Line &line) const
|
||||
{
|
||||
if (line.a.coincides_with(line.b)) return line.a;
|
||||
if (line.a == line.b) return line.a;
|
||||
|
||||
/*
|
||||
(Ported from VisiLibity by Karl J. Obermeyer)
|
||||
@ -226,8 +226,8 @@ void Pointf::rotate(double angle)
|
||||
{
|
||||
double cur_x = this->x();
|
||||
double cur_y = this->y();
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
double s = ::sin(angle);
|
||||
double c = ::cos(angle);
|
||||
this->x() = c * cur_x - s * cur_y;
|
||||
this->y() = c * cur_y + s * cur_x;
|
||||
}
|
||||
@ -236,8 +236,8 @@ void Pointf::rotate(double angle, const Pointf ¢er)
|
||||
{
|
||||
double cur_x = this->x();
|
||||
double cur_y = this->y();
|
||||
double s = sin(angle);
|
||||
double c = cos(angle);
|
||||
double s = ::sin(angle);
|
||||
double c = ::cos(angle);
|
||||
double dx = cur_x - center.x();
|
||||
double dy = cur_y - center.y();
|
||||
this->x() = center.x() + c * dx - s * dy;
|
||||
|
@ -35,45 +35,49 @@ 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;
|
||||
|
||||
// Vector types with a double coordinate base type.
|
||||
typedef Eigen::Matrix<float, 2, 1, Eigen::DontAlign> Vec2f;
|
||||
typedef Eigen::Matrix<float, 3, 1, Eigen::DontAlign> Vec3f;
|
||||
typedef Eigen::Matrix<coordf_t, 2, 1, Eigen::DontAlign> Vec2d;
|
||||
typedef Eigen::Matrix<coordf_t, 3, 1, Eigen::DontAlign> Vec3d;
|
||||
typedef Eigen::Matrix<double, 2, 1, Eigen::DontAlign> Vec2d;
|
||||
typedef Eigen::Matrix<double, 3, 1, Eigen::DontAlign> Vec3d;
|
||||
|
||||
typedef Eigen::Transform<float, 2, Eigen::Affine, Eigen::DontAlign> Transform2f;
|
||||
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;
|
||||
|
||||
class Point
|
||||
class Point : public Vec2crd
|
||||
{
|
||||
public:
|
||||
typedef coord_t coord_type;
|
||||
Vec2crd data;
|
||||
|
||||
Point(coord_t x = 0, coord_t y = 0) { data(0) = x; data(1) = y; }
|
||||
Point(int64_t x, int64_t y) : Point(coord_t(x), coord_t(y)) {} // for Clipper
|
||||
Point(double x, double y) : Point(lrint(x), lrint(y)) {}
|
||||
explicit Point(const Vec2crd &rhs) { this->data = rhs; }
|
||||
explicit Point(Vec2crd &&rhs) { this->data = std::move(rhs); }
|
||||
Point() : Vec2crd() { (*this)(0) = 0; (*this)(1) = 0; }
|
||||
Point(coord_t x, coord_t y) { (*this)(0) = x; (*this)(1) = y; }
|
||||
Point(int64_t x, int64_t y) { (*this)(0) = coord_t(x); (*this)(1) = coord_t(y); } // for Clipper
|
||||
Point(double x, double y) { (*this)(0) = coord_t(lrint(x)); (*this)(1) = coord_t(lrint(y)); }
|
||||
Point(const Point &rhs) { *this = rhs; }
|
||||
// This constructor allows you to construct Point from Eigen expressions
|
||||
template<typename OtherDerived>
|
||||
Point(const Eigen::MatrixBase<OtherDerived> &other) : Vec2crd(other) {}
|
||||
static Point new_scale(coordf_t x, coordf_t y) { return Point(coord_t(scale_(x)), coord_t(scale_(y))); }
|
||||
|
||||
const coord_t& x() const { return this->data[0]; }
|
||||
coord_t& x() { return this->data[0]; }
|
||||
const coord_t& y() const { return this->data[1]; }
|
||||
coord_t& y() { return this->data[1]; }
|
||||
// This method allows you to assign Eigen expressions to MyVectorType
|
||||
template<typename OtherDerived>
|
||||
Point& operator=(const Eigen::MatrixBase<OtherDerived> &other)
|
||||
{
|
||||
this->Point::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator const Vec2crd& () const { return this->data; }
|
||||
operator Vec2crd& () { return this->data; }
|
||||
template<typename T> Eigen::Matrix<T, 2, 1, Eigen::DontAlign> cast() const { return this->data.cast<T>(); }
|
||||
|
||||
Point& operator=(const Vec2crd &rhs) { this->data = rhs; return *this; }
|
||||
Point& operator=(Vec2crd &&rhs) { this->data = std::move(rhs); return *this; }
|
||||
const coord_t& x() const { return (*this)(0); }
|
||||
coord_t& x() { return (*this)(0); }
|
||||
const coord_t& y() const { return (*this)(1); }
|
||||
coord_t& y() { return (*this)(1); }
|
||||
|
||||
bool operator==(const Point& rhs) const { return this->x() == rhs.x() && this->y() == rhs.y(); }
|
||||
bool operator!=(const Point& rhs) const { return ! (*this == rhs); }
|
||||
bool operator<(const Point& rhs) const { return this->x() < rhs.x() || (this->x() == rhs.x() && this->y() < rhs.y()); }
|
||||
bool operator< (const Point& rhs) const { return this->x() < rhs.x() || (this->x() == rhs.x() && this->y() < rhs.y()); }
|
||||
|
||||
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; }
|
||||
@ -81,30 +85,30 @@ public:
|
||||
|
||||
std::string wkt() const;
|
||||
std::string dump_perl() const;
|
||||
void scale(double factor) { this->data *= factor; }
|
||||
void translate(double x, double y) { this->data += Vec2crd(x, y); }
|
||||
void translate(const Vector &vector) { this->data += vector.data; }
|
||||
void rotate(double angle);
|
||||
void rotate(double angle, const Point ¢er);
|
||||
Point rotated(double angle) const { Point res(*this); res.rotate(angle); return res; }
|
||||
Point rotated(double angle, const Point ¢er) const { Point res(*this); res.rotate(angle, center); return res; }
|
||||
bool coincides_with(const Point &point) const { return this->x() == point.x() && this->y() == point.y(); }
|
||||
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 sqrt(distance_to_sq(point)); }
|
||||
double distance_to_sq(const Point &point) const { double dx = double(point.x() - this->x()); double dy = double(point.y() - this->y()); return dx*dx + dy*dy; }
|
||||
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 ¢er);
|
||||
Point rotated(double angle) const { Point res(*this); res.rotate(angle); return res; }
|
||||
Point rotated(double angle, const Point ¢er) 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->data); }
|
||||
Vector vector_to(const Point &point) const { return Vector(point.data - this->data); }
|
||||
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()); }
|
||||
@ -223,70 +227,77 @@ private:
|
||||
coord_t m_grid_log2;
|
||||
};
|
||||
|
||||
class Point3
|
||||
class Point3 : public Vec3crd
|
||||
{
|
||||
public:
|
||||
typedef coord_t coord_type;
|
||||
Vec3crd data;
|
||||
|
||||
const coord_t& x() const { return this->data[0]; }
|
||||
coord_t& x() { return this->data[0]; }
|
||||
const coord_t& y() const { return this->data[1]; }
|
||||
coord_t& y() { return this->data[1]; }
|
||||
const coord_t& z() const { return this->data[2]; }
|
||||
coord_t& z() { return this->data[2]; }
|
||||
|
||||
operator const Vec3crd& () const { return this->data; }
|
||||
operator Vec3crd& () { return this->data; }
|
||||
template<typename T> Eigen::Matrix<T, 3, 1, Eigen::DontAlign> cast() const { return this->data.cast<T>(); }
|
||||
|
||||
explicit Point3(coord_t _x = 0, coord_t _y = 0, coord_t _z = 0) { this->data[0] = _x; this->data[1] = _y; this->data[2] = _z; }
|
||||
explicit Point3(const Vec3crd &rhs) { this->data = rhs; }
|
||||
explicit Point3(Vec3crd &&rhs) { this->data = std::move(rhs); }
|
||||
explicit Point3() { (*this)(0) = (*this)(1) = (*this)(2) = 0; }
|
||||
explicit Point3(coord_t x, coord_t y, coord_t z) { (*this)(0) = x; (*this)(1) = y; (*this)(2) = z; }
|
||||
// This constructor allows you to construct Point3 from Eigen expressions
|
||||
template<typename OtherDerived>
|
||||
Point3(const Eigen::MatrixBase<OtherDerived> &other) : Vec3crd(other) {}
|
||||
static Point3 new_scale(coordf_t x, coordf_t y, coordf_t z) { return Point3(coord_t(scale_(x)), coord_t(scale_(y)), coord_t(scale_(z))); }
|
||||
Point3& operator=(const Vec3crd &rhs) { this->data = rhs; return *this; }
|
||||
Point3& operator=(Vec3crd &&rhs) { this->data = std::move(rhs); return *this; }
|
||||
bool operator==(const Point3 &rhs) const { return this->x() == rhs.x() && this->y() == rhs.y() && this->z() == rhs.z(); }
|
||||
bool operator!=(const Point3 &rhs) const { return ! (*this == rhs); }
|
||||
bool coincides_with(const Point3& rhs) const { return this->x() == rhs.x() && this->y() == rhs.y() && this->z() == rhs.z(); }
|
||||
|
||||
Point xy() const { return Point(this->x(), this->y()); }
|
||||
// This method allows you to assign Eigen expressions to MyVectorType
|
||||
template<typename OtherDerived>
|
||||
Point3& operator=(const Eigen::MatrixBase<OtherDerived> &other)
|
||||
{
|
||||
this->Point3::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const coord_t& x() const { return (*this)(0); }
|
||||
coord_t& x() { return (*this)(0); }
|
||||
const coord_t& y() const { return (*this)(1); }
|
||||
coord_t& y() { return (*this)(1); }
|
||||
const coord_t& z() const { return (*this)(2); }
|
||||
coord_t& z() { return (*this)(2); }
|
||||
|
||||
bool operator==(const Point3 &rhs) const { return this->x() == rhs.x() && this->y() == rhs.y() && this->z() == rhs.z(); }
|
||||
bool operator!=(const Point3 &rhs) const { return ! (*this == rhs); }
|
||||
|
||||
Point xy() const { return Point(this->x(), this->y()); }
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream &stm, const Pointf &pointf);
|
||||
|
||||
class Pointf
|
||||
class Pointf : public Vec2d
|
||||
{
|
||||
public:
|
||||
typedef coordf_t coord_type;
|
||||
Vec2d data;
|
||||
|
||||
explicit Pointf(coordf_t x = 0, coordf_t y = 0) { data(0) = x; data(1) = y; }
|
||||
explicit Pointf(const Vec2d &rhs) { this->data = rhs; }
|
||||
explicit Pointf(Vec2d &&rhs) { this->data = std::move(rhs); }
|
||||
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>
|
||||
Pointf(const Eigen::MatrixBase<OtherDerived> &other) : Vec2d(other) {}
|
||||
static Pointf new_unscale(coord_t x, coord_t y) { return Pointf(unscale(x), unscale(y)); }
|
||||
static Pointf new_unscale(const Point &p) { return Pointf(unscale(p.x()), unscale(p.y())); }
|
||||
Pointf& operator=(const Vec2d &rhs) { this->data = rhs; return *this; }
|
||||
Pointf& operator=(Vec2d &&rhs) { this->data = std::move(rhs); return *this; }
|
||||
|
||||
const coordf_t& x() const { return this->data[0]; }
|
||||
coordf_t& x() { return this->data[0]; }
|
||||
const coordf_t& y() const { return this->data[1]; }
|
||||
coordf_t& y() { return this->data[1]; }
|
||||
// This method allows you to assign Eigen expressions to MyVectorType
|
||||
template<typename OtherDerived>
|
||||
Pointf& operator=(const Eigen::MatrixBase<OtherDerived> &other)
|
||||
{
|
||||
this->Pointf::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator const Vec2d& () const { return this->data; }
|
||||
operator Vec2d& () { return this->data; }
|
||||
template<typename T> Eigen::Matrix<T, 2, 1, Eigen::DontAlign> cast() const { return this->data.cast<T>(); }
|
||||
const coordf_t& x() const { return (*this)(0); }
|
||||
coordf_t& x() { return (*this)(0); }
|
||||
const coordf_t& y() const { return (*this)(1); }
|
||||
coordf_t& y() { return (*this)(1); }
|
||||
|
||||
std::string wkt() const;
|
||||
std::string dump_perl() const;
|
||||
void scale(double factor) { this->data *= factor; }
|
||||
void translate(double x, double y) { this->data += Vec2d(x, y); }
|
||||
void translate(const Vectorf &vector) { this->data += vector.data; }
|
||||
void rotate(double angle);
|
||||
void rotate(double angle, const Pointf ¢er);
|
||||
Pointf negative() const { return Pointf(- this->data); }
|
||||
Vectorf vector_to(const Pointf &point) const { return Vectorf(point.data - this->data); }
|
||||
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 ¢er);
|
||||
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; }
|
||||
@ -311,37 +322,41 @@ inline Vectorf normalize(const Vectorf& v)
|
||||
return (len != 0.0) ? 1.0 / len * v : Vectorf(0.0, 0.0);
|
||||
}
|
||||
|
||||
class Pointf3
|
||||
class Pointf3 : public Vec3d
|
||||
{
|
||||
public:
|
||||
typedef coordf_t coord_type;
|
||||
Vec3d data;
|
||||
|
||||
const coordf_t& x() const { return this->data[0]; }
|
||||
coordf_t& x() { return this->data[0]; }
|
||||
const coordf_t& y() const { return this->data[1]; }
|
||||
coordf_t& y() { return this->data[1]; }
|
||||
const coordf_t& z() const { return this->data[2]; }
|
||||
coordf_t& z() { return this->data[2]; }
|
||||
|
||||
operator const Vec3d& () const { return this->data; }
|
||||
operator Vec3d& () { return this->data; }
|
||||
template<typename T> Eigen::Matrix<T, 3, 1, Eigen::DontAlign> cast() const { return this->data.cast<T>(); }
|
||||
|
||||
explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0) { this->data[0] = _x; this->data[1] = _y; this->data[2] = _z; }
|
||||
explicit Pointf3(const Vec3d &rhs) { this->data = rhs; }
|
||||
explicit Pointf3(Vec3d &&rhs) { this->data = std::move(rhs); }
|
||||
explicit Pointf3() { (*this)(0) = (*this)(1) = (*this)(2) = 0.; }
|
||||
// explicit Pointf3(coord_t x, coord_t y, coord_t z) { (*this)(0) = x; (*this)(1) = y; (*this)(2) = z; }
|
||||
explicit Pointf3(coordf_t x, coordf_t y, coordf_t z) { (*this)(0) = x; (*this)(1) = y; (*this)(2) = z; }
|
||||
// This constructor allows you to construct Pointf from Eigen expressions
|
||||
template<typename OtherDerived>
|
||||
Pointf3(const Eigen::MatrixBase<OtherDerived> &other) : Vec3d(other) {}
|
||||
static Pointf3 new_unscale(coord_t x, coord_t y, coord_t z) { return Pointf3(unscale(x), unscale(y), unscale(z)); }
|
||||
static Pointf3 new_unscale(const Point3& p) { return Pointf3(unscale(p.x()), unscale(p.y()), unscale(p.z())); }
|
||||
Pointf3& operator=(const Vec3d &rhs) { this->data = rhs; return *this; }
|
||||
Pointf3& operator=(Vec3d &&rhs) { this->data = std::move(rhs); return *this; }
|
||||
|
||||
void scale(double factor) { this->data *= factor; }
|
||||
void translate(const Vectorf3 &vector) { this->data += vector.data; }
|
||||
void translate(double x, double y, double z) { this->data += Vec3d(x, y, z); }
|
||||
double distance_to(const Pointf3 &point) const { return (point.data - this->data).norm(); }
|
||||
Pointf3 negative() const { return Pointf3(- this->data); }
|
||||
Vectorf3 vector_to(const Pointf3 &point) const { return Vectorf3(point.data - this->data); }
|
||||
// This method allows you to assign Eigen expressions to MyVectorType
|
||||
template<typename OtherDerived>
|
||||
Pointf3& operator=(const Eigen::MatrixBase<OtherDerived> &other)
|
||||
{
|
||||
this->Pointf3::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const coordf_t& x() const { return (*this)(0); }
|
||||
coordf_t& x() { return (*this)(0); }
|
||||
const coordf_t& y() const { return (*this)(1); }
|
||||
coordf_t& y() { return (*this)(1); }
|
||||
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); }
|
||||
|
@ -44,11 +44,9 @@ Polyline
|
||||
Polygon::split_at_vertex(const Point &point) const
|
||||
{
|
||||
// find index of point
|
||||
for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
|
||||
if (it->coincides_with(point)) {
|
||||
return this->split_at_index(it - this->points.begin());
|
||||
}
|
||||
}
|
||||
for (const Point &pt : this->points)
|
||||
if (pt == point)
|
||||
return this->split_at_index(&pt - &this->points.front());
|
||||
CONFESS("Point not found");
|
||||
return Polyline();
|
||||
}
|
||||
|
@ -178,9 +178,9 @@ Polyline::split_at(const Point &point, Polyline* p1, Polyline* p2) const
|
||||
|
||||
// create first half
|
||||
p1->points.clear();
|
||||
for (Lines::const_iterator line = lines.begin(); line != lines.begin() + line_idx + 1; ++line) {
|
||||
if (!line->a.coincides_with(p)) p1->points.push_back(line->a);
|
||||
}
|
||||
for (Lines::const_iterator line = lines.begin(); line != lines.begin() + line_idx + 1; ++line)
|
||||
if (line->a != p)
|
||||
p1->points.push_back(line->a);
|
||||
// we add point instead of p because they might differ because of numerical issues
|
||||
// and caller might want to rely on point belonging to result polylines
|
||||
p1->points.push_back(point);
|
||||
|
@ -1052,7 +1052,10 @@ void Print::_make_wipe_tower()
|
||||
return;
|
||||
|
||||
// Get wiping matrix to get number of extruders and convert vector<double> to vector<float>:
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4244) // disable Visual Studio's warning: conversion from 'double' to 'float', possible loss of data
|
||||
std::vector<float> wiping_matrix((this->config.wiping_volumes_matrix.values).begin(),(this->config.wiping_volumes_matrix.values).end());
|
||||
#pragma warning(pop)
|
||||
// Extract purging volumes for each extruder pair:
|
||||
std::vector<std::vector<float>> wipe_volumes;
|
||||
const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON);
|
||||
|
@ -280,7 +280,7 @@ const Transform3f& GLVolume::world_matrix() const
|
||||
{
|
||||
m_world_mat = Transform3f::Identity();
|
||||
m_world_mat.translate(Vec3f(m_origin.x(), m_origin.y(), 0));
|
||||
m_world_mat.rotate(Eigen::AngleAxisf(m_angle_z, Eigen::Vector3f::UnitZ()));
|
||||
m_world_mat.rotate(Eigen::AngleAxisf(m_angle_z, Vec3f::UnitZ()));
|
||||
m_world_mat.scale(m_scale_factor);
|
||||
m_dirty = false;
|
||||
}
|
||||
|
@ -1947,7 +1947,7 @@ void GLCanvas3D::set_auto_bed_shape()
|
||||
// draw a default square bed around object center
|
||||
const BoundingBoxf3& bbox = volumes_bounding_box();
|
||||
coordf_t max_size = bbox.max_size();
|
||||
const Pointf3& center = bbox.center();
|
||||
const Pointf3 center = bbox.center();
|
||||
|
||||
Pointfs bed_shape;
|
||||
bed_shape.reserve(4);
|
||||
@ -3101,7 +3101,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
||||
{
|
||||
// The mouse_to_3d gets the Z coordinate from the Z buffer at the screen coordinate pos x, y,
|
||||
// an converts the screen space coordinate to unscaled object space.
|
||||
Pointf3 pos3d = (volume_idx == -1) ? Pointf3(DBL_MAX, DBL_MAX) : _mouse_to_3d(pos);
|
||||
Pointf3 pos3d = (volume_idx == -1) ? Pointf3(DBL_MAX, DBL_MAX, DBL_MAX) : _mouse_to_3d(pos);
|
||||
|
||||
// Only accept the initial position, if it is inside the volume bounding box.
|
||||
BoundingBoxf3 volume_bbox = m_volumes.volumes[volume_idx]->transformed_bounding_box();
|
||||
|
@ -891,10 +891,13 @@ void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFl
|
||||
g_wiping_dialog_button->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent& e)
|
||||
{
|
||||
auto &config = g_PresetBundle->project_config;
|
||||
std::vector<double> init_matrix = (config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
|
||||
std::vector<double> init_extruders = (config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
|
||||
const std::vector<double> &init_matrix = (config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
|
||||
const std::vector<double> &init_extruders = (config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4244) // disable Visual Studio's warning: conversion from 'double' to 'float', possible loss of data
|
||||
WipingDialog dlg(parent,std::vector<float>(init_matrix.begin(),init_matrix.end()),std::vector<float>(init_extruders.begin(),init_extruders.end()));
|
||||
#pragma warning(pop)
|
||||
|
||||
if (dlg.ShowModal() == wxID_OK) {
|
||||
std::vector<float> matrix = dlg.get_matrix();
|
||||
|
@ -48,7 +48,7 @@
|
||||
Clone<Point> negative()
|
||||
%code{% RETVAL = new Point(THIS->negative()); %};
|
||||
bool coincides_with_epsilon(Point* point)
|
||||
%code{% RETVAL = THIS->coincides_with_epsilon(*point); %};
|
||||
%code{% RETVAL = (*THIS) == *point; %};
|
||||
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", THIS->x(), THIS->y()); RETVAL = buf; %};
|
||||
|
||||
%{
|
||||
@ -68,7 +68,7 @@ Point::coincides_with(point_sv)
|
||||
CODE:
|
||||
Point point;
|
||||
from_SV_check(point_sv, &point);
|
||||
RETVAL = THIS->coincides_with(point);
|
||||
RETVAL = (*THIS) == point;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user