WhiteBoxEdgeTest.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "WhiteBoxTestFixtures.h"
  9. #include "WhiteBoxTestUtil.h"
  10. #include <AzCore/UnitTest/TestTypes.h>
  11. #include <AzCore/std/containers/array.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzTest/AzTest.h>
  14. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  15. #include <WhiteBox/WhiteBoxToolApi.h>
  16. namespace UnitTest
  17. {
  18. class WhiteBoxEdgeTests : public WhiteBoxTestFixture
  19. {
  20. };
  21. TEST_F(WhiteBoxEdgeTests, TestPolygonEdgeHandles)
  22. {
  23. namespace Api = WhiteBox::Api;
  24. Api::InitializeAsUnitQuad(*m_whiteBox);
  25. auto polygonHandle = Api::MeshPolygonHandles(*m_whiteBox)[0];
  26. auto edgeHandles = Api::PolygonBorderEdgeHandlesFlattened(*m_whiteBox, polygonHandle);
  27. EXPECT_EQ(edgeHandles.size(), 4);
  28. }
  29. TEST_F(WhiteBoxEdgeTests, TestMeshPolygonEdgeHandlesAsCube)
  30. {
  31. namespace Api = WhiteBox::Api;
  32. Api::InitializeAsUnitCube(*m_whiteBox);
  33. auto edgeHandles = Api::MeshPolygonEdgeHandles(*m_whiteBox);
  34. EXPECT_EQ(edgeHandles.size(), 12);
  35. }
  36. TEST_F(WhiteBoxEdgeTests, TestMeshPolygonEdgeHandlesAsQuad)
  37. {
  38. namespace Api = WhiteBox::Api;
  39. Api::InitializeAsUnitQuad(*m_whiteBox);
  40. auto edgeHandles = Api::MeshPolygonEdgeHandles(*m_whiteBox);
  41. EXPECT_EQ(edgeHandles.size(), 4);
  42. }
  43. TEST_F(WhiteBoxEdgeTests, TestMeshEdgeHandlesCube)
  44. {
  45. namespace Api = WhiteBox::Api;
  46. Api::InitializeAsUnitCube(*m_whiteBox);
  47. auto edgeHandles = Api::MeshEdgeHandles(*m_whiteBox);
  48. EXPECT_EQ(edgeHandles.size(), 18);
  49. }
  50. TEST_F(WhiteBoxEdgeTests, TestMeshEdgeHandlesQuad)
  51. {
  52. namespace Api = WhiteBox::Api;
  53. Api::InitializeAsUnitQuad(*m_whiteBox);
  54. auto edgeHandles = Api::MeshEdgeHandles(*m_whiteBox);
  55. EXPECT_EQ(edgeHandles.size(), 5);
  56. }
  57. TEST_F(WhiteBoxEdgeTests, TestFaceEdgeHandles)
  58. {
  59. namespace Api = WhiteBox::Api;
  60. Api::InitializeAsUnitQuad(*m_whiteBox);
  61. auto face = Api::MeshPolygonHandles(*m_whiteBox)[0].m_faceHandles[0];
  62. auto edgeHandles = Api::FaceEdgeHandles(*m_whiteBox, face);
  63. EXPECT_EQ(edgeHandles.size(), 3);
  64. }
  65. TEST_F(WhiteBoxEdgeTests, PolygonEdgeHandles)
  66. {
  67. namespace Api = WhiteBox::Api;
  68. Api::InitializeAsUnitQuad(*m_whiteBox);
  69. auto polygon = Api::MeshPolygonHandles(*m_whiteBox)[0];
  70. auto edgeHandles = Api::PolygonBorderEdgeHandlesFlattened(*m_whiteBox, polygon);
  71. EXPECT_EQ(edgeHandles.size(), 4);
  72. }
  73. TEST_F(WhiteBoxEdgeTests, EdgeFaceHandles)
  74. {
  75. namespace Api = WhiteBox::Api;
  76. Api::InitializeAsUnitCube(*m_whiteBox);
  77. auto edgeHandle = Api::MeshEdgeHandles(*m_whiteBox)[0];
  78. auto faceHandles = Api::EdgeFaceHandles(*m_whiteBox, edgeHandle);
  79. EXPECT_TRUE(faceHandles[0].IsValid());
  80. EXPECT_TRUE(faceHandles[1].IsValid());
  81. }
  82. TEST_F(WhiteBoxEdgeTests, EdgeFacehandlesAtBorder)
  83. {
  84. namespace Api = WhiteBox::Api;
  85. Api::InitializeAsUnitQuad(*m_whiteBox);
  86. auto edgeHandle = Api::MeshEdgeHandles(*m_whiteBox)[0];
  87. auto faceHandles = Api::EdgeFaceHandles(*m_whiteBox, edgeHandle);
  88. ASSERT_EQ(1, faceHandles.size());
  89. EXPECT_TRUE(faceHandles[0].IsValid());
  90. }
  91. TEST_F(WhiteBoxEdgeTests, EdgeVertexhandles)
  92. {
  93. namespace Api = WhiteBox::Api;
  94. Api::InitializeAsUnitQuad(*m_whiteBox);
  95. auto edgeHandle = Api::MeshEdgeHandles(*m_whiteBox)[0];
  96. auto vertexHandles = Api::EdgeVertexHandles(*m_whiteBox, edgeHandle);
  97. EXPECT_TRUE(vertexHandles[0].IsValid());
  98. EXPECT_TRUE(vertexHandles[1].IsValid());
  99. }
  100. TEST_F(WhiteBoxEdgeTests, EdgeTranslate)
  101. {
  102. namespace Api = WhiteBox::Api;
  103. Api::InitializeAsUnitQuad(*m_whiteBox);
  104. AZStd::vector<AZ::Vector3> expectedVertexPositions = {
  105. AZ::Vector3(-0.5f, 0.0f, -1.0f), AZ::Vector3(0.5f, 0.0f, -1.0f), AZ::Vector3(0.5f, 0.0f, 0.5f),
  106. AZ::Vector3(-0.5f, 0.0f, 0.5f)};
  107. auto edgeHandle = Api::MeshEdgeHandles(*m_whiteBox)[0];
  108. Api::TranslateEdge(*m_whiteBox, edgeHandle, AZ::Vector3(0.0, 0.0, -0.5f));
  109. auto vertexPositions = Api::MeshVertexPositions(*m_whiteBox);
  110. EXPECT_THAT(vertexPositions, ::testing::Pointwise(ContainerIsClose(), expectedVertexPositions));
  111. }
  112. } // namespace UnitTest