collinear.t 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan tests => 11;
  5. BEGIN {
  6. use FindBin;
  7. use lib "$FindBin::Bin/../lib";
  8. }
  9. use Slic3r;
  10. use Slic3r::Geometry qw(collinear);
  11. #==========================================================
  12. {
  13. my @lines = (
  14. Slic3r::Line->new([0,4], [4,2]),
  15. Slic3r::Line->new([2,3], [8,0]),
  16. Slic3r::Line->new([6,1], [8,0]),
  17. );
  18. is collinear($lines[0], $lines[1]), 1, 'collinear';
  19. is collinear($lines[1], $lines[2]), 1, 'collinear';
  20. is collinear($lines[0], $lines[2]), 1, 'collinear';
  21. }
  22. #==========================================================
  23. {
  24. # horizontal
  25. my @lines = (
  26. Slic3r::Line->new([0,1], [5,1]),
  27. Slic3r::Line->new([2,1], [8,1]),
  28. );
  29. is collinear($lines[0], $lines[1]), 1, 'collinear';
  30. }
  31. #==========================================================
  32. {
  33. # vertical
  34. my @lines = (
  35. Slic3r::Line->new([1,0], [1,5]),
  36. Slic3r::Line->new([1,2], [1,8]),
  37. );
  38. is collinear($lines[0], $lines[1]), 1, 'collinear';
  39. }
  40. #==========================================================
  41. {
  42. # non overlapping
  43. my @lines = (
  44. Slic3r::Line->new([0,1], [5,1]),
  45. Slic3r::Line->new([7,1], [10,1]),
  46. );
  47. is collinear($lines[0], $lines[1], 1), 0, 'non overlapping';
  48. is collinear($lines[0], $lines[1], 0), 1, 'overlapping';
  49. }
  50. #==========================================================
  51. {
  52. # with one common point
  53. my @lines = (
  54. Slic3r::Line->new([0,4], [4,2]),
  55. Slic3r::Line->new([4,2], [8,0]),
  56. );
  57. is collinear($lines[0], $lines[1], 1), 1, 'one common point';
  58. is collinear($lines[0], $lines[1], 0), 1, 'one common point';
  59. }
  60. #==========================================================
  61. {
  62. # not collinear
  63. my @lines = (
  64. Slic3r::Line->new([290000000,690525600], [285163380,684761540]),
  65. Slic3r::Line->new([285163380,684761540], [193267599,575244400]),
  66. );
  67. is collinear($lines[0], $lines[1], 0), 0, 'not collinear';
  68. is collinear($lines[0], $lines[1], 1), 0, 'not collinear';
  69. }
  70. #==========================================================