mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Refactoring: use Slic3r::Geometry::BoundingBox objects everywhere
This commit is contained in:
parent
07407e5dbd
commit
ac4a0bcdd8
20 changed files with 105 additions and 127 deletions
|
@ -175,9 +175,9 @@ sub size {
|
|||
return [ Slic3r::Geometry::size_3D($self->used_vertices) ];
|
||||
}
|
||||
|
||||
sub extents {
|
||||
sub bounding_box {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::bounding_box_3D($self->used_vertices);
|
||||
return Slic3r::Geometry::BoundingBox->new_from_points_3D($self->used_vertices);
|
||||
}
|
||||
|
||||
sub align_to_origin {
|
||||
|
@ -186,8 +186,8 @@ sub align_to_origin {
|
|||
# calculate the displacements needed to
|
||||
# have lowest value for each axis at coordinate 0
|
||||
{
|
||||
my @extents = $self->extents;
|
||||
$self->move(map -$extents[$_][MIN], X,Y,Z);
|
||||
my $bb = $self->bounding_box;
|
||||
$self->move(map -$bb->extents->[$_][MIN], X,Y,Z);
|
||||
}
|
||||
|
||||
# align all instances to 0,0 as well
|
||||
|
@ -254,12 +254,12 @@ sub split_meshes {
|
|||
|
||||
# let's now align the new object to the origin and put its displacement
|
||||
# (extents) in the instances info
|
||||
my @extents = $mesh->extents;
|
||||
my $bb = $mesh->bounding_box;
|
||||
$new_object->align_to_origin;
|
||||
|
||||
# add one instance per original instance applying the displacement
|
||||
$new_object->add_instance(
|
||||
offset => [ $_->offset->[X] + $extents[X][MIN], $_->offset->[Y] + $extents[Y][MIN] ],
|
||||
offset => [ $_->offset->[X] + $bb->x_min, $_->offset->[Y] + $bb->y_min ],
|
||||
rotation => $_->rotation,
|
||||
scaling_factor => $_->scaling_factor,
|
||||
) for @{ $object->instances // [] };
|
||||
|
@ -336,21 +336,14 @@ sub size {
|
|||
return [ Slic3r::Geometry::size_3D($self->used_vertices) ];
|
||||
}
|
||||
|
||||
sub extents {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::bounding_box_3D($self->used_vertices);
|
||||
}
|
||||
|
||||
sub center {
|
||||
my $self = shift;
|
||||
|
||||
my @extents = $self->extents;
|
||||
return [ map +($extents[$_][MAX] + $extents[$_][MIN])/2, X,Y,Z ];
|
||||
return $self->bounding_box->center;
|
||||
}
|
||||
|
||||
sub bounding_box {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::BoundingBox->new(extents => [ $self->extents ]);
|
||||
return Slic3r::Geometry::BoundingBox->new_from_points_3D($self->used_vertices);
|
||||
}
|
||||
|
||||
sub align_to_origin {
|
||||
|
@ -358,8 +351,8 @@ sub align_to_origin {
|
|||
|
||||
# calculate the displacements needed to
|
||||
# have lowest value for each axis at coordinate 0
|
||||
my @extents = $self->extents;
|
||||
my @shift = map -$extents[$_][MIN], X,Y,Z;
|
||||
my $bb = $self->bounding_box;
|
||||
my @shift = map -$bb->extents->[$_][MIN], X,Y,Z;
|
||||
$self->move(@shift);
|
||||
return @shift;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue