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/t/thin.t
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2014-03-03 05:13:50 +0400
committerAlessandro Ranellucci <aar@cpan.org>2014-03-03 05:14:02 +0400
commitba5435cde1820e5660a39f84e95ed697af9791db (patch)
tree771f176d2d6502538609ee0eea6f88406d4ee251 /t/thin.t
parentb49a6527360a48b5f56d95e410b94a2b1400e2f2 (diff)
More medial axis tests
Diffstat (limited to 't/thin.t')
-rw-r--r--t/thin.t77
1 files changed, 62 insertions, 15 deletions
diff --git a/t/thin.t b/t/thin.t
index a19fcd144..bf048868f 100644
--- a/t/thin.t
+++ b/t/thin.t
@@ -1,4 +1,4 @@
-use Test::More tests => 3;
+use Test::More tests => 9;
use strict;
use warnings;
@@ -9,7 +9,7 @@ BEGIN {
use Slic3r;
use List::Util qw(first);
-use Slic3r::Geometry qw(epsilon scale);
+use Slic3r::Geometry qw(epsilon scale unscale);
use Slic3r::Test;
{
@@ -45,20 +45,19 @@ use Slic3r::Test;
'no superfluous thin walls are generated for toothed profile';
}
-my $square = Slic3r::Polygon->new_scale( # ccw
- [100, 100],
- [200, 100],
- [200, 200],
- [100, 200],
-);
-my $hole_in_square = Slic3r::Polygon->new_scale( # cw
- [140, 140],
- [140, 160],
- [160, 160],
- [160, 140],
-);
-
{
+ my $square = Slic3r::Polygon->new_scale( # ccw
+ [100, 100],
+ [200, 100],
+ [200, 200],
+ [100, 200],
+ );
+ my $hole_in_square = Slic3r::Polygon->new_scale( # cw
+ [140, 140],
+ [140, 160],
+ [160, 160],
+ [160, 140],
+ );
my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
my $res = $expolygon->medial_axis(scale 10);
is scalar(@$res), 1, 'medial axis of a square shape is a single closed loop';
@@ -66,4 +65,52 @@ my $hole_in_square = Slic3r::Polygon->new_scale( # cw
'medial axis loop has reasonable length';
}
+{
+ my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
+ [100, 100],
+ [120, 100],
+ [120, 200],
+ [100, 200],
+ ));
+ my $res = $expolygon->medial_axis(scale 10);
+ is scalar(@$res), 1, 'medial axis of a narrow rectangle is a single line';
+ ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has reasonable length';
+}
+
+{
+ my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
+ [100, 100],
+ [120, 100],
+ [112, 200],
+ [108, 200],
+ ));
+ my $res = $expolygon->medial_axis(scale 10);
+ is scalar(@$res), 1, 'medial axis of a narrow trapezoid is a single line';
+ ok unscale($res->[0]->length) >= (200-100 - (120-100)) - epsilon, 'medial axis has reasonable length';
+}
+
+{
+ my $expolygon = Slic3r::ExPolygon->new(Slic3r::Polygon->new_scale(
+ [100, 100],
+ [120, 100],
+ [120, 180],
+ [200, 180],
+ [200, 200],
+ [100, 200],
+ ));
+ my $res = $expolygon->medial_axis(scale 20);
+ is scalar(@$res), 1, 'medial axis of a L shape is a single polyline';
+ my $len = unscale($res->[0]->length) + 20; # 20 is the thickness of the expolygon, which is subtracted from the ends
+ ok $len > 80*2 && $len < 100*2, 'medial axis has reasonable length';
+
+ if (0) {
+ require "Slic3r/SVG.pm";
+ Slic3r::SVG::output(
+ "thin.svg",
+ expolygons => [$expolygon],
+ polylines => $res,
+ );
+ }
+}
+
__END__