| 33 | #include <geode/tests/common.hpp> |
| 34 | |
| 35 | void test_bbox() |
| 36 | { |
| 37 | geode::BoundingBox2D box; |
| 38 | box.add_point( geode::Point2D{ { -1, -1 } } ); |
| 39 | box.add_point( geode::Point2D{ { 1, 1 } } ); |
| 40 | |
| 41 | geode::BoundingBox2D box2; |
| 42 | box2.add_point( geode::Point2D{ { -2, -2 } } ); |
| 43 | box2.add_point( geode::Point2D{ { -1, -1 } } ); |
| 44 | |
| 45 | geode::OpenGeodeGeometryException::test( |
| 46 | box2.min() == geode::Point2D( { -2, -2 } ), |
| 47 | "Error in BoundingBox initialization" ); |
| 48 | geode::OpenGeodeGeometryException::test( |
| 49 | box2.max() == geode::Point2D( { -1, -1 } ), |
| 50 | "Error in BoundingBox initialization" ); |
| 51 | |
| 52 | box2.add_box( box ); |
| 53 | geode::OpenGeodeGeometryException::test( |
| 54 | box2.min() == geode::Point2D( { -2, -2 } ), |
| 55 | "Error in BoundingBox union computation" ); |
| 56 | geode::OpenGeodeGeometryException::test( |
| 57 | box2.max() == geode::Point2D( { 1, 1 } ), |
| 58 | "Error in BoundingBox union computation" ); |
| 59 | geode::OpenGeodeGeometryException::test( |
| 60 | box.intersects( box2 ), "BBox should overlap" ); |
| 61 | |
| 62 | geode::BoundingBox2D box3; |
| 63 | box3.add_point( geode::Point2D{ { 2, 2 } } ); |
| 64 | box3.add_point( geode::Point2D{ { 3, 3 } } ); |
| 65 | geode::OpenGeodeGeometryException::test( |
| 66 | !box.intersects( box3 ), "BBox should not overlap" ); |
| 67 | geode::OpenGeodeGeometryException::test( |
| 68 | box3.contains( geode::Point2D{ { 2.5, 2.5 } } ), |
| 69 | "BBox should contain this point" ); |
| 70 | geode::OpenGeodeGeometryException::test( |
| 71 | !box3.contains( geode::Point2D{ { 10, 0 } } ), |
| 72 | "BBox should not contain this point" ); |
| 73 | geode::OpenGeodeGeometryException::test( |
| 74 | !box3.contains( geode::Point2D{ { 0, 0 } } ), |
| 75 | "BBox should not contain that point" ); |
| 76 | |
| 77 | geode::BoundingBox2D box_negative; |
| 78 | box_negative.add_point( geode::Point2D{ { -2, -2 } } ); |
| 79 | box_negative.add_point( geode::Point2D{ { -1.5, -1.5 } } ); |
| 80 | geode::OpenGeodeGeometryException::test( |
| 81 | box_negative.min() == geode::Point2D( { -2, -2 } ), |
| 82 | "Error in BoundingBox initialization and point additions" ); |
| 83 | geode::OpenGeodeGeometryException::test( |
| 84 | box_negative.max() == geode::Point2D( { -1.5, -1.5 } ), |
| 85 | "Error in BoundingBox initialization and point additions" ); |
| 86 | geode::OpenGeodeGeometryException::test( !box.intersects( box_negative ), |
| 87 | "BBox should not overlap box_negative" ); |
| 88 | |
| 89 | const geode::BoundingBox2D copy_box = box2; |
| 90 | geode::OpenGeodeGeometryException::test( |
| 91 | copy_box.min() == geode::Point2D( { -2, -2 } ) |
| 92 | && copy_box.max() == geode::Point2D( { 1, 1 } ), |