From 7bf308c08fec43d45649f0a20787372ba046e9a6 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 15 Jun 2013 15:50:02 +0200 Subject: Fix one more centering problem caused by wrong bounding box implementation --- lib/Slic3r/GUI/Plater.pm | 11 ++++++++--- lib/Slic3r/Geometry/BoundingBox.pm | 15 ++------------- lib/Slic3r/Polyline.pm | 7 ++++--- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 999a18680..b34efa82e 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1067,7 +1067,7 @@ sub OnDropFiles { package Slic3r::GUI::Plater::Object; use Moo; -use Math::ConvexHull::MonotoneChain qw(convex_hull); +use Math::ConvexHull::MonotoneChain qw(); use Slic3r::Geometry qw(X Y Z MIN MAX deg2rad); has 'name' => (is => 'rw', required => 1); @@ -1075,6 +1075,7 @@ has 'input_file' => (is => 'rw', required => 1); has 'input_file_object_id' => (is => 'rw'); # undef means keep model object has 'model_object' => (is => 'rw', required => 1, trigger => 1); has 'bounding_box' => (is => 'rw'); # 3D bb of original object (aligned to origin) with no rotation or scaling +has 'convex_hull' => (is => 'rw'); # 2D convex hull of original object (aligned to origin) with no rotation or scaling has 'scale' => (is => 'rw', default => sub { 1 }, trigger => \&_transform_thumbnail); has 'rotate' => (is => 'rw', default => sub { 0 }, trigger => \&_transform_thumbnail); # around object center point has 'instances' => (is => 'rw', default => sub { [] }); # upward Y axis @@ -1138,10 +1139,11 @@ sub make_thumbnail { my $self = shift; my $mesh = $self->model_object->mesh; # $self->model_object is already aligned to origin + $self->convex_hull(Slic3r::Polygon->new(Math::ConvexHull::MonotoneChain::convex_hull($mesh->vertices))); my $thumbnail = Slic3r::ExPolygon::Collection->new( expolygons => (@{$mesh->facets} <= 5000) ? $mesh->horizontal_projection - : [ Slic3r::ExPolygon->new(convex_hull($mesh->vertices)) ], + : [ Slic3r::ExPolygon->new($self->convex_hull) ], ); # only simplify expolygons larger than the threshold @@ -1168,7 +1170,10 @@ sub _transform_thumbnail { # bounding box with applied rotation and scaling sub transformed_bounding_box { my $self = shift; - return $self->_apply_transform($self->bounding_box); + + my $bb = Slic3r::Geometry::BoundingBox->new_from_points($self->_apply_transform($self->convex_hull)); + $bb->extents->[Z] = $self->bounding_box->clone->extents->[Z]; + return $bb; } sub _apply_transform { diff --git a/lib/Slic3r/Geometry/BoundingBox.pm b/lib/Slic3r/Geometry/BoundingBox.pm index 3cd019f0c..c2d27a1fe 100644 --- a/lib/Slic3r/Geometry/BoundingBox.pm +++ b/lib/Slic3r/Geometry/BoundingBox.pm @@ -39,20 +39,9 @@ sub polygon { return Slic3r::Polygon->new_from_bounding_box($self->bb); } +# note to $self sub rotate { - my $self = shift; - my ($angle, $center) = @_; - - # rotate the 2D bounding box polygon and leave Z unaltered - my $bb_p = $self->polygon; - $bb_p->rotate($angle, $center); - my @bb = $bb_p->bounding_box; - $self->extents->[X][MIN] = $bb[X1]; - $self->extents->[Y][MIN] = $bb[Y1]; - $self->extents->[X][MAX] = $bb[X2]; - $self->extents->[Y][MAX] = $bb[Y2]; - - $self; + die "Rotating an axis-aligned bounding box doesn't make any sense"; } sub scale { diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index 6646d1aae..2de79893a 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -156,11 +156,12 @@ sub translate { sub scale { my $self = shift; my ($factor) = @_; - return if $factor == 1; # transform point coordinates - foreach my $point (@$self) { - $point->[$_] *= $factor for X,Y; + if ($factor != 1) { + foreach my $point (@$self) { + $point->[$_] *= $factor for X,Y; + } } return $self; } -- cgit v1.2.3