LineSegmentTests.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AZTestShared/Math/MathTestHelpers.h>
  9. #include <AzCore/Math/LineSegment.h>
  10. #include <AzCore/Math/Ray.h>
  11. #include <AzCore/Math/Vector3.h>
  12. #include <AzCore/UnitTest/TestTypes.h>
  13. namespace UnitTest
  14. {
  15. TEST(MATH_LineSegment, LineSegment_CreateFromStartAndEnd)
  16. {
  17. AZ::LineSegment segment(AZ::Vector3(0.0f, 15.5f, 12.0f), AZ::Vector3(12.0f, 0.0f, 4.0f));
  18. EXPECT_THAT(segment.GetStart(), IsClose(AZ::Vector3(0.0f, 15.5f, 12.0f)));
  19. EXPECT_THAT(segment.GetEnd(), IsClose(AZ::Vector3(12.0f, 0.0f, 4.0f)));
  20. }
  21. TEST(MATH_LineSegment, LineSegment_CreateFromRayAndLength)
  22. {
  23. AZ::Ray ray(AZ::Vector3(0.0f, 0.5f, 12.0f), AZ::Vector3(15.0f, 0.0f, 3.0f).GetNormalized());
  24. AZ::LineSegment segment = AZ::LineSegment::CreateFromRayAndLength(ray, 25.0f);
  25. EXPECT_THAT(segment.GetStart(), IsClose(AZ::Vector3(0.0f, 0.5f, 12.0f)));
  26. EXPECT_THAT(segment.GetEnd(), IsClose(AZ::Vector3(0.0f, 0.5f, 12.0f) + (AZ::Vector3(15.0f, 0.0f, 3.0f).GetNormalized() * 25.0f)));
  27. }
  28. TEST(MATH_LineSegment, LineSegment_GetDifference)
  29. {
  30. AZ::LineSegment segment(AZ::Vector3(13.0f, 15.5f, 12.0f), AZ::Vector3(12.0f, 51.0f, 4.0f));
  31. EXPECT_THAT(segment.GetDifference(), IsClose(AZ::Vector3(-1.0f, 35.5f, -8.0f)));
  32. }
  33. TEST(MATH_LineSegment, LineSegment_GetPoint)
  34. {
  35. AZ::LineSegment segment(AZ::Vector3(4.0f, 5.0f, 6.0f), AZ::Vector3(5.0f, 10.0f, 2.0f));
  36. EXPECT_THAT(segment.GetPoint(0.5f), IsClose(AZ::Vector3(4.5f, 7.5f, 4.0f)));
  37. }
  38. }