arcs.t 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan skip_all => 'arcs are currently disabled';
  5. plan tests => 13;
  6. BEGIN {
  7. use FindBin;
  8. use lib "$FindBin::Bin/../lib";
  9. }
  10. use Slic3r;
  11. use Slic3r::ExtrusionPath ':roles';
  12. use Slic3r::Geometry qw(scaled_epsilon scale X Y);
  13. {
  14. my $path = Slic3r::ExtrusionPath->new(polyline => Slic3r::Polyline->new(
  15. [135322.42,26654.96], [187029.11,99546.23], [222515.14,92381.93], [258001.16,99546.23],
  16. [286979.42,119083.91], [306517.1,148062.17], [313681.4,183548.2],
  17. [306517.1,219034.23], [286979.42,248012.49], [258001.16,267550.17], [222515.14,274714.47],
  18. [187029.11,267550.17], [158050.85,248012.49], [138513.17,219034.23], [131348.87,183548.2],
  19. [86948.77,175149.09], [119825.35,100585],
  20. ), role => EXTR_ROLE_FILL, flow_spacing => 0.5);
  21. my @paths = $path->detect_arcs(30);
  22. is scalar(@paths), 3, 'path collection now contains three paths';
  23. isa_ok $paths[1], 'Slic3r::ExtrusionPath::Arc', 'second one';
  24. }
  25. #==========================================================
  26. {
  27. my @points = map [ scale $_->[0], scale $_->[1] ], (
  28. [10,20], [10.7845909572784,19.9691733373313], [11.5643446504023,19.8768834059514],
  29. [12.3344536385591,19.7236992039768], [13.0901699437495,19.5105651629515],
  30. [13.8268343236509,19.2387953251129], [14.5399049973955,18.9100652418837],
  31. [15.2249856471595,18.5264016435409], [15.8778525229247,18.0901699437495],
  32. [16.4944804833018,17.6040596560003]
  33. );
  34. my $path1 = Slic3r::ExtrusionPath->new(
  35. polyline => Slic3r::Polyline->new(@points),
  36. role => EXTR_ROLE_FILL,
  37. flow_spacing => 0.5,
  38. );
  39. my $path2 = Slic3r::ExtrusionPath->new(
  40. polyline => Slic3r::Polyline->new(reverse @points),
  41. role => EXTR_ROLE_FILL,
  42. flow_spacing => 0.5,
  43. );
  44. my @paths1 = $path1->detect_arcs(10, scale 1);
  45. my @paths2 = $path2->detect_arcs(10, scale 1);
  46. is scalar(@paths1), 1, 'path collection now contains one path';
  47. is scalar(@paths2), 1, 'path collection now contains one path';
  48. isa_ok $paths1[0], 'Slic3r::ExtrusionPath::Arc', 'path';
  49. isa_ok $paths2[0], 'Slic3r::ExtrusionPath::Arc', 'path';
  50. my $expected_length = scale 7.06858347057701;
  51. ok abs($paths1[0]->length - $expected_length) < scaled_epsilon, 'cw oriented arc has correct length';
  52. ok abs($paths2[0]->length - $expected_length) < scaled_epsilon, 'ccw oriented arc has correct length';
  53. is $paths1[0]->orientation, 'cw', 'cw orientation was correctly detected';
  54. is $paths2[0]->orientation, 'ccw', 'ccw orientation was correctly detected';
  55. is $paths1[0]->flow_spacing, $path1->flow_spacing, 'flow spacing was correctly preserved';
  56. my $center1 = [ map sprintf('%.0f', $_), @{ $paths1[0]->center } ];
  57. ok abs($center1->[X] - scale 10) < scaled_epsilon && abs($center1->[Y] - scale 10) < scaled_epsilon, 'center was correctly detected';
  58. my $center2 = [ map sprintf('%.0f', $_), @{ $paths2[0]->center } ];
  59. ok abs($center2->[X] - scale 10) < scaled_epsilon && abs($center1->[Y] - scale 10) < scaled_epsilon, 'center was correctly detected';
  60. }
  61. #==========================================================