line2d.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (C) 2017 Dario Oliveri
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. #include <iostream>
  5. using namespace irr;
  6. using namespace irr::core;
  7. #define EXPECT( condition, value, name) if( condition != value) \
  8. { std::cout<< name << ": test failed"<< std::endl; return false;}
  9. //! Tests the basic functionality of the software device.
  10. bool line2DTest(void)
  11. {
  12. {
  13. line2d< f32> a(0, 0, 0, 1);
  14. line2d< f32> b(2, 0, 2, 1);
  15. line2d< f32> c(2, 0, 2, 1 + 0.00001f);
  16. EXPECT( a.nearlyParallel( b), true, "parallel Lines are parallel");
  17. EXPECT( a.nearlyParallel( c, (f32)32), true, "nearly parallel lines are parallel");
  18. }
  19. {
  20. line2d< f32> a( 0, 0, 0, 1);
  21. line2d< f32> b( 0, 2, 2, 1);
  22. EXPECT( a.nearlyParallel( b, 1), false, "orthogonal lines are NOT parallel");
  23. }
  24. {
  25. line2d< f32> a( 0, 0, 100, 100);
  26. line2d< f32> b( 100, 0, 0, 100);
  27. EXPECT( a.nearlyParallel( b, 1), false, "orthogonal lines are NOT parallel 2");
  28. vector2df t = a.fastLinesIntersection( b);
  29. vector2df u = vector2df( 50.0f, 50.0f);
  30. EXPECT( t.equals( u, roundingError<f32>() ), true, "fast intersection in known point");
  31. EXPECT( a .intersectAsSegments(b), true, "intersect as Segments");
  32. EXPECT( a.incidentSegments(b), true, "incidentSegments");
  33. vector2df out;
  34. EXPECT( a.lineIntersectSegment( b, out), true, "lineIntersectSegment");
  35. EXPECT( t.equals( out), true, "line intersect segment in known point");
  36. EXPECT( a.isPointBetweenStartAndEnd( out), true, "point isBetween StartEnd of first line");
  37. EXPECT( b.isPointBetweenStartAndEnd( out), true, "point isBetween StartEnd of second line");
  38. EXPECT( a.isPointOnLine( out), true, "is point on first line");
  39. EXPECT( b.isPointOnLine( out), true, "is point on second line");
  40. EXPECT( out.isBetweenPoints( a.start, a.end), true, "test point is on segment with first line");
  41. EXPECT( out.isBetweenPoints( b.start, b.end), true, "test point is on segment with first line");
  42. }
  43. {
  44. vector2df a( 0, 0);
  45. vector2df b( 10, 0);
  46. vector2df c( 0, 10);
  47. vector2df d( 0, 40);
  48. EXPECT( a.areClockwise( c, b), true, "test if points are clockwise");
  49. EXPECT( a.areClockwise( b, c), false, "test if points are NOT clockwise");
  50. EXPECT( a.areCounterClockwise( b, c), true, "test if points are counter clockwise");
  51. EXPECT( a.areCounterClockwise( c, b), false, "test if points are NOT counter clockwise");
  52. EXPECT( a.checkOrientation( c, b), 1, "test if orientation is clockwise");
  53. EXPECT( a.checkOrientation( b, c), 2, "test if orientation is anticlockwise");
  54. EXPECT( a.checkOrientation( c, d), 0, "test if orientation is colinear");
  55. EXPECT( a.checkOrientation( d, c), 0, "test if orientation is colinear 2");
  56. }
  57. return true;
  58. }