You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Code/Framework/AzCore/Tests/IntersectPoint.cpp

157 lines
6.0 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/Math/IntersectPoint.h>
#include <AzCore/UnitTest/TestTypes.h>
using namespace AZ;
namespace UnitTest
{
// Tests a point inside sphere
TEST(INTERSECT_PointSphere, TestPointInside)
{
Vector3 sphereCenter(1.f, 2.f, 3.f);
float sphereRadius = 5.f;
Vector3 testPoint(2.f, 3.f, 4.f);
AZ_TEST_ASSERT(Intersect::PointSphere(sphereCenter, sphereRadius * sphereRadius, testPoint));
}
// Tests a point outside sphere
TEST(INTERSECT_PointSphere, TestPointOutside)
{
Vector3 sphereCenter(1.f, 2.f, 3.f);
float sphereRadius = 5.f;
Vector3 testPoint(10.f, 10.f, 10.f);
AZ_TEST_ASSERT(Intersect::PointSphere(sphereCenter, sphereRadius * sphereRadius, testPoint) == false);
}
// Tests a point just inside the border of the sphere
TEST(INTERSECT_PointSphere, TestPointInsideBorder)
{
Vector3 sphereCenter(1.f, 2.f, 3.f);
float sphereRadius = 5.f;
Vector3 testPoint(5.99f, 2.f, 3.f);
AZ_TEST_ASSERT(Intersect::PointSphere(sphereCenter, sphereRadius * sphereRadius, testPoint));
}
// Tests a point just outside the border of the sphere
TEST(INTERSECT_PointSphere, TestPointOutsideBorder)
{
Vector3 sphereCenter(1.f, 2.f, 3.f);
float sphereRadius = 5.f;
Vector3 testPoint(6.01f, 2.f, 3.f);
AZ_TEST_ASSERT(Intersect::PointSphere(sphereCenter, sphereRadius * sphereRadius, testPoint) == false);
}
// Tests a point inside cylinder
TEST(INTERSECT_PointCylinder, TestPointInside)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 5.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = cylinderAxis.GetLength();
Vector3 testPoint(1.f, 5.f, 3.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint));
}
// Tests a point outside cylinder
TEST(INTERSECT_PointCylinder, TestPointOutside)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 1.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = 2.f;
Vector3 testPoint(9.f, 9.f, 9.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint) == false);
}
// Tests a point just inside border at the top of the cylinder
TEST(INTERSECT_PointCylinder, TestPointInsideBorderTop)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 5.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = cylinderAxis.GetLength();
Vector3 testPoint(1.f, 6.99f, 3.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint));
}
// Tests a point just outside border at the top of the cylinder
TEST(INTERSECT_PointCylinder, TestPointOutsideBorderTop)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 5.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = cylinderAxis.GetLength();
Vector3 testPoint(1.f, 7.01f, 3.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint) == false);
}
// Tests a point just inside border at the bottom of the cylinder
TEST(INTERSECT_PointCylinder, TestPointInsideBorderBottom)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 5.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = cylinderAxis.GetLength();
Vector3 testPoint(1.f, 2.01f, 3.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint));
}
// Tests a point just outside border at the bottom of the cylinder
TEST(INTERSECT_PointCylinder, TestPointOutsideBorderBottom)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 5.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = cylinderAxis.GetLength();
Vector3 testPoint(1.f, 1.99f, 3.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint) == false);
}
// Tests a point just inside border at the side of the cylinder
TEST(INTERSECT_PointCylinder, TestPointInsideBorderSide)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 5.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = cylinderAxis.GetLength();
Vector3 testPoint(1.99f, 2.f, 3.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint));
}
// Tests a point just outside border at the side of the cylinder
TEST(INTERSECT_PointCylinder, TestPointOutsideBorderSide)
{
Vector3 cylinderBase(1.f, 2.f, 3.f);
Vector3 cylinderAxis(0.f, 5.f, 0.f);
float cylinderRadius = 1.f;
float cylinderLength = cylinderAxis.GetLength();
Vector3 testPoint(2.01f, 2.f, 3.f);
AZ_TEST_ASSERT(Intersect::PointCylinder(cylinderBase, cylinderAxis, cylinderLength * cylinderLength, cylinderRadius * cylinderRadius, testPoint) == false);
}
}