mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 11:17:51 -06:00
Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types:
Changed the Point3 / Pointf3 to composite Eigen Vec3crd / Vec3d. Point3 is no more derived from Point, Pointf3 is no more derived from Pointf. Introduced Transform2f/3f/2d/3d types as aliases to Eigen::Transform.
This commit is contained in:
parent
86da661097
commit
f34252a27b
15 changed files with 197 additions and 303 deletions
|
@ -13,36 +13,14 @@ std::string Point::wkt() const
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
std::string
|
||||
Point::dump_perl() const
|
||||
std::string Point::dump_perl() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "[" << this->x() << "," << this->y() << "]";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void
|
||||
Point::scale(double factor)
|
||||
{
|
||||
this->x() *= factor;
|
||||
this->y() *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
Point::translate(double x, double y)
|
||||
{
|
||||
this->x() += x;
|
||||
this->y() += y;
|
||||
}
|
||||
|
||||
void
|
||||
Point::translate(const Vector &vector)
|
||||
{
|
||||
this->translate(vector.x(), vector.y());
|
||||
}
|
||||
|
||||
void
|
||||
Point::rotate(double angle)
|
||||
void Point::rotate(double angle)
|
||||
{
|
||||
double cur_x = (double)this->x();
|
||||
double cur_y = (double)this->y();
|
||||
|
@ -52,8 +30,7 @@ Point::rotate(double angle)
|
|||
this->y() = (coord_t)round(c * cur_y + s * cur_x);
|
||||
}
|
||||
|
||||
void
|
||||
Point::rotate(double angle, const Point ¢er)
|
||||
void Point::rotate(double angle, const Point ¢er)
|
||||
{
|
||||
double cur_x = (double)this->x();
|
||||
double cur_y = (double)this->y();
|
||||
|
@ -65,14 +42,12 @@ Point::rotate(double angle, const Point ¢er)
|
|||
this->y() = (coord_t)round( (double)center.y() + c * dy + s * dx );
|
||||
}
|
||||
|
||||
bool
|
||||
Point::coincides_with_epsilon(const Point &point) const
|
||||
bool Point::coincides_with_epsilon(const Point &point) const
|
||||
{
|
||||
return std::abs(this->x() - point.x()) < SCALED_EPSILON && std::abs(this->y() - point.y()) < SCALED_EPSILON;
|
||||
}
|
||||
|
||||
int
|
||||
Point::nearest_point_index(const Points &points) const
|
||||
int Point::nearest_point_index(const Points &points) const
|
||||
{
|
||||
PointConstPtrs p;
|
||||
p.reserve(points.size());
|
||||
|
@ -106,8 +81,7 @@ int Point::nearest_point_index(const PointConstPtrs &points) const
|
|||
return idx;
|
||||
}
|
||||
|
||||
int
|
||||
Point::nearest_point_index(const PointPtrs &points) const
|
||||
int Point::nearest_point_index(const PointPtrs &points) const
|
||||
{
|
||||
PointConstPtrs p;
|
||||
p.reserve(points.size());
|
||||
|
@ -116,8 +90,7 @@ Point::nearest_point_index(const PointPtrs &points) const
|
|||
return this->nearest_point_index(p);
|
||||
}
|
||||
|
||||
bool
|
||||
Point::nearest_point(const Points &points, Point* point) const
|
||||
bool Point::nearest_point(const Points &points, Point* point) const
|
||||
{
|
||||
int idx = this->nearest_point_index(points);
|
||||
if (idx == -1) return false;
|
||||
|
@ -126,8 +99,7 @@ Point::nearest_point(const Points &points, Point* point) const
|
|||
}
|
||||
|
||||
/* distance to the closest point of line */
|
||||
double
|
||||
Point::distance_to(const Line &line) const
|
||||
double Point::distance_to(const Line &line) const
|
||||
{
|
||||
const double dx = line.b.x() - line.a.x();
|
||||
const double dy = line.b.y() - line.a.y();
|
||||
|
@ -148,8 +120,7 @@ Point::distance_to(const Line &line) const
|
|||
return this->distance_to(projection);
|
||||
}
|
||||
|
||||
double
|
||||
Point::perp_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);
|
||||
|
||||
|
@ -166,22 +137,19 @@ Point::perp_distance_to(const Line &line) const
|
|||
* z-component of their 3D cross product.
|
||||
* We return double because it must be big enough to hold 2*max(|coordinate|)^2
|
||||
*/
|
||||
double
|
||||
Point::ccw(const Point &p1, const Point &p2) const
|
||||
double Point::ccw(const Point &p1, const Point &p2) const
|
||||
{
|
||||
return (double)(p2.x() - p1.x())*(double)(this->y() - p1.y()) - (double)(p2.y() - p1.y())*(double)(this->x() - p1.x());
|
||||
}
|
||||
|
||||
double
|
||||
Point::ccw(const Line &line) const
|
||||
double Point::ccw(const Line &line) const
|
||||
{
|
||||
return this->ccw(line.a, line.b);
|
||||
}
|
||||
|
||||
// returns the CCW angle between this-p1 and this-p2
|
||||
// i.e. this assumes a CCW rotation from p1 to p2 around this
|
||||
double
|
||||
Point::ccw_angle(const Point &p1, const Point &p2) const
|
||||
double Point::ccw_angle(const Point &p1, const Point &p2) const
|
||||
{
|
||||
double angle = atan2(p1.x() - this->x(), p1.y() - this->y())
|
||||
- atan2(p2.x() - this->x(), p2.y() - this->y());
|
||||
|
@ -190,8 +158,7 @@ Point::ccw_angle(const Point &p1, const Point &p2) const
|
|||
return angle <= 0 ? angle + 2*PI : angle;
|
||||
}
|
||||
|
||||
Point
|
||||
Point::projection_onto(const MultiPoint &poly) const
|
||||
Point Point::projection_onto(const MultiPoint &poly) const
|
||||
{
|
||||
Point running_projection = poly.first_point();
|
||||
double running_min = this->distance_to(running_projection);
|
||||
|
@ -207,8 +174,7 @@ Point::projection_onto(const MultiPoint &poly) const
|
|||
return running_projection;
|
||||
}
|
||||
|
||||
Point
|
||||
Point::projection_onto(const Line &line) const
|
||||
Point Point::projection_onto(const Line &line) const
|
||||
{
|
||||
if (line.a.coincides_with(line.b)) return line.a;
|
||||
|
||||
|
@ -237,62 +203,26 @@ Point::projection_onto(const Line &line) const
|
|||
}
|
||||
}
|
||||
|
||||
Point
|
||||
Point::negative() const
|
||||
{
|
||||
return Point(-this->x(), -this->y());
|
||||
}
|
||||
|
||||
Vector
|
||||
Point::vector_to(const Point &point) const
|
||||
{
|
||||
return Vector(point.x() - this->x(), point.y() - this->y());
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream &stm, const Pointf &pointf)
|
||||
std::ostream& operator<<(std::ostream &stm, const Pointf &pointf)
|
||||
{
|
||||
return stm << pointf.x() << "," << pointf.y();
|
||||
}
|
||||
|
||||
std::string
|
||||
Pointf::wkt() const
|
||||
std::string Pointf::wkt() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "POINT(" << this->x() << " " << this->y() << ")";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string
|
||||
Pointf::dump_perl() const
|
||||
std::string Pointf::dump_perl() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "[" << this->x() << "," << this->y() << "]";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void
|
||||
Pointf::scale(double factor)
|
||||
{
|
||||
this->x() *= factor;
|
||||
this->y() *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf::translate(double x, double y)
|
||||
{
|
||||
this->x() += x;
|
||||
this->y() += y;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf::translate(const Vectorf &vector)
|
||||
{
|
||||
this->translate(vector.x(), vector.y());
|
||||
}
|
||||
|
||||
void
|
||||
Pointf::rotate(double angle)
|
||||
void Pointf::rotate(double angle)
|
||||
{
|
||||
double cur_x = this->x();
|
||||
double cur_y = this->y();
|
||||
|
@ -302,8 +232,7 @@ Pointf::rotate(double angle)
|
|||
this->y() = c * cur_y + s * cur_x;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf::rotate(double angle, const Pointf ¢er)
|
||||
void Pointf::rotate(double angle, const Pointf ¢er)
|
||||
{
|
||||
double cur_x = this->x();
|
||||
double cur_y = this->y();
|
||||
|
@ -315,59 +244,6 @@ Pointf::rotate(double angle, const Pointf ¢er)
|
|||
this->y() = center.y() + c * dy + s * dx;
|
||||
}
|
||||
|
||||
Pointf
|
||||
Pointf::negative() const
|
||||
{
|
||||
return Pointf(-this->x(), -this->y());
|
||||
}
|
||||
|
||||
Vectorf
|
||||
Pointf::vector_to(const Pointf &point) const
|
||||
{
|
||||
return Vectorf(point.x() - this->x(), point.y() - this->y());
|
||||
}
|
||||
|
||||
void
|
||||
Pointf3::scale(double factor)
|
||||
{
|
||||
Pointf::scale(factor);
|
||||
this->z() *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
Pointf3::translate(const Vectorf3 &vector)
|
||||
{
|
||||
this->translate(vector.x(), vector.y(), vector.z());
|
||||
}
|
||||
|
||||
void
|
||||
Pointf3::translate(double x, double y, double z)
|
||||
{
|
||||
Pointf::translate(x, y);
|
||||
this->z() += z;
|
||||
}
|
||||
|
||||
double
|
||||
Pointf3::distance_to(const Pointf3 &point) const
|
||||
{
|
||||
double dx = ((double)point.x() - this->x());
|
||||
double dy = ((double)point.y() - this->y());
|
||||
double dz = ((double)point.z() - this->z());
|
||||
return sqrt(dx*dx + dy*dy + dz*dz);
|
||||
}
|
||||
|
||||
Pointf3
|
||||
Pointf3::negative() const
|
||||
{
|
||||
return Pointf3(-this->x(), -this->y(), -this->z());
|
||||
}
|
||||
|
||||
Vectorf3
|
||||
Pointf3::vector_to(const Pointf3 &point) const
|
||||
{
|
||||
return Vectorf3(point.x() - this->x(), point.y() - this->y(), point.z() - this->z());
|
||||
}
|
||||
|
||||
namespace int128 {
|
||||
|
||||
int orient(const Point &p1, const Point &p2, const Point &p3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue