Ported ExPolygon->area()
This commit is contained in:
parent
792fcba7be
commit
706851f836
7 changed files with 19 additions and 12 deletions
|
@ -126,13 +126,6 @@ sub simplify {
|
||||||
return @{ Slic3r::Geometry::Clipper::union_ex([ $self->simplify_as_polygons($tolerance) ]) };
|
return @{ Slic3r::Geometry::Clipper::union_ex([ $self->simplify_as_polygons($tolerance) ]) };
|
||||||
}
|
}
|
||||||
|
|
||||||
sub area {
|
|
||||||
my $self = shift;
|
|
||||||
my $area = $self->contour->area;
|
|
||||||
$area -= $_->area for $self->holes;
|
|
||||||
return $area;
|
|
||||||
}
|
|
||||||
|
|
||||||
# this method only works for expolygons having only a contour or
|
# this method only works for expolygons having only a contour or
|
||||||
# a contour and a hole, and not being thicker than the supplied
|
# a contour and a hole, and not being thicker than the supplied
|
||||||
# width. it returns a polyline or a polygon
|
# width. it returns a polyline or a polygon
|
||||||
|
|
|
@ -30,6 +30,16 @@ ExPolygon::rotate(double angle, Point* center)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
ExPolygon::area() const
|
||||||
|
{
|
||||||
|
double a = this->contour.area();
|
||||||
|
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
|
||||||
|
a -= -(*it).area(); // holes have negative area
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
SV*
|
SV*
|
||||||
ExPolygon::to_SV() {
|
ExPolygon::to_SV() {
|
||||||
const unsigned int num_holes = this->holes.size();
|
const unsigned int num_holes = this->holes.size();
|
||||||
|
|
|
@ -19,6 +19,7 @@ class ExPolygon
|
||||||
void scale(double factor);
|
void scale(double factor);
|
||||||
void translate(double x, double y);
|
void translate(double x, double y);
|
||||||
void rotate(double angle, Point* center);
|
void rotate(double angle, Point* center);
|
||||||
|
double area() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<ExPolygon> ExPolygons;
|
typedef std::vector<ExPolygon> ExPolygons;
|
||||||
|
|
|
@ -55,7 +55,7 @@ Polygon::split_at_first_point()
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
Polygon::area()
|
Polygon::area() const
|
||||||
{
|
{
|
||||||
ClipperLib::Polygon p;
|
ClipperLib::Polygon p;
|
||||||
Slic3rPolygon_to_ClipperPolygon(*this, p);
|
Slic3rPolygon_to_ClipperPolygon(*this, p);
|
||||||
|
@ -63,7 +63,7 @@ Polygon::area()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Polygon::is_counter_clockwise()
|
Polygon::is_counter_clockwise() const
|
||||||
{
|
{
|
||||||
ClipperLib::Polygon* p = new ClipperLib::Polygon();
|
ClipperLib::Polygon* p = new ClipperLib::Polygon();
|
||||||
Slic3rPolygon_to_ClipperPolygon(*this, *p);
|
Slic3rPolygon_to_ClipperPolygon(*this, *p);
|
||||||
|
|
|
@ -16,8 +16,8 @@ class Polygon : public MultiPoint {
|
||||||
Polyline* split_at(const Point* point);
|
Polyline* split_at(const Point* point);
|
||||||
Polyline* split_at_index(int index);
|
Polyline* split_at_index(int index);
|
||||||
Polyline* split_at_first_point();
|
Polyline* split_at_first_point();
|
||||||
double area();
|
double area() const;
|
||||||
bool is_counter_clockwise();
|
bool is_counter_clockwise() const;
|
||||||
bool make_counter_clockwise();
|
bool make_counter_clockwise();
|
||||||
bool make_clockwise();
|
bool make_clockwise();
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@ use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 17;
|
use Test::More tests => 18;
|
||||||
|
|
||||||
use constant PI => 4 * atan2(1, 1);
|
use constant PI => 4 * atan2(1, 1);
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ is_deeply $expolygon->clone->pp, [$square, $hole_in_square], 'clone';
|
||||||
# The following tests implicitely check that modifying clones
|
# The following tests implicitely check that modifying clones
|
||||||
# does not modify the original one.
|
# does not modify the original one.
|
||||||
|
|
||||||
|
is $expolygon->area, 100*100-20*20, 'area';
|
||||||
|
|
||||||
{
|
{
|
||||||
my $expolygon2 = $expolygon->clone;
|
my $expolygon2 = $expolygon->clone;
|
||||||
$expolygon2->scale(2.5);
|
$expolygon2->scale(2.5);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||||
void scale(double factor);
|
void scale(double factor);
|
||||||
void translate(double x, double y);
|
void translate(double x, double y);
|
||||||
|
double area();
|
||||||
%{
|
%{
|
||||||
|
|
||||||
ExPolygon*
|
ExPolygon*
|
||||||
|
|
Loading…
Reference in a new issue