#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/Point2.h" #include namespace { /// Writes a description of the point into a stream /// Stream into which the point's description will be written /// Point that will be described /// The stream into which the point has been described std::ostream &operator<<(std::ostream &stream, Nuclex::Geometry::Point2 const &point) { return stream << "Point2(" << point.X << ", " << point.Y << ")"; } } // anonymous namespace namespace Nuclex { namespace Geometry { // ------------------------------------------------------------------------------------------- // TEST(Point2Test, ParameterConstructorAssignsValues) { EXPECT_EQ(12.34f, Point2(12.34f, 56.78f).X); EXPECT_EQ(56.78f, Point2(12.34f, 56.78f).Y); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, SquaredDistanceToOtherPointCanBeCalculated) { Point2 from(10.0f, 20.0f); float distance = from.SquaredDistanceTo(Point2(100.0f, 200.0f)); EXPECT_EQ((90.0f * 90.0f) + (180.0f * 180.0f), distance); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, SquaredDistanceToSelfIsZero) { Point2 from(10.0f, 20.0f); EXPECT_EQ(0.0f, from.SquaredDistanceTo(from)); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, DistanceToOtherPointCanBeCalculated) { Point2 from(10.0f, 20.0f); float distance = from.DistanceTo(Point2(100.0f, 200.0f)); EXPECT_EQ(Math::SquareRoot((90.0f * 90.0f) + (180.0f * 180.0f)), distance); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, DistanceToSelfIsZero) { Point2 from(10.0f, 20.0f); EXPECT_EQ(0.0f, from.DistanceTo(from)); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, SquaredDistanceBetweenPointsCanBeCalculated) { Point2 from(10.0f, 20.0f); Point2 to(100.0f, 200.0f); float expected = (90.0f * 90.0f) + (180.0f * 180.0f); EXPECT_EQ(expected, Point2::SquaredDistanceBetween(from, to)); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, SquaredDistanceBetweenSamePointsIsZero) { Point2 from(10.0f, 20.0f); EXPECT_EQ(0.0f, Point2::SquaredDistanceBetween(from, from)); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, CanCalculateDistanceToOtherPoint) { Point2 from(10.0f, 20.0f); Point2 to(100.0f, 200.0f); float expected = Math::SquareRoot((90.0f * 90.0f) + (180.0f * 180.0f)); EXPECT_EQ(expected, Point2::DistanceBetween(from, to)); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, DistanceBetwenSamePointsIsZero) { Point2 from(10.0f, 20.0f); EXPECT_EQ(0.0f, Point2::DistanceBetween(from, from)); } // ------------------------------------------------------------------------------------------- // TEST(Point2Test, LinearInterpolationBetweenPointsIsPossible) { Point2 from(10.0f, 20.0f); Point2 to(110.0f, 220.0f); EXPECT_EQ(Point2(35.0f, 70.0f), Point2::Lerp(from, to, 0.25f)); EXPECT_EQ(Point2(60.0f, 120.0f), Point2::Lerp(from, to, 0.5f)); EXPECT_EQ(Point2(85.0f, 170.0f), Point2::Lerp(from, to, 0.75f)); } // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Geometry