mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 15:13:58 -06:00
Removed the x(), y(), z() Point/Pointf/Point3/Pointf3 accessors.
This commit is contained in:
parent
1ba64da3fe
commit
65011f9382
60 changed files with 1083 additions and 1111 deletions
|
@ -86,7 +86,7 @@ int64_t Polygon::area2x() const
|
|||
|
||||
int64_t a = 0;
|
||||
for (size_t i = 0, j = n - 1; i < n; ++i)
|
||||
a += int64_t(poly[j].x() + poly[i].x()) * int64_t(poly[j].y() - poly[i].y());
|
||||
a += int64_t(poly[j](0) + poly[i](0)) * int64_t(poly[j](1) - poly[i](1));
|
||||
j = i;
|
||||
}
|
||||
return -a * 0.5;
|
||||
|
@ -101,7 +101,7 @@ double Polygon::area() const
|
|||
|
||||
double a = 0.;
|
||||
for (size_t i = 0, j = n - 1; i < n; ++i) {
|
||||
a += ((double)points[j].x() + (double)points[i].x()) * ((double)points[i].y() - (double)points[j].y());
|
||||
a += ((double)points[j](0) + (double)points[i](0)) * ((double)points[i](1) - (double)points[j](1));
|
||||
j = i;
|
||||
}
|
||||
return 0.5 * a;
|
||||
|
@ -155,17 +155,17 @@ Polygon::contains(const Point &point) const
|
|||
Points::const_iterator i = this->points.begin();
|
||||
Points::const_iterator j = this->points.end() - 1;
|
||||
for (; i != this->points.end(); j = i++) {
|
||||
//FIXME this test is not numerically robust. Particularly, it does not handle horizontal segments at y == point.y() well.
|
||||
// Does the ray with y == point.y() intersect this line segment?
|
||||
//FIXME this test is not numerically robust. Particularly, it does not handle horizontal segments at y == point(1) well.
|
||||
// Does the ray with y == point(1) intersect this line segment?
|
||||
#if 1
|
||||
if ( ((i->y() > point.y()) != (j->y() > point.y()))
|
||||
&& ((double)point.x() < (double)(j->x() - i->x()) * (double)(point.y() - i->y()) / (double)(j->y() - i->y()) + (double)i->x()) )
|
||||
if ( (((*i)(1) > point(1)) != ((*j)(1) > point(1)))
|
||||
&& ((double)point(0) < (double)((*j)(0) - (*i)(0)) * (double)(point(1) - (*i)(1)) / (double)((*j)(1) - (*i)(1)) + (double)(*i)(0)) )
|
||||
result = !result;
|
||||
#else
|
||||
if ((i->y() > point.y()) != (j->y() > point.y())) {
|
||||
if (((*i)(1) > point(1)) != ((*j)(1) > point(1))) {
|
||||
// Orientation predicated relative to i-th point.
|
||||
double orient = (double)(point.x() - i->x()) * (double)(j->y() - i->y()) - (double)(point.y() - i->y()) * (double)(j->x() - i->x());
|
||||
if ((i->y() > j->y()) ? (orient > 0.) : (orient < 0.))
|
||||
double orient = (double)(point(0) - (*i)(0)) * (double)((*j)(1) - (*i)(1)) - (double)(point(1) - (*i)(1)) * (double)((*j)(0) - (*i)(0));
|
||||
if (((*i)(1) > (*j)(1)) ? (orient > 0.) : (orient < 0.))
|
||||
result = !result;
|
||||
}
|
||||
#endif
|
||||
|
@ -310,13 +310,13 @@ Point Polygon::point_projection(const Point &point) const
|
|||
dmin = d;
|
||||
proj = pt1;
|
||||
}
|
||||
Pointf v1(coordf_t(pt1.x() - pt0.x()), coordf_t(pt1.y() - pt0.y()));
|
||||
Pointf v1(coordf_t(pt1(0) - pt0(0)), coordf_t(pt1(1) - pt0(1)));
|
||||
coordf_t div = v1.squaredNorm();
|
||||
if (div > 0.) {
|
||||
Pointf v2(coordf_t(point.x() - pt0.x()), coordf_t(point.y() - pt0.y()));
|
||||
Pointf v2(coordf_t(point(0) - pt0(0)), coordf_t(point(1) - pt0(1)));
|
||||
coordf_t t = v1.dot(v2) / div;
|
||||
if (t > 0. && t < 1.) {
|
||||
Point foot(coord_t(floor(coordf_t(pt0.x()) + t * v1.x() + 0.5)), coord_t(floor(coordf_t(pt0.y()) + t * v1.y() + 0.5)));
|
||||
Point foot(coord_t(floor(coordf_t(pt0(0)) + t * v1(0) + 0.5)), coord_t(floor(coordf_t(pt0(1)) + t * v1(1) + 0.5)));
|
||||
d = (point - foot).cast<double>().norm();
|
||||
if (d < dmin) {
|
||||
dmin = d;
|
||||
|
@ -374,12 +374,12 @@ static inline bool is_stick(const Point &p1, const Point &p2, const Point &p3)
|
|||
{
|
||||
Point v1 = p2 - p1;
|
||||
Point v2 = p3 - p2;
|
||||
int64_t dir = int64_t(v1.x()) * int64_t(v2.x()) + int64_t(v1.y()) * int64_t(v2.y());
|
||||
int64_t dir = int64_t(v1(0)) * int64_t(v2(0)) + int64_t(v1(1)) * int64_t(v2(1));
|
||||
if (dir > 0)
|
||||
// p3 does not turn back to p1. Do not remove p2.
|
||||
return false;
|
||||
double l2_1 = double(v1.x()) * double(v1.x()) + double(v1.y()) * double(v1.y());
|
||||
double l2_2 = double(v2.x()) * double(v2.x()) + double(v2.y()) * double(v2.y());
|
||||
double l2_1 = double(v1(0)) * double(v1(0)) + double(v1(1)) * double(v1(1));
|
||||
double l2_2 = double(v2(0)) * double(v2(0)) + double(v2(1)) * double(v2(1));
|
||||
if (dir == 0)
|
||||
// p1, p2, p3 may make a perpendicular corner, or there is a zero edge length.
|
||||
// Remove p2 if it is coincident with p1 or p2.
|
||||
|
@ -387,7 +387,7 @@ static inline bool is_stick(const Point &p1, const Point &p2, const Point &p3)
|
|||
// p3 turns back to p1 after p2. Are p1, p2, p3 collinear?
|
||||
// Calculate distance from p3 to a segment (p1, p2) or from p1 to a segment(p2, p3),
|
||||
// whichever segment is longer
|
||||
double cross = double(v1.x()) * double(v2.y()) - double(v2.x()) * double(v1.y());
|
||||
double cross = double(v1(0)) * double(v2(1)) - double(v2(0)) * double(v1(1));
|
||||
double dist2 = cross * cross / std::max(l2_1, l2_2);
|
||||
return dist2 < EPSILON * EPSILON;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue