From b5672de3ca94e8b4c58f21d2b417a4cf2f45e3ad Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 22 Sep 2012 16:10:24 +0200 Subject: [PATCH] Refactoring, new bounding_box_3D function --- lib/Slic3r/Geometry.pm | 16 +++++++++++++++- lib/Slic3r/TriangleMesh.pm | 9 +-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 7b66d40e9..86e7bf96e 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -20,7 +20,7 @@ our @EXPORT_OK = qw( shortest_path collinear scale unscale merge_collinear_lines rad2deg_dir bounding_box_center line_intersects_any douglas_peucker polyline_remove_short_segments normal triangle_normal polygon_is_convex - scaled_epsilon + scaled_epsilon bounding_box_3D ); @@ -707,6 +707,20 @@ sub bounding_box_intersect { return 1; } +# 3D +sub bounding_box_3D { + my ($points) = @_; + + my @extents = (map [undef, undef], X,Y,Z); + foreach my $point (@$points) { + for (X,Y,Z) { + $extents[$_][MIN] = $point->[$_] if !defined $extents[$_][MIN] || $point->[$_] < $extents[$_][MIN]; + $extents[$_][MAX] = $point->[$_] if !defined $extents[$_][MAX] || $point->[$_] > $extents[$_][MAX]; + } + } + return @extents; +} + sub angle3points { my ($p1, $p2, $p3) = @_; # p1 is the center diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm index 7f9d929b1..90ff45614 100644 --- a/lib/Slic3r/TriangleMesh.pm +++ b/lib/Slic3r/TriangleMesh.pm @@ -381,14 +381,7 @@ sub duplicate { sub extents { my $self = shift; - my @extents = (map [undef, undef], X,Y,Z); - foreach my $vertex (@{$self->vertices}) { - for (X,Y,Z) { - $extents[$_][MIN] = $vertex->[$_] if !defined $extents[$_][MIN] || $vertex->[$_] < $extents[$_][MIN]; - $extents[$_][MAX] = $vertex->[$_] if !defined $extents[$_][MAX] || $vertex->[$_] > $extents[$_][MAX]; - } - } - return @extents; + return Slic3r::Geometry::bounding_box_3D($self->vertices); } sub size {