From ae35df716fa2fb9fba8b22a7cc0f702d8ef76bf2 Mon Sep 17 00:00:00 2001
From: Alessandro Ranellucci <aar@cpan.org>
Date: Mon, 20 Feb 2012 11:47:21 +0100
Subject: [PATCH] Little refactoring, new TriangleMesh->align_to_origin method

---
 lib/Slic3r/Print.pm        | 9 +--------
 lib/Slic3r/TriangleMesh.pm | 9 +++++++++
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm
index 7a739d28a..21d2c1532 100644
--- a/lib/Slic3r/Print.pm
+++ b/lib/Slic3r/Print.pm
@@ -28,14 +28,7 @@ sub new_from_mesh {
     
     $mesh->rotate($Slic3r::rotate);
     $mesh->scale($Slic3r::scale / $Slic3r::resolution);
-    
-    # calculate the displacements needed to 
-    # have lowest value for each axis at coordinate 0
-    {
-        my @extents = $mesh->bounding_box;
-        my @shift = map -$extents[$_][MIN], X,Y,Z;
-        $mesh->move(@shift);
-    }
+    $mesh->align_to_origin;
     
     # initialize print job
     my @size = $mesh->size;
diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm
index 7e245425f..b5449a12d 100644
--- a/lib/Slic3r/TriangleMesh.pm
+++ b/lib/Slic3r/TriangleMesh.pm
@@ -289,6 +289,15 @@ sub move {
     }
 }
 
+sub align_to_origin {
+    my $self = shift;
+    
+    # calculate the displacements needed to 
+    # have lowest value for each axis at coordinate 0
+    my @extents = $self->bounding_box;
+    $self->move(map -$extents[$_][MIN], X,Y,Z);
+}
+
 sub duplicate {
     my $self = shift;
     my (@shifts) = @_;