From a81e8c4afc91b828094825eddf512a394f539648 Mon Sep 17 00:00:00 2001 From: Clarence Risher Date: Thu, 22 Dec 2011 06:09:01 -0500 Subject: [PATCH] correct length calculation for clockwise arcs --- lib/Slic3r/ExtrusionPath/Arc.pm | 6 +++++- t/arcs.t | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/ExtrusionPath/Arc.pm b/lib/Slic3r/ExtrusionPath/Arc.pm index 59c65c75c..05596f185 100644 --- a/lib/Slic3r/ExtrusionPath/Arc.pm +++ b/lib/Slic3r/ExtrusionPath/Arc.pm @@ -17,7 +17,11 @@ sub angle { sub length { my $self = shift; - return $self->radius * $self->angle; + if($self->orientation eq 'ccw') { + return $self->radius * $self->angle; + } else { + return $self->radius * (2*PI() - $self->angle); + } } 1; diff --git a/t/arcs.t b/t/arcs.t index 7fcc69bf4..981d35e3e 100644 --- a/t/arcs.t +++ b/t/arcs.t @@ -2,7 +2,7 @@ use Test::More; use strict; use warnings; -plan tests => 10; +plan tests => 12; BEGIN { use FindBin; @@ -50,7 +50,10 @@ use Slic3r; isa_ok $collection1->paths->[0], 'Slic3r::ExtrusionPath::Arc', 'path'; isa_ok $collection2->paths->[0], 'Slic3r::ExtrusionPath::Arc', 'path'; - + + is $collection1->paths->[0]->length, 7.06858347057701, 'cw oriented arc has correct length'; + is $collection2->paths->[0]->length, 7.06858347057705, 'ccw oriented arc has correct length'; + is $collection1->paths->[0]->orientation, 'cw', 'cw orientation was correctly detected'; is $collection2->paths->[0]->orientation, 'ccw', 'ccw orientation was correctly detected';