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