/* * 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. * */ // float template <> MCORE_INLINE bool Compare::CheckIfIsClose(const float& a, const float& b, float threshold) { return (Math::Abs(a - b) <= threshold); } // Vector2 template <> MCORE_INLINE bool Compare::CheckIfIsClose(const AZ::Vector2& a, const AZ::Vector2& b, float threshold) { return ((a - b).GetLength() <= threshold); } // Vector3 template <> MCORE_INLINE bool Compare::CheckIfIsClose(const AZ::Vector3& a, const AZ::Vector3& b, float threshold) { return ((a - b).GetLengthExact() <= threshold); } // Vector4 template <> MCORE_INLINE bool Compare::CheckIfIsClose(const AZ::Vector4& a, const AZ::Vector4& b, float threshold) { return ((a - b).GetLengthExact() <= threshold); } // Quaternion template <> MCORE_INLINE bool Compare::CheckIfIsClose(const AZ::Quaternion& a, const AZ::Quaternion& b, float threshold) { /* if (a.Dot(b) < 0.0f) return Compare::CheckIfIsClose( Vector4(a.x, a.y, a.z, a.w), Vector4(-b.x, -b.y, -b.z, -b.w), threshold); else return Compare::CheckIfIsClose( Vector4(a.x, a.y, a.z, a.w), Vector4(b.x, b.y, b.z, b.w), threshold); */ AZ::Vector3 axisA, axisB; float angleA, angleB; // convert to an axis and angle representation MCore::ToAxisAngle(a, axisA, angleA); MCore::ToAxisAngle(b, axisB, angleB); // compare the axis and angles if (Math::Abs(angleA - angleB) > threshold) { return false; } if (Math::Abs(axisA.GetX() - axisB.GetX()) > threshold) { return false; } if (Math::Abs(axisA.GetY() - axisB.GetY()) > threshold) { return false; } if (Math::Abs(axisA.GetZ() - axisB.GetZ()) > threshold) { return false; } // they are the same! return true; }