#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/Lines/Segment3.h" #include namespace Nuclex { namespace Geometry { namespace Lines { // ------------------------------------------------------------------------------------------- // TEST(Segment3Test, ParameterConstructorAssignsValues) { Segment3 segment(Point3(1.1f, 2.2f, 3.3f), Point3(4.4f, 5.5f, 6.6f)); EXPECT_EQ(1.1f, segment.Start.X); EXPECT_EQ(2.2f, segment.Start.Y); EXPECT_EQ(3.3f, segment.Start.Z); EXPECT_EQ(4.4f, segment.End.X); EXPECT_EQ(5.5f, segment.End.Y); EXPECT_EQ(6.6f, segment.End.Z); } // ------------------------------------------------------------------------------------------- // TEST(Segment3Test, SquaredLengthCanBeCalculated) { Segment3 segment(Point3(1.0f, 2.0f, 4.0f), Point3(8.0f, 16.0f, 32.0f)); EXPECT_EQ(7.0f * 7.0f + 14.0f * 14.0f + 28.0f * 28.0f, segment.GetSquaredLength()); } // ------------------------------------------------------------------------------------------- // TEST(Segment3Test, SquaredLengthOfDegenerateSegmentIsZero) { Segment3 segment(Point3(1.0f, 2.0f, 3.0f), Point3(1.0f, 2.0f, 3.0f)); EXPECT_EQ(0.0f, segment.GetSquaredLength()); } // ------------------------------------------------------------------------------------------- // TEST(Segment3Test, LengthCanBeCalculated) { Segment3 segment(Point3(1.0f, 2.0f, 4.0f), Point3(8.0f, 16.0f, 32.0f)); EXPECT_EQ(sqrtf(7.0f * 7.0f + 14.0f * 14.0f + 28.0f * 28.0f), segment.GetLength()); } // ------------------------------------------------------------------------------------------- // TEST(Segment3Test, LengthOfDegenerateSegmentIsZero) { Segment3 segment(Point3(1.0f, 2.0f, 3.0f), Point3(1.0f, 2.0f, 3.0f)); EXPECT_EQ(0.0f, segment.GetLength()); } // ------------------------------------------------------------------------------------------- // TEST(Segment3Test, LineSegmentCanBeShiftedByCoordinates) { Segment3 segment(Point3(1.1f, 2.2f, 3.3f), Point3(4.4f, 5.5f, 6.6f)); segment.ShiftBy(10.0f, 100.0f, 1000.0f); EXPECT_EQ(11.1f, segment.Start.X); EXPECT_EQ(102.2f, segment.Start.Y); EXPECT_EQ(1003.3f, segment.Start.Z); EXPECT_EQ(14.4f, segment.End.X); EXPECT_EQ(105.5f, segment.End.Y); EXPECT_EQ(1006.6f, segment.End.Z); } // ------------------------------------------------------------------------------------------- // TEST(Segment3Test, LineSegmentCanBeShiftedByVectors) { Segment3 segment(Point3(1.1f, 2.2f, 3.3f), Point3(4.4f, 5.5f, 6.6f)); segment.ShiftBy(Vector3(1000.0f, 100.0f, 10.0f)); EXPECT_EQ(1001.1f, segment.Start.X); EXPECT_EQ(102.2f, segment.Start.Y); EXPECT_EQ(13.3f, segment.Start.Z); EXPECT_EQ(1004.4f, segment.End.X); EXPECT_EQ(105.5f, segment.End.Y); EXPECT_EQ(16.6f, segment.End.Z); } // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Geometry::Lines