collinear.t 2.1 KB

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