Ported Polygon->area
This commit is contained in:
parent
1f734807b9
commit
792fcba7be
5 changed files with 12 additions and 7 deletions
|
@ -8,7 +8,6 @@ use parent 'Slic3r::Polyline';
|
|||
use Slic3r::Geometry qw(polygon_remove_parallel_continuous_edges
|
||||
polygon_remove_acute_vertices polygon_segment_having_point
|
||||
PI X1 X2 Y1 Y2 epsilon);
|
||||
use Slic3r::Geometry::Clipper qw(JT_MITER);
|
||||
|
||||
sub wkt {
|
||||
my $self = shift;
|
||||
|
@ -34,11 +33,6 @@ sub encloses_point {
|
|||
return Boost::Geometry::Utils::point_covered_by_polygon($point->pp, [$self->pp]);
|
||||
}
|
||||
|
||||
sub area {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::Clipper::area($self->pp);
|
||||
}
|
||||
|
||||
sub grow {
|
||||
my $self = shift;
|
||||
return $self->split_at_first_point->grow(@_);
|
||||
|
|
|
@ -54,6 +54,14 @@ Polygon::split_at_first_point()
|
|||
return this->split_at_index(0);
|
||||
}
|
||||
|
||||
double
|
||||
Polygon::area()
|
||||
{
|
||||
ClipperLib::Polygon p;
|
||||
Slic3rPolygon_to_ClipperPolygon(*this, p);
|
||||
return ClipperLib::Area(p);
|
||||
}
|
||||
|
||||
bool
|
||||
Polygon::is_counter_clockwise()
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@ class Polygon : public MultiPoint {
|
|||
Polyline* split_at(const Point* point);
|
||||
Polyline* split_at_index(int index);
|
||||
Polyline* split_at_first_point();
|
||||
double area();
|
||||
bool is_counter_clockwise();
|
||||
bool make_counter_clockwise();
|
||||
bool make_clockwise();
|
||||
|
|
|
@ -4,7 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 11;
|
||||
use Test::More tests => 12;
|
||||
|
||||
my $square = [ # ccw
|
||||
[100, 100],
|
||||
|
@ -30,6 +30,7 @@ is_deeply [ map $_->pp, @$lines ], [
|
|||
is_deeply $polygon->split_at_first_point->pp, [ @$square[0,1,2,3,0] ], 'split_at_first_point';
|
||||
is_deeply $polygon->split_at_index(2)->pp, [ @$square[2,3,0,1,2] ], 'split_at_index';
|
||||
is_deeply $polygon->split_at(Slic3r::Point->new(@{$square->[2]}))->pp, [ @$square[2,3,0,1,2] ], 'split_at';
|
||||
is $polygon->area, 100*100, 'area';
|
||||
|
||||
ok $polygon->is_counter_clockwise, 'is_counter_clockwise';
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_index(index); %};
|
||||
Polyline* split_at_first_point()
|
||||
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_first_point(); %};
|
||||
double area();
|
||||
bool is_counter_clockwise();
|
||||
bool make_counter_clockwise();
|
||||
bool make_clockwise();
|
||||
|
|
Loading…
Reference in a new issue