#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2015 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_GEOMETRY_SOURCE 1 #include "Nuclex/Geometry/Areas/Generators/Triangle2Generator.h" #include namespace Nuclex { namespace Geometry { namespace Areas { namespace Generators { // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, RandomPointsInsideCanBeGenerated) { } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, ClosestPointInTriangleCanBeFound) { Triangle2 triangle( Point2(5.0f, 5.0f), Point2(5.0f, -5.0f), Point2(15.0f, -5.0f) ); // 1 5,5 // |\ // | \ // | \ // | \ // 2----3 5,-5 15,-5 EXPECT_EQ( // Left edge Point2(5.0f, 0.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(0.0f, 0.0f)) ); EXPECT_EQ( // Top left Point2(5.0f, 5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(0.0f, 10.0f)) ); EXPECT_EQ( // Right edge Point2(10.0f, 0.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(15.0f, 5.0f)) ); EXPECT_EQ( // Bottom right Point2(15.0f, -5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(20.0f, -10.0f)) ); EXPECT_EQ( // Bottom edge Point2(10.0f, -5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(10.0f, -10.0f)) ); EXPECT_EQ( // Bottom left Point2(5.0f, -5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(0.0f, -10.0f)) ); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, ClosestPointInTriangleIsInputPointWhenContained) { Triangle2 triangle( Point2(0.0f, 5.0f), Point2(-5.0f,-5.0f), Point2(5.0f, -5.0f) ); EXPECT_EQ( Point2(-1.0f, 1.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(-1.0f, 1.0f)) ); EXPECT_EQ( Point2(1.0f, -1.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(1.0f, -1.0f)) ); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, ClosestPointInFlatTriangleIsValid) { Triangle2 triangle( Point2(-5.0f, 5.0f), Point2(0.0f, 0.0f), Point2(5.0f, -5.0f) ); // 1 -5,5 // \ // 2 0,0 // \ // 3 5,-5 EXPECT_EQ( Point2(-5.0f, 5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(-10.0f, 10.0f)) ); EXPECT_EQ( Point2(-5.0f, 5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(-4.0f, 6.0f)) ); EXPECT_EQ( Point2(0.0f, 0.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(5.0f, 5.0f)) ); EXPECT_EQ( Point2(5.0f, -5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(6.0f, -4.0f)) ); EXPECT_EQ( Point2(5.0f, -5.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(10.0f, -10.0f)) ); EXPECT_EQ( Point2(0.0f, 0.0f), Triangle2Generator::GetClosestPointInside(triangle, Point2(-5.0f, -5.0f)) ); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, ClosestPointOnTriangleHullCanBeFound) { Triangle2 triangle( Point2(5.0f, 5.0f), Point2(5.0f, -5.0f), Point2(15.0f, -5.0f) ); // 1 5,5 // |\ // | \ // | \ // | \ // 2----3 5,-5 15,-5 EXPECT_EQ( // Left edge Point2(5.0f, 0.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(0.0f, 0.0f)) ); EXPECT_EQ( // Top left Point2(5.0f, 5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(0.0f, 10.0f)) ); EXPECT_EQ( // Right edge Point2(10.0f, 0.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(15.0f, 5.0f)) ); EXPECT_EQ( // Bottom right Point2(15.0f, -5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(20.0f, -10.0f)) ); EXPECT_EQ( // Bottom edge Point2(10.0f, -5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(10.0f, -10.0f)) ); EXPECT_EQ( // Bottom left Point2(5.0f, -5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(0.0f, -10.0f)) ); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, ClosestPointOnTriangleHullCanBeFoundWhenContained) { Triangle2 triangle( Point2(0.0f, 5.0f), Point2(-10.0f,-5.0f), Point2(10.0f, -5.0f) ); EXPECT_EQ( Point2(-5.0f, 0.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(-4.0f, -1.0f)) ); EXPECT_EQ( Point2(5.0f, 0.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(4.0f, -1.0f)) ); EXPECT_EQ( Point2(1.0f, -5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(1.0f, -4.0f)) ); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, ClosestPointOnFlatTriangleHullIsValid) { Triangle2 triangle( Point2(-5.0f, 5.0f), Point2(0.0f, 0.0f), Point2(5.0f, -5.0f) ); // 1 -5,5 // \ // 2 0,0 // \ // 3 5,-5 EXPECT_EQ( Point2(-5.0f, 5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(-10.0f, 10.0f)) ); EXPECT_EQ( Point2(-5.0f, 5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(-4.0f, 6.0f)) ); EXPECT_EQ( Point2(0.0f, 0.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(5.0f, 5.0f)) ); EXPECT_EQ( Point2(5.0f, -5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(6.0f, -4.0f)) ); EXPECT_EQ( Point2(5.0f, -5.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(10.0f, -10.0f)) ); EXPECT_EQ( Point2(0.0f, 0.0f), Triangle2Generator::GetClosestPointOnOutline(triangle, Point2(-5.0f, -5.0f)) ); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, BoundingRectangleCanBeObtained) { Triangle2 triangle( Point2(1.0f, 2.0f), Point2(3.0f, 4.0f), Point2(5.0f, 6.0f) ); Rectangle2 boundingRectangle = Triangle2Generator::GetBoundingRectangle( triangle ); EXPECT_FLOAT_EQ(1.0f, boundingRectangle.Min.X); EXPECT_FLOAT_EQ(5.0f, boundingRectangle.Max.X); EXPECT_FLOAT_EQ(2.0f, boundingRectangle.Min.Y); EXPECT_FLOAT_EQ(6.0f, boundingRectangle.Max.Y); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, BoundingDiscCanBeObtained) { Triangle2 triangle( Point2(-10.0f, -10.0f), Point2(10.0f, -10.0f), Point2(0.0f, 10.0f) ); Disc2 boundingDisc = Triangle2Generator::GetBoundingDisc(triangle); EXPECT_FLOAT_EQ(0.0f, boundingDisc.Center.X); EXPECT_FLOAT_EQ(-2.5f, boundingDisc.Center.Y); EXPECT_FLOAT_EQ(12.5f, boundingDisc.Radius); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, BoundingDiscOfFlatTrianglesIsValid) { Triangle2 triangle( Point2(-10.0f, -10.0f), Point2(9.0f, 9.0f), Point2(10.0f, 10.0f) ); Disc2 boundingDisc = Triangle2Generator::GetBoundingDisc(triangle); EXPECT_FLOAT_EQ(0.0f, boundingDisc.Center.X); EXPECT_FLOAT_EQ(0.0f, boundingDisc.Center.Y); EXPECT_FLOAT_EQ(14.142135623730950488016887242097f, boundingDisc.Radius); } // ------------------------------------------------------------------------------------------- // TEST(Triangle2GeneratorTest, BoundingDiscOfWideTrianglesIsMinimal) { Triangle2 triangle( Point2(-10.0f, 0.0f), Point2(0.0f, 5.0f), Point2(10.0f, 0.0f) ); Disc2 boundingDisc = Triangle2Generator::GetBoundingDisc(triangle); EXPECT_FLOAT_EQ(0.0f, boundingDisc.Center.X); EXPECT_FLOAT_EQ(0.0f, boundingDisc.Center.Y); EXPECT_FLOAT_EQ(10.0f, boundingDisc.Radius); } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Geometry::Areas::Generators