main.cpp
1 #include "Point.hpp" 2 #include <iostream> 3 4 // prototype for bsp 5 bool bsp(Point const a, Point const b, Point const c, Point const point); 6 7 int main() { 8 std::cout << "==========================================" << std::endl; 9 std::cout << " Point-in-Triangle (BSP) Demo" << std::endl; 10 std::cout << "==========================================" << std::endl; 11 std::cout << std::endl; 12 13 // Define the triangle 14 Point a(0.0f, 0.0f); 15 Point b(10.0f, 0.0f); 16 Point c(0.0f, 10.0f); 17 18 std::cout << "Triangle vertices:" << std::endl; 19 std::cout << " A: (" << a.getX().toFloat() << ", " << a.getY().toFloat() 20 << ")" << std::endl; 21 std::cout << " B: (" << b.getX().toFloat() << ", " << b.getY().toFloat() 22 << ")" << std::endl; 23 std::cout << " C: (" << c.getX().toFloat() << ", " << c.getY().toFloat() 24 << ")" << std::endl; 25 std::cout << std::endl; 26 27 // Test points 28 Point p1(1.0f, 1.0f); // inside 29 Point p2(5.0f, 0.0f); // on edge 30 Point p3(0.0f, 0.0f); // vertex 31 Point p4(10.0f, 10.0f); // outside 32 33 // Test p1 34 std::cout << "Testing point P1: (" << p1.getX().toFloat() << ", " 35 << p1.getY().toFloat() << ") - should be INSIDE the triangle." 36 << std::endl; 37 bool result1 = bsp(a, b, c, p1); 38 std::cout << " Result: " 39 << (result1 ? "YES, it's inside!" : "NO, it's not inside.") 40 << std::endl; 41 std::cout << std::endl; 42 43 // Test p2 44 std::cout << "Testing point P2: (" << p2.getX().toFloat() << ", " 45 << p2.getY().toFloat() << ") - on the EDGE of the triangle." 46 << std::endl; 47 bool result2 = bsp(a, b, c, p2); 48 std::cout << " Result: " 49 << (result2 ? "YES, it's inside!" 50 : "NO, it's not inside (on edge).") 51 << std::endl; 52 std::cout << std::endl; 53 54 // Test p3 55 std::cout << "Testing point P3: (" << p3.getX().toFloat() << ", " 56 << p3.getY().toFloat() << ") - at a VERTEX of the triangle." 57 << std::endl; 58 bool result3 = bsp(a, b, c, p3); 59 std::cout << " Result: " 60 << (result3 ? "YES, it's inside!" 61 : "NO, it's not inside (at vertex).") 62 << std::endl; 63 std::cout << std::endl; 64 65 // Test p4 66 std::cout << "Testing point P4: (" << p4.getX().toFloat() << ", " 67 << p4.getY().toFloat() << ") - OUTSIDE the triangle." << std::endl; 68 bool result4 = bsp(a, b, c, p4); 69 std::cout << " Result: " 70 << (result4 ? "YES, it's inside!" : "NO, it's not inside.") 71 << std::endl; 72 std::cout << std::endl; 73 74 std::cout << "==========================================" << std::endl; 75 std::cout << " Demo complete! BSP function tested." << std::endl; 76 std::cout << "==========================================" << std::endl; 77 78 return 0; 79 }