mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
Fix of Polygon::area().
This commit is contained in:
parent
feefbc575a
commit
68fabfea62
1 changed files with 7 additions and 23 deletions
|
@ -33,32 +33,16 @@ Polyline Polygon::split_at_index(int index) const
|
||||||
return polyline;
|
return polyline;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int64_t Polygon::area2x() const
|
|
||||||
{
|
|
||||||
size_t n = poly.size();
|
|
||||||
if (n < 3)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int64_t a = 0;
|
|
||||||
for (size_t i = 0, j = n - 1; i < n; ++i)
|
|
||||||
a += int64_t(poly[j](0) + poly[i](0)) * int64_t(poly[j](1) - poly[i](1));
|
|
||||||
j = i;
|
|
||||||
}
|
|
||||||
return -a * 0.5;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
double Polygon::area(const Points &points)
|
double Polygon::area(const Points &points)
|
||||||
{
|
{
|
||||||
size_t n = points.size();
|
|
||||||
if (n < 3)
|
|
||||||
return 0.;
|
|
||||||
|
|
||||||
double a = 0.;
|
double a = 0.;
|
||||||
for (size_t i = 0, j = n - 1; i < n; ++i) {
|
if (points.size() >= 3) {
|
||||||
a += ((double)points[j](0) + (double)points[i](0)) * ((double)points[i](1) - (double)points[j](1));
|
Vec2d p1 = points.back().cast<double>();
|
||||||
j = i;
|
for (const Point &p : points) {
|
||||||
|
Vec2d p2 = p.cast<double>();
|
||||||
|
a += cross2(p1, p2);
|
||||||
|
p1 = p2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0.5 * a;
|
return 0.5 * a;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue