diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /gfx/tests/gtest/TestBSPTree.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'gfx/tests/gtest/TestBSPTree.cpp')
-rw-r--r-- | gfx/tests/gtest/TestBSPTree.cpp | 959 |
1 files changed, 959 insertions, 0 deletions
diff --git a/gfx/tests/gtest/TestBSPTree.cpp b/gfx/tests/gtest/TestBSPTree.cpp new file mode 100644 index 000000000..1a84e37b6 --- /dev/null +++ b/gfx/tests/gtest/TestBSPTree.cpp @@ -0,0 +1,959 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "gtest/gtest.h" + +#include "BSPTree.h" +#include "Polygon.h" +#include "PolygonTestUtils.h" + +#include <deque> + +using namespace mozilla::gfx; +using namespace mozilla::layers; + +namespace { + +static void RunTest(std::deque<Polygon3D> aPolygons, + std::deque<Polygon3D> aExpected) +{ + std::deque<LayerPolygon> layers; + for (Polygon3D& polygon : aPolygons) { + layers.push_back(LayerPolygon(nullptr, Move(polygon))); + } + + const BSPTree tree(layers); + const nsTArray<LayerPolygon> order = tree.GetDrawOrder(); + + EXPECT_EQ(aExpected.size(), order.Length()); + + for (size_t i = 0; i < order.Length(); ++i) { + EXPECT_TRUE(aExpected[i] == *order[i].geometry); + } +} + +} // namespace + + +TEST(BSPTree, SameNode) +{ + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(0.0f, 0.0f, 0.0f), + Point3D(1.0f, 0.0f, 0.0f), + Point3D(1.0f, 1.0f, 0.0f), + Point3D(0.0f, 1.0f, 0.0f) + }, + Polygon3D { + Point3D(0.0f, 0.0f, 0.0f), + Point3D(1.0f, 0.0f, 0.0f), + Point3D(1.0f, 1.0f, 0.0f), + Point3D(0.0f, 1.0f, 0.0f) + } + }; + + ::RunTest(polygons, polygons); +} + +TEST(BSPTree, OneChild) +{ + const Polygon3D p1 { + Point3D(0.0f, 0.0f, 0.0f), + Point3D(1.0f, 0.0f, 0.0f), + Point3D(1.0f, 1.0f, 0.0f), + Point3D(0.0f, 1.0f, 0.0f) + }; + + const Polygon3D p2 { + Point3D(0.0f, 0.0f, 1.0f), + Point3D(1.0f, 0.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f), + Point3D(0.0f, 1.0f, 1.0f) + }; + + ::RunTest({p1, p2}, {p1, p2}); + ::RunTest({p2, p1}, {p1, p2}); +} + +TEST(BSPTree, SharedEdge1) +{ + Polygon3D p1 { + Point3D(1.0f, 0.0f, 1.0f), + Point3D(0.0f, 0.0f, 1.0f), + Point3D(0.0f, 1.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f) + }; + + Polygon3D p2 { + Point3D(1.0f, 0.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f), + Point3D(2.0f, 2.0f, 1.0f), + Point3D(2.0f, 0.0f, 1.0f) + }; + + ::RunTest({p1, p2}, {p1, p2}); +} + +TEST(BSPTree, SharedEdge2) +{ + Polygon3D p1 { + Point3D(1.0f, 0.0f, 1.0f), + Point3D(0.0f, 0.0f, 1.0f), + Point3D(0.0f, 1.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f) + }; + + Polygon3D p2 { + Point3D(1.0f, 0.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f), + Point3D(2.0f, 2.0f, 0.0f), + Point3D(2.0f, 0.0f, 0.0f) + }; + + ::RunTest({p1, p2}, {p2, p1}); +} + +TEST(BSPTree, SplitSharedEdge) +{ + Polygon3D p1 { + Point3D(1.0f, 0.0f, 1.0f), + Point3D(0.0f, 0.0f, 1.0f), + Point3D(0.0f, 1.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f) + }; + + Polygon3D p2 { + Point3D(1.0f, 0.0f, 2.0f), + Point3D(1.0f, 1.0f, 2.0f), + Point3D(1.0f, 1.0f, 0.0f), + Point3D(1.0f, 0.0f, 0.0f) + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(1.0f, 1.0f, 1.0f), + Point3D(1.0f, 1.0f, 0.0f), + Point3D(1.0f, 0.0f, 0.0f), + Point3D(1.0f, 0.0f, 1.0f) + }, + Polygon3D { + Point3D(1.0f, 0.0f, 1.0f), + Point3D(0.0f, 0.0f, 1.0f), + Point3D(0.0f, 1.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f) + }, + Polygon3D { + Point3D(1.0f, 0.0f, 2.0f), + Point3D(1.0f, 1.0f, 2.0f), + Point3D(1.0f, 1.0f, 1.0f), + Point3D(1.0f, 0.0f, 1.0f) + } + }; + + ::RunTest({p1, p2}, expected); +} + +TEST(BSPTree, SplitSimple1) +{ + Polygon3D p1 { + Point3D(0.0f, 0.0f, 1.0f), + Point3D(1.0f, 0.0f, 1.0f), + Point3D(1.0f, 1.0f, 1.0f), + Point3D(0.0f, 1.0f, 1.0f) + }; + + Polygon3D p2 { + Point3D(0.0f, 0.0f, 2.0f), + Point3D(1.0f, 0.0f, 2.0f), + Point3D(1.0f, 1.0f, 0.0f), + Point3D(0.0f, 1.0f, 0.0f) + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(0.0f, 1.0f, 0.0f), + Point3D(0.0f, 0.5f, 1.0f), + Point3D(1.0f, 0.5f, 1.0f), + Point3D(1.0f, 1.0f, 0.0f) + }, + p1, + Polygon3D { + Point3D(0.0f, 0.0f, 2.0f), + Point3D(1.0f, 0.0f, 2.0f), + Point3D(1.0f, 0.5f, 1.0f), + Point3D(0.0f, 0.5f, 1.0f) + } + }; + + ::RunTest({p1, p2}, expected); +} + +TEST(BSPTree, SplitSimple2) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-5.00000f, -5.00000f, 0.00000f), + Point3D(-5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, -5.00000f, 0.00000f) + }, + Polygon3D { + Point3D(0.00000f, -5.00000f, -5.00000f), + Point3D(0.00000f, 5.00000f, -5.00000f), + Point3D(0.00000f, 5.00000f, 5.00000f), + Point3D(0.00000f, -5.00000f, 5.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(0.00000f, -5.00000f, 0.00000f), + Point3D(0.00000f, -5.00000f, -5.00000f), + Point3D(0.00000f, 5.00000f, -5.00000f), + Point3D(0.00000f, 5.00000f, 0.00000f) + }, + Polygon3D { + Point3D(-5.00000f, -5.00000f, 0.00000f), + Point3D(-5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, -5.00000f, 0.00000f) + }, + Polygon3D { + Point3D(0.00000f, 5.00000f, 0.00000f), + Point3D(0.00000f, 5.00000f, 5.00000f), + Point3D(0.00000f, -5.00000f, 5.00000f), + Point3D(0.00000f, -5.00000f, 0.00000f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, NoSplit1) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(0.00000f, 10.00000f, 0.00000f), + Point3D(0.00000f, 0.00000f, 0.00000f), + Point3D(10.00000f, 0.00000f, 0.00000f), + Point3D(10.00000f, 10.00000f, 0.00000f) + }, + Polygon3D { + Point3D(0.00000f, 10.00000f, -5.00000f), + Point3D(0.00000f, 0.00000f, -5.00000f), + Point3D(10.00000f, 0.00000f, -5.00000f), + Point3D(10.00000f, 10.00000f, -5.00000f) + }, + Polygon3D { + Point3D(0.00000f, 10.00000f, 5.00000f), + Point3D(0.00000f, 0.00000f, 5.00000f), + Point3D(10.00000f, 0.00000f, 5.00000f), + Point3D(10.00000f, 10.00000f, 5.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(0.00000f, 10.00000f, -5.00000f), + Point3D(0.00000f, 0.00000f, -5.00000f), + Point3D(10.00000f, 0.00000f, -5.00000f), + Point3D(10.00000f, 10.00000f, -5.00000f) + }, + Polygon3D { + Point3D(0.00000f, 10.00000f, 0.00000f), + Point3D(0.00000f, 0.00000f, 0.00000f), + Point3D(10.00000f, 0.00000f, 0.00000f), + Point3D(10.00000f, 10.00000f, 0.00000f) + }, + Polygon3D { + Point3D(0.00000f, 10.00000f, 5.00000f), + Point3D(0.00000f, 0.00000f, 5.00000f), + Point3D(10.00000f, 0.00000f, 5.00000f), + Point3D(10.00000f, 10.00000f, 5.00000f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, NoSplit2) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-5.00000f, -5.00000f, 0.00000f), + Point3D(-5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, -5.00000f, 0.00000f) + }, + Polygon3D { + Point3D(0.00000f, 5.00000f, -15.00000f), + Point3D(0.00000f, -5.00000f, -15.00000f), + Point3D(0.00000f, -5.00000f, -10.00000f), + Point3D(0.00000f, 5.00000f, -10.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(0.00000f, 5.00000f, -15.00000f), + Point3D(0.00000f, -5.00000f, -15.00000f), + Point3D(0.00000f, -5.00000f, -10.00000f), + Point3D(0.00000f, 5.00000f, -10.00000f) + }, + Polygon3D { + Point3D(-5.00000f, -5.00000f, 0.00000f), + Point3D(-5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, 5.00000f, 0.00000f), + Point3D(5.00000f, -5.00000f, 0.00000f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate0degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 2.00000f, 2.00000f), + Point3D(-0.00000f, -2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, -2.00000f) + }, + Polygon3D { + Point3D(2.00000f, 0.00000f, 2.00000f), + Point3D(2.00000f, -0.00000f, -2.00000f), + Point3D(-2.00000f, 0.00000f, -2.00000f), + Point3D(-2.00000f, 0.00010f, 2.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, 0.00000f, 2.00000f), + Point3D(2.00000f, -0.00000f, -2.00000f), + Point3D(-2.00000f, 0.00000f, -2.00000f), + Point3D(-2.00000f, 0.00010f, 2.00000f) + }, + Polygon3D { + Point3D(-0.00000f, 2.00000f, 2.00000f), + Point3D(-0.00000f, -2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, -2.00000f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate20degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 1.19540f, 2.56350f), + Point3D(-0.00000f, -2.56340f, 1.19540f), + Point3D(0.00010f, -1.19530f, -2.56340f), + Point3D(0.00010f, 2.56350f, -1.19530f) + }, + Polygon3D { + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, -0.68400f, 1.87940f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, -0.68400f, 1.87940f) + }, + Polygon3D { + Point3D(-0.00000f, 1.19540f, 2.56350f), + Point3D(-0.00000f, -2.56340f, 1.19540f), + Point3D(0.00010f, -1.19530f, -2.56340f), + Point3D(0.00010f, 2.56350f, -1.19530f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate40degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -0.73200f, 2.73210f), + Point3D(-0.00000f, -2.73200f, -0.73200f), + Point3D(0.00010f, 0.73210f, -2.73200f), + Point3D(0.00010f, 2.73210f, 0.73210f) + }, + Polygon3D { + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, -1.73200f, 1.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, -1.73200f, 1.00000f) + }, + Polygon3D { + Point3D(-0.00000f, -0.73200f, 2.73210f), + Point3D(-0.00000f, -2.73200f, -0.73200f), + Point3D(0.00010f, 0.73210f, -2.73200f), + Point3D(0.00010f, 2.73210f, 0.73210f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate60degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -2.73200f, 0.73210f), + Point3D(-0.00000f, -0.73200f, -2.73200f), + Point3D(0.00010f, 2.73210f, -0.73200f), + Point3D(0.00010f, 0.73210f, 2.73210f) + }, + Polygon3D { + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, -1.73200f, -1.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-2.00000f, 1.26793f, 0.73210f), + Point3D(-2.00000f, -1.73200f, -1.00000f), + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(2.00000f, 1.26793f, 0.73210f) + }, + Polygon3D { + Point3D(-0.00000f, -2.73200f, 0.73210f), + Point3D(-0.00000f, -0.73200f, -2.73200f), + Point3D(0.00010f, 2.73210f, -0.73200f), + Point3D(0.00010f, 0.73210f, 2.73210f) + }, + Polygon3D { + Point3D(2.00000f, 1.26793f, 0.73210f), + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, 1.26793f, 0.73210f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate80degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -1.19530f, -2.56340f), + Point3D(-0.00000f, 2.56350f, -1.19530f), + Point3D(0.00010f, 1.19540f, 2.56350f), + Point3D(0.00010f, -2.56340f, 1.19540f) + }, + Polygon3D { + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, 0.68410f, -1.87930f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, -1.19530f, -2.56340f), + Point3D(-0.00000f, 2.56350f, -1.19530f), + Point3D(0.00010f, 1.19540f, 2.56350f), + Point3D(0.00010f, -2.56340f, 1.19540f) + }, + Polygon3D { + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, 0.68410f, -1.87930f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate100degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 2.73210f, -0.73200f), + Point3D(-0.00000f, 0.73210f, 2.73210f), + Point3D(0.00010f, -2.73200f, 0.73210f), + Point3D(0.00010f, -0.73200f, -2.73200f) + }, + Polygon3D { + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, 1.73210f, 1.00010f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -1.26783f, -0.73200f), + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, -1.26783f, -0.73200f) + }, + Polygon3D { + Point3D(-0.00000f, 2.73210f, -0.73200f), + Point3D(-0.00000f, 0.73210f, 2.73210f), + Point3D(0.00010f, -2.73200f, 0.73210f), + Point3D(0.00010f, -0.73200f, -2.73200f) + }, + Polygon3D { + Point3D(-2.00000f, -1.26783f, -0.73200f), + Point3D(-2.00000f, 1.73210f, 1.00010f), + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(2.00000f, -1.26783f, -0.73200f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate120degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -0.73200f, 2.73210f), + Point3D(-0.00000f, -2.73200f, -0.73200f), + Point3D(0.00010f, 0.73210f, -2.73200f), + Point3D(0.00010f, 2.73210f, 0.73210f) + }, + Polygon3D { + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, -1.73200f, 1.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, 1.73210f, -0.99990f), + Point3D(-2.00000f, -1.73200f, 1.00000f) + }, + Polygon3D { + Point3D(-0.00000f, -0.73200f, 2.73210f), + Point3D(-0.00000f, -2.73200f, -0.73200f), + Point3D(0.00010f, 0.73210f, -2.73200f), + Point3D(0.00010f, 2.73210f, 0.73210f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate140degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -1.19530f, -2.56340f), + Point3D(-0.00000f, 2.56350f, -1.19530f), + Point3D(0.00010f, 1.19540f, 2.56350f), + Point3D(0.00010f, -2.56340f, 1.19540f) + }, + Polygon3D { + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, 0.68410f, -1.87930f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, -1.19530f, -2.56340f), + Point3D(-0.00000f, 2.56350f, -1.19530f), + Point3D(0.00010f, 1.19540f, 2.56350f), + Point3D(0.00010f, -2.56340f, 1.19540f) + }, + Polygon3D { + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, 0.68410f, -1.87930f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate160degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 2.00000f, 2.00000f), + Point3D(-0.00000f, -2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, -2.00000f) + }, + Polygon3D { + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f) + }, + Polygon3D { + Point3D(-0.00000f, 2.00000f, 2.00000f), + Point3D(-0.00000f, -2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, -2.00000f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate180degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -2.00000f, -2.00000f), + Point3D(-0.00000f, 2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, 2.00000f) + }, + Polygon3D { + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, -2.00000f, -2.00000f), + Point3D(-0.00000f, 2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, 2.00000f) + }, + Polygon3D { + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate200degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 1.19540f, 2.56350f), + Point3D(-0.00000f, -2.56340f, 1.19540f), + Point3D(0.00010f, -1.19530f, -2.56340f), + Point3D(0.00010f, 2.56350f, -1.19530f) + }, + Polygon3D { + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, -0.68400f, 1.87940f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, -0.68400f, 1.87940f) + }, + Polygon3D { + Point3D(-0.00000f, 1.19540f, 2.56350f), + Point3D(-0.00000f, -2.56340f, 1.19540f), + Point3D(0.00010f, -1.19530f, -2.56340f), + Point3D(0.00010f, 2.56350f, -1.19530f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate220degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 0.73210f, -2.73200f), + Point3D(-0.00000f, 2.73210f, 0.73210f), + Point3D(0.00010f, -0.73200f, 2.73210f), + Point3D(0.00010f, -2.73200f, -0.73200f) + }, + Polygon3D { + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, 1.73210f, -0.99990f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, 0.73210f, -2.73200f), + Point3D(-0.00000f, 2.73210f, 0.73210f), + Point3D(0.00010f, -0.73200f, 2.73210f), + Point3D(0.00010f, -2.73200f, -0.73200f) + }, + Polygon3D { + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, 1.73210f, -0.99990f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate240degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -2.73200f, 0.73210f), + Point3D(-0.00000f, -0.73200f, -2.73200f), + Point3D(0.00010f, 2.73210f, -0.73200f), + Point3D(0.00010f, 0.73210f, 2.73210f) + }, + Polygon3D { + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, -1.73200f, -1.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-2.00000f, 1.26793f, 0.73210f), + Point3D(-2.00000f, -1.73200f, -1.00000f), + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(2.00000f, 1.26793f, 0.73210f) + }, + Polygon3D { + Point3D(-0.00000f, -2.73200f, 0.73210f), + Point3D(-0.00000f, -0.73200f, -2.73200f), + Point3D(0.00010f, 2.73210f, -0.73200f), + Point3D(0.00010f, 0.73210f, 2.73210f) + }, + Polygon3D { + Point3D(2.00000f, 1.26793f, 0.73210f), + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, 1.73210f, 1.00010f), + Point3D(-2.00000f, 1.26793f, 0.73210f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate260degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 1.19540f, 2.56350f), + Point3D(-0.00000f, -2.56340f, 1.19540f), + Point3D(0.00010f, -1.19530f, -2.56340f), + Point3D(0.00010f, 2.56350f, -1.19530f) + }, + Polygon3D { + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, -0.68400f, 1.87940f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, 0.68410f, -1.87930f), + Point3D(-2.00000f, -0.68400f, 1.87940f) + }, + Polygon3D { + Point3D(-0.00000f, 1.19540f, 2.56350f), + Point3D(-0.00000f, -2.56340f, 1.19540f), + Point3D(0.00010f, -1.19530f, -2.56340f), + Point3D(0.00010f, 2.56350f, -1.19530f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate280degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 2.73210f, -0.73200f), + Point3D(-0.00000f, 0.73210f, 2.73210f), + Point3D(0.00010f, -2.73200f, 0.73210f), + Point3D(0.00010f, -0.73200f, -2.73200f) + }, + Polygon3D { + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, 1.73210f, 1.00010f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(2.00000f, -1.26783f, -0.73200f), + Point3D(2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, -1.73200f, -1.00000f), + Point3D(-2.00000f, -1.26783f, -0.73200f) + }, + Polygon3D { + Point3D(-0.00000f, 2.73210f, -0.73200f), + Point3D(-0.00000f, 0.73210f, 2.73210f), + Point3D(0.00010f, -2.73200f, 0.73210f), + Point3D(0.00010f, -0.73200f, -2.73200f) + }, + Polygon3D { + Point3D(-2.00000f, -1.26783f, -0.73200f), + Point3D(-2.00000f, 1.73210f, 1.00010f), + Point3D(2.00000f, 1.73210f, 1.00010f), + Point3D(2.00000f, -1.26783f, -0.73200f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate300degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, 0.73210f, -2.73200f), + Point3D(-0.00000f, 2.73210f, 0.73210f), + Point3D(0.00010f, -0.73200f, 2.73210f), + Point3D(0.00010f, -2.73200f, -0.73200f) + }, + Polygon3D { + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, 1.73210f, -0.99990f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, 0.73210f, -2.73200f), + Point3D(-0.00000f, 2.73210f, 0.73210f), + Point3D(0.00010f, -0.73200f, 2.73210f), + Point3D(0.00010f, -2.73200f, -0.73200f) + }, + Polygon3D { + Point3D(2.00000f, 1.73210f, -0.99990f), + Point3D(2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, -1.73200f, 1.00000f), + Point3D(-2.00000f, 1.73210f, -0.99990f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate320degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -1.19530f, -2.56340f), + Point3D(-0.00000f, 2.56350f, -1.19530f), + Point3D(0.00010f, 1.19540f, 2.56350f), + Point3D(0.00010f, -2.56340f, 1.19540f) + }, + Polygon3D { + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, 0.68410f, -1.87930f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, -1.19530f, -2.56340f), + Point3D(-0.00000f, 2.56350f, -1.19530f), + Point3D(0.00010f, 1.19540f, 2.56350f), + Point3D(0.00010f, -2.56340f, 1.19540f) + }, + Polygon3D { + Point3D(2.00000f, 0.68410f, -1.87930f), + Point3D(2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, -0.68400f, 1.87940f), + Point3D(-2.00000f, 0.68410f, -1.87930f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate340degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -2.00000f, -2.00000f), + Point3D(-0.00000f, 2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, 2.00000f) + }, + Polygon3D { + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, -2.00000f, -2.00000f), + Point3D(-0.00000f, 2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, 2.00000f) + }, + Polygon3D { + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f) + } + }; + ::RunTest(polygons, expected); +} + +TEST(BSPTree, TwoPlaneIntersectRotate360degrees) { + const std::deque<Polygon3D> polygons { + Polygon3D { + Point3D(-0.00000f, -2.00000f, -2.00000f), + Point3D(-0.00000f, 2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, 2.00000f) + }, + Polygon3D { + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f) + } + }; + + const std::deque<Polygon3D> expected { + Polygon3D { + Point3D(-0.00000f, -2.00000f, -2.00000f), + Point3D(-0.00000f, 2.00000f, -2.00000f), + Point3D(0.00010f, 2.00000f, 2.00000f), + Point3D(0.00010f, -2.00000f, 2.00000f) + }, + Polygon3D { + Point3D(2.00000f, 0.00010f, -2.00000f), + Point3D(2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, -0.00000f, 2.00000f), + Point3D(-2.00000f, 0.00010f, -2.00000f) + } + }; + ::RunTest(polygons, expected); +} |