From c7f5753a2838bab8a84521795505e1e2c43194ca Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 30 Nov 2014 21:58:41 +0100 Subject: [PATCH] Ported PrintObject::bounding_box() to XS --- lib/Slic3r/Print/Object.pm | 10 ---------- xs/src/libslic3r/Print.hpp | 2 ++ xs/src/libslic3r/PrintObject.cpp | 10 ++++++++++ xs/xsp/Print.xsp | 5 +++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index ba03cc6a8..5a7091121 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -40,16 +40,6 @@ sub total_layer_count { return $self->layer_count + $self->support_layer_count; } -sub bounding_box { - my $self = shift; - - # since the object is aligned to origin, bounding box coincides with size - return Slic3r::Geometry::BoundingBox->new_from_points([ - Slic3r::Point->new(0,0), - map Slic3r::Point->new($_->x, $_->y), $self->size #)) - ]); -} - # this should be idempotent sub slice { my $self = shift; diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 574a9b6d2..868a3d775 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -5,6 +5,7 @@ #include #include #include +#include "BoundingBox.hpp" #include "Flow.hpp" #include "PrintConfig.hpp" #include "Point.hpp" @@ -108,6 +109,7 @@ class PrintObject bool delete_all_copies(); bool set_copies(const Points &points); bool reload_model_instances(); + void bounding_box(BoundingBox* bb) const; // adds region_id, too, if necessary void add_region_volume(int region_id, int volume_id); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 309012c7c..e8d4eb788 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -111,6 +111,16 @@ PrintObject::reload_model_instances() return this->set_copies(copies); } +void +PrintObject::bounding_box(BoundingBox* bb) const +{ + // since the object is aligned to origin, bounding box coincides with size + Points pp; + pp.push_back(Point(0,0)); + pp.push_back(this->size); + *bb = BoundingBox(pp); +} + void PrintObject::add_region_volume(int region_id, int volume_id) { diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 6369524e1..60135f4a1 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -61,6 +61,11 @@ _constant() %code%{ RETVAL = THIS->layer_height_ranges; %}; Ref size() %code%{ RETVAL = &THIS->size; %}; + BoundingBox* bounding_box() + %code{% + RETVAL = new BoundingBox(); + THIS->bounding_box(RETVAL); + %}; Ref _copies_shift() %code%{ RETVAL = &THIS->_copies_shift; %};