mPolyhedronTest.cpp
Engine/source/math/test/mPolyhedronTest.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2014 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifdef TORQUE_TESTS_ENABLED 25#include "testing/unitTesting.h" 26#include "math/mPolyhedron.h" 27 28FIXTURE(Polyhedron) 29{ 30protected: 31 Vector<PlaneF> planes; 32 33 virtual void SetUp() 34 { 35 // Build planes for a unit cube centered at the origin. 36 // Note that the normals must be facing inwards. 37 planes.push_back(PlaneF(Point3F(-0.5f, 0.f, 0.f ), Point3F( 1.f, 0.f, 0.f))); 38 planes.push_back(PlaneF(Point3F( 0.5f, 0.f, 0.f ), Point3F(-1.f, 0.f, 0.f))); 39 planes.push_back(PlaneF(Point3F( 0.f, -0.5f, 0.f ), Point3F( 0.f, 1.f, 0.f))); 40 planes.push_back(PlaneF(Point3F( 0.f, 0.5f, 0.f ), Point3F( 0.f, -1.f, 0.f))); 41 planes.push_back(PlaneF(Point3F( 0.f, 0.f, -0.5f), Point3F( 0.f, 0.f, 1.f))); 42 planes.push_back(PlaneF(Point3F( 0.f, 0.f, 0.5f), Point3F( 0.f, 0.f, -1.f))); 43 } 44}; 45 46TEST_FIX(Polyhedron, BuildFromPlanes) 47{ 48 // Turn planes into a polyhedron. 49 Polyhedron p1; 50 p1.buildFromPlanes(PlaneSetF(planes.address(), planes.size())); 51 52 // Check if we got a cube back. 53 EXPECT_EQ(p1.getNumPoints(), 8); 54 EXPECT_EQ(p1.getNumPlanes(), 6); 55 EXPECT_EQ(p1.getNumEdges(), 12); 56 57 // Add extra plane that doesn't contribute a new edge. 58 Vector<PlaneF> planes2 = planes; 59 planes2.push_back( PlaneF( Point3F( 0.5f, 0.5f, 0.5f ), Point3F( -1.f, -1.f, -1.f ) ) ); 60 61 // Turn them into another polyhedron. 62 Polyhedron p2; 63 p2.buildFromPlanes(PlaneSetF(planes2.address(), planes2.size())); 64 65 // Check if we got a cube back. 66 EXPECT_EQ(p2.getNumPoints(), 8); 67 EXPECT_EQ(p2.getNumPlanes(), 6); 68 EXPECT_EQ(p2.getNumEdges(), 12); 69} 70 71#endif 72