Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
Diffstat (limited to 'xs')
-rw-r--r--xs/src/libslic3r/Model.cpp21
-rw-r--r--xs/src/libslic3r/Model.hpp3
-rw-r--r--xs/src/libslic3r/Point.cpp8
-rw-r--r--xs/src/libslic3r/Point.hpp4
-rw-r--r--xs/t/19_model.t6
-rw-r--r--xs/xsp/Model.xsp4
6 files changed, 30 insertions, 16 deletions
diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp
index d5e9aa6ee..06919cedd 100644
--- a/xs/src/libslic3r/Model.cpp
+++ b/xs/src/libslic3r/Model.cpp
@@ -480,27 +480,32 @@ ModelObject::center_around_origin()
mesh.bounding_box(&bb);
}
- // first align to origin on XY
- double shift_x = -bb.min.x;
- double shift_y = -bb.min.y;
+ // first align to origin on XYZ
+ Vectorf3 vector(-bb.min.x, -bb.min.y, -bb.min.z);
// then center it on XY
Sizef3 size = bb.size();
- shift_x -= size.x/2;
- shift_y -= size.y/2;
+ vector.x -= size.x/2;
+ vector.y -= size.y/2;
- this->translate(shift_x, shift_y, 0);
- this->origin_translation.translate(shift_x, shift_y);
+ this->translate(vector);
+ this->origin_translation.translate(vector);
if (!this->instances.empty()) {
for (ModelInstancePtrs::const_iterator i = this->instances.begin(); i != this->instances.end(); ++i) {
- (*i)->offset.translate(-shift_x, -shift_y);
+ (*i)->offset.translate(-vector.x, -vector.y);
}
this->update_bounding_box();
}
}
void
+ModelObject::translate(const Vectorf3 &vector)
+{
+ this->translate(vector.x, vector.y, vector.z);
+}
+
+void
ModelObject::translate(coordf_t x, coordf_t y, coordf_t z)
{
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp
index 9cbe6be40..62bb38bfc 100644
--- a/xs/src/libslic3r/Model.hpp
+++ b/xs/src/libslic3r/Model.hpp
@@ -99,7 +99,7 @@ class ModelObject
center_around_origin() method. Callers might want to apply the same translation
to new volumes before adding them to this object in order to preset alignment
when user expects that. */
- Pointf origin_translation;
+ Pointf3 origin_translation;
// these should be private but we need to expose them via XS until all methods are ported
BoundingBoxf3 _bounding_box;
@@ -126,6 +126,7 @@ class ModelObject
void raw_bounding_box(BoundingBoxf3* bb) const;
void instance_bounding_box(size_t instance_idx, BoundingBoxf3* bb) const;
void center_around_origin();
+ void translate(const Vectorf3 &vector);
void translate(coordf_t x, coordf_t y, coordf_t z);
void scale(const Pointf3 &versor);
size_t materials_count() const;
diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp
index 76da85334..5f3f1da01 100644
--- a/xs/src/libslic3r/Point.cpp
+++ b/xs/src/libslic3r/Point.cpp
@@ -41,7 +41,7 @@ Point::translate(double x, double y)
}
void
-Point::translate(const Point &vector)
+Point::translate(const Vector &vector)
{
this->translate(vector.x, vector.y);
}
@@ -341,6 +341,12 @@ Pointf3::scale(double factor)
}
void
+Pointf3::translate(const Vectorf3 &vector)
+{
+ this->translate(vector.x, vector.y, vector.z);
+}
+
+void
Pointf3::translate(double x, double y, double z)
{
Pointf::translate(x, y);
diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp
index 60127b1b7..271c9584e 100644
--- a/xs/src/libslic3r/Point.hpp
+++ b/xs/src/libslic3r/Point.hpp
@@ -14,6 +14,7 @@ class Point;
class Pointf;
class Pointf3;
typedef Point Vector;
+typedef Pointf3 Vectorf3;
typedef std::vector<Point> Points;
typedef std::vector<Point*> PointPtrs;
typedef std::vector<const Point*> PointConstPtrs;
@@ -36,7 +37,7 @@ class Point
std::string wkt() const;
void scale(double factor);
void translate(double x, double y);
- void translate(const Point &vector);
+ void translate(const Vector &vector);
void rotate(double angle, const Point &center);
bool coincides_with(const Point &point) const;
bool coincides_with_epsilon(const Point &point) const;
@@ -93,6 +94,7 @@ class Pointf3 : public Pointf
coordf_t z;
explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0): Pointf(_x, _y), z(_z) {};
void scale(double factor);
+ void translate(const Vectorf3 &vector);
void translate(double x, double y, double z);
};
diff --git a/xs/t/19_model.t b/xs/t/19_model.t
index 56b3631af..d6f6d97a1 100644
--- a/xs/t/19_model.t
+++ b/xs/t/19_model.t
@@ -10,9 +10,9 @@ use Test::More tests => 4;
my $model = Slic3r::Model->new;
my $object = $model->_add_object;
isa_ok $object, 'Slic3r::Model::Object::Ref';
- isa_ok $object->origin_translation, 'Slic3r::Pointf::Ref';
- $object->origin_translation->translate(10,0);
- is_deeply \@{$object->origin_translation}, [10,0], 'origin_translation is modified by ref';
+ isa_ok $object->origin_translation, 'Slic3r::Pointf3::Ref';
+ $object->origin_translation->translate(10,0,0);
+ is_deeply \@{$object->origin_translation}, [10,0,0], 'origin_translation is modified by ref';
my $lhr = [ [ 5, 10, 0.1 ] ];
$object->set_layer_height_ranges($lhr);
diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp
index fd31a93d4..8d795f7d6 100644
--- a/xs/xsp/Model.xsp
+++ b/xs/xsp/Model.xsp
@@ -188,9 +188,9 @@ ModelMaterial::attributes()
void set_layer_height_ranges(t_layer_height_ranges ranges)
%code%{ THIS->layer_height_ranges = ranges; %};
- Ref<Pointf> origin_translation()
+ Ref<Pointf3> origin_translation()
%code%{ RETVAL = &THIS->origin_translation; %};
- void set_origin_translation(Pointf* point)
+ void set_origin_translation(Pointf3* point)
%code%{ THIS->origin_translation = *point; %};
bool needed_repair() const;