From d881c5ab2f9c8f43ab72a2a5310962a89a8f9af6 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 5 Aug 2013 19:52:37 +0200 Subject: [PATCH] Ported TriangleMesh->rotate --- xs/src/TriangleMesh.cpp | 7 +++++++ xs/src/TriangleMesh.hpp | 2 ++ xs/t/01_trianglemesh.t | 5 ++++- xs/xsp/TriangleMesh.xsp | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/xs/src/TriangleMesh.cpp b/xs/src/TriangleMesh.cpp index 2c84cedc9..ada776052 100644 --- a/xs/src/TriangleMesh.cpp +++ b/xs/src/TriangleMesh.cpp @@ -123,4 +123,11 @@ void TriangleMesh::align_to_origin() ); } +void TriangleMesh::rotate(double angle, Point* center) +{ + this->translate(-center->x, -center->y, 0); + stl_rotate_z(&(this->stl), (float)angle); + this->translate(+center->x, +center->y, 0); +} + } diff --git a/xs/src/TriangleMesh.hpp b/xs/src/TriangleMesh.hpp index c9e5a3f79..da3d10451 100644 --- a/xs/src/TriangleMesh.hpp +++ b/xs/src/TriangleMesh.hpp @@ -3,6 +3,7 @@ #include #include +#include "Point.hpp" namespace Slic3r { @@ -18,6 +19,7 @@ class TriangleMesh void scale(float factor); void translate(float x, float y, float z); void align_to_origin(); + void rotate(double angle, Point* center); stl_file stl; }; diff --git a/xs/t/01_trianglemesh.t b/xs/t/01_trianglemesh.t index 0db846267..2cdfe01ef 100644 --- a/xs/t/01_trianglemesh.t +++ b/xs/t/01_trianglemesh.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 9; +use Test::More tests => 10; is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!', 'hello world'; @@ -39,6 +39,9 @@ my $cube = { is_deeply $m->vertices->[2], [0,0,0], 'align_to_origin'; is_deeply $m->size, [40,40,40], 'size'; + + $m->rotate(45, Slic3r::Point->new(20,20)); + ok abs($m->size->[0] - sqrt(2)*40) < 1E-4, 'rotate'; } __END__ diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index 82f723873..2c88be3d9 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -15,6 +15,7 @@ void scale(float factor); void translate(float x, float y, float z); void align_to_origin(); + void rotate(double angle, Point* center); %{ SV*