From 4e6bd3d25c0eb4c79bf805518cc431cc1ab32b2c Mon Sep 17 00:00:00 2001 From: puvvadar Date: Fri, 11 Feb 2022 17:58:28 -0800 Subject: [PATCH 1/5] Consolidate various to_string implementations for math classes Signed-off-by: puvvadar --- .../AzCore/Math/MathStringConversions.cpp | 97 +++++++++++++++++++ .../AzCore/Math/MathStringConversions.h | 66 +++++++++++++ .../Framework/AzCore/AzCore/Math/ToString.cpp | 96 ------------------ Code/Framework/AzCore/AzCore/Math/ToString.h | 35 ------- .../AzCore/AzCore/azcore_files.cmake | 4 +- .../AzCore/AzCore/std/string/conversions.h | 8 ++ Code/Framework/AzCore/Tests/AZStd/String.cpp | 2 + .../AZTestShared/Math/MathTestHelpers.cpp | 1 - .../AzCore/Tests/Math/MathStringsTests.cpp | 64 ++++++++++++ .../AzCore/Tests/azcoretests_files.cmake | 1 + .../Components/NonUniformScaleComponent.cpp | 4 +- .../ActionDispatcher.h | 4 +- .../EditorNonUniformScaleComponent.cpp | 4 +- ...EditorTransformComponentSelectionTests.cpp | 1 - .../Code/MCore/Source/StringConversions.cpp | 61 ------------ .../Code/MCore/Source/StringConversions.h | 31 +----- .../MultiplayerDebugPerEntityReporter.cpp | 1 - Gems/PhysX/Code/Editor/ColliderSphereMode.cpp | 1 - Gems/PhysX/Code/Source/RigidBody.cpp | 6 +- Gems/PhysX/Code/Source/Utils.cpp | 6 +- .../Code/Source/Core/WhiteBoxToolApi.cpp | 18 ++-- 21 files changed, 260 insertions(+), 251 deletions(-) create mode 100644 Code/Framework/AzCore/AzCore/Math/MathStringConversions.cpp create mode 100644 Code/Framework/AzCore/AzCore/Math/MathStringConversions.h delete mode 100644 Code/Framework/AzCore/AzCore/Math/ToString.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Math/ToString.h create mode 100644 Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp diff --git a/Code/Framework/AzCore/AzCore/Math/MathStringConversions.cpp b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.cpp new file mode 100644 index 0000000000..9997db09b5 --- /dev/null +++ b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace AZStd +{ + void to_string(string& str, const AZ::Vector2& value) + { + str = AZStd::string::format("%.8f,%.8f", + static_cast(value.GetX()), + static_cast(value.GetY())); + } + + void to_string(string& str, const AZ::Vector3& value) + { + str = AZStd::string::format("%.8f,%.8f,%.8f", + static_cast(value.GetX()), + static_cast(value.GetY()), + static_cast(value.GetZ())); + } + + void to_string(string& str, const AZ::Vector4& value) + { + str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f", + static_cast(value.GetX()), + static_cast(value.GetY()), + static_cast(value.GetZ()), + static_cast(value.GetW())); + } + + void to_string(string& str, const AZ::Quaternion& value) + { + str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f", + static_cast(value.GetX()), + static_cast(value.GetY()), + static_cast(value.GetZ()), + static_cast(value.GetW())); + } + + void to_string(string& str, const AZ::Matrix3x3& value) + { + str = AZStd::string::format( + "%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f", + static_cast(value(0, 0)), static_cast(value(1, 0)), static_cast(value(2, 0)), + static_cast(value(0, 1)), static_cast(value(1, 1)), static_cast(value(2, 1)), + static_cast(value(0, 2)), static_cast(value(1, 2)), static_cast(value(2, 2))); + } + + void to_string(string& str, const AZ::Matrix4x4& value) + { + str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f", + static_cast(value(0, 0)), static_cast(value(1, 0)), static_cast(value(2, 0)), static_cast(value(3, 0)), + static_cast(value(0, 1)), static_cast(value(1, 1)), static_cast(value(2, 1)), static_cast(value(3, 1)), + static_cast(value(0, 2)), static_cast(value(1, 2)), static_cast(value(2, 2)), static_cast(value(3, 2)), + static_cast(value(0, 3)), static_cast(value(1, 3)), static_cast(value(2, 3)), static_cast(value(3, 3))); + } + + void to_string(string& str, const AZ::Transform& value) + { + AZ::Matrix3x4 matrix3x4 = AZ::Matrix3x4::CreateFromTransform(value); + + str = AZStd::string::format("%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f", + static_cast(matrix3x4(0, 0)), static_cast(matrix3x4(1, 0)), static_cast(matrix3x4(2, 0)), + static_cast(matrix3x4(0, 1)), static_cast(matrix3x4(1, 1)), static_cast(matrix3x4(2, 1)), + static_cast(matrix3x4(0, 2)), static_cast(matrix3x4(1, 2)), static_cast(matrix3x4(2, 2)), + static_cast(matrix3x4(0, 3)), static_cast(matrix3x4(1, 3)), static_cast(matrix3x4(2, 3))); + } + + void to_string(string& str, const AZ::Aabb& value) + { + str = AZStd::string::format( + "%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f", + static_cast(value.GetMin().GetX()), static_cast(value.GetMin().GetY()), + static_cast(value.GetMin().GetZ()), static_cast(value.GetMax().GetX()), + static_cast(value.GetMax().GetY()), static_cast(value.GetMax().GetZ())); + } + + void to_string(string& str, const AZ::Color& color) + { + str = AZStd::string::format("R:%d, G:%d, B:%d A:%d", color.GetR8(), color.GetG8(), color.GetB8(), color.GetA8()); + } +} diff --git a/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h new file mode 100644 index 0000000000..48c37c51ee --- /dev/null +++ b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#pragma once + +#include +#include +#include + +namespace AZ +{ + class Aabb; + class Color; + class Matrix3x3; + class Matrix4x4; + class Quaternion; + class Transform; + class Vector2; + class Vector3; + class Vector4; +} + +namespace AZStd +{ + //! Prints a Vector2 with precision to 8 decimal points + void to_string(string& str, const AZ::Vector2& value); + + //! Prints a Vector3 with precision to 8 decimal points + void to_string(string& str, const AZ::Vector3& value); + + //! Prints a Vector4 with precision to 8 decimal points + void to_string(string& str, const AZ::Vector4& value); + + //! Prints a Quaternion with precision to 8 decimal points + void to_string(string& str, const AZ::Quaternion& value); + + //! Prints a 3x3 matrix in row major order over three lines with precision to 8 decimal points + void to_string(string& str, const AZ::Matrix3x3& value); + + //! Prints a 4x4 matrix in row major order over four lines with precision to 8 decimal points + void to_string(string& str, const AZ::Matrix4x4& value); + + //! Prints a transform as a 3x4 matrix in row major order over four lines with precision to 8 decimal points + void to_string(string& str, const AZ::Transform& value); + + //! Prints an AABB as a pair of Vector3s with precision to 8 decimal points + void to_string(string& str, const AZ::Aabb& value); + + //! Prints a Color as four unsigned ints representing RGBA + void to_string(string& str, const AZ::Color& value); + + inline AZStd::string to_string(const AZ::Vector2& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Vector3& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Vector4& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Quaternion& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Matrix3x3& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Matrix4x4& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Transform& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Aabb& val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(const AZ::Color& val) { AZStd::string str; to_string(str, val); return str; } +} diff --git a/Code/Framework/AzCore/AzCore/Math/ToString.cpp b/Code/Framework/AzCore/AzCore/Math/ToString.cpp deleted file mode 100644 index 2a1c94e660..0000000000 --- a/Code/Framework/AzCore/AzCore/Math/ToString.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include "ToString.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace AZ -{ - AZStd::string ToString(const AZ::Vector2& vector2) - { - return AZStd::string::format("(X:%f, Y:%f)", static_cast(vector2.GetX()), static_cast(vector2.GetY())); - } - - AZStd::string ToString(const AZ::Vector3& vector3) - { - return AZStd::string::format("(X:%f, Y:%f, Z:%f)", static_cast(vector3.GetX()), static_cast(vector3.GetY()), static_cast(vector3.GetZ())); - } - - AZStd::string ToString(const AZ::Vector4& vector4) - { - return AZStd::string::format("(X:%f, Y:%f, Z:%f W:%f)", static_cast(vector4.GetX()), static_cast(vector4.GetY()), static_cast(vector4.GetZ()), static_cast(vector4.GetW())); - } - - AZStd::string ToString(const AZ::Quaternion& quaternion) - { - return AZStd::string::format("(X:%f, Y:%f, Z:%f W:%f)", static_cast(quaternion.GetX()), static_cast(quaternion.GetY()), static_cast(quaternion.GetZ()), static_cast(quaternion.GetW())); - } - - AZStd::string ToString(const AZ::Transform& transform) - { - AZ::Vector3 cols[4]; - transform.GetBasisAndTranslation(&cols[0], &cols[1], &cols[2], &cols[3]); - - return AZStd::string::format( - "[%f, %f, %f, %f]\n" - "[%f, %f, %f, %f]\n" - "[%f, %f, %f, %f]", - cols[0].GetX(), cols[1].GetX(), cols[2].GetX(), cols[3].GetX(), - cols[0].GetY(), cols[1].GetY(), cols[2].GetY(), cols[3].GetY(), - cols[0].GetZ(), cols[1].GetZ(), cols[2].GetZ(), cols[3].GetZ() - ); - } - - AZStd::string ToString(const AZ::Matrix3x3& matrix33) - { - auto row1 = matrix33.GetRow(0); - auto row2 = matrix33.GetRow(1); - auto row3 = matrix33.GetRow(2); - - return AZStd::string::format( - "[%f, %f, %f]\n" - "[%f, %f, %f]\n" - "[%f, %f, %f]", - static_cast(row1.GetX()), static_cast(row1.GetY()), static_cast(row1.GetZ()), - static_cast(row2.GetX()), static_cast(row2.GetY()), static_cast(row2.GetZ()), - static_cast(row3.GetX()), static_cast(row3.GetY()), static_cast(row3.GetZ()) - ); - } - - AZStd::string ToString(const AZ::Matrix4x4& matrix44) - { - auto row1 = matrix44.GetRow(0); - auto row2 = matrix44.GetRow(1); - auto row3 = matrix44.GetRow(2); - auto row4 = matrix44.GetRow(3); - - return AZStd::string::format( - "[%f, %f, %f %f]\n" - "[%f, %f, %f %f]\n" - "[%f, %f, %f %f]\n" - "[%f, %f, %f %f]", - static_cast(row1.GetX()), static_cast(row1.GetY()), static_cast(row1.GetZ()), static_cast(row1.GetW()), - static_cast(row2.GetX()), static_cast(row2.GetY()), static_cast(row2.GetZ()), static_cast(row2.GetW()), - static_cast(row3.GetX()), static_cast(row3.GetY()), static_cast(row3.GetZ()), static_cast(row3.GetW()), - static_cast(row4.GetX()), static_cast(row4.GetY()), static_cast(row4.GetZ()), static_cast(row4.GetW()) - ); - } - - AZStd::string ToString(const AZ::Color& color) - { - return AZStd::string::format("(R:%d, G:%d, B:%d A:%d)", color.GetR8(), color.GetG8(), color.GetB8(), color.GetA8()); - } -} diff --git a/Code/Framework/AzCore/AzCore/Math/ToString.h b/Code/Framework/AzCore/AzCore/Math/ToString.h deleted file mode 100644 index f7de73f79b..0000000000 --- a/Code/Framework/AzCore/AzCore/Math/ToString.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#pragma once - -#include - -/** - * Utility functions for convertings math types into strings. - */ -namespace AZ -{ - class Vector2; - class Vector3; - class Vector4; - class Quaternion; - class Transform; - class Matrix3x3; - class Matrix4x4; - class Color; - - AZStd::string ToString(const Vector2& vector2); - AZStd::string ToString(const Vector3& vector3); - AZStd::string ToString(const Vector4& vector4); - AZStd::string ToString(const Quaternion& quaternion); - AZStd::string ToString(const Transform& transform); - AZStd::string ToString(const Matrix3x3& matrix33); - AZStd::string ToString(const Matrix4x4& matrix44); - AZStd::string ToString(const Color& color); -} diff --git a/Code/Framework/AzCore/AzCore/azcore_files.cmake b/Code/Framework/AzCore/AzCore/azcore_files.cmake index b7821f1d65..9971b99331 100644 --- a/Code/Framework/AzCore/AzCore/azcore_files.cmake +++ b/Code/Framework/AzCore/AzCore/azcore_files.cmake @@ -298,6 +298,8 @@ set(FILES Math/MathUtils.h Math/MathMatrixSerializer.h Math/MathMatrixSerializer.cpp + Math/MathStringConversions.h + Math/MathStringConversions.cpp Math/MathVectorSerializer.h Math/MathVectorSerializer.cpp Math/Matrix3x3.cpp @@ -364,8 +366,6 @@ set(FILES Math/Color.cpp Math/ColorSerializer.h Math/ColorSerializer.cpp - Math/ToString.h - Math/ToString.cpp Memory/AllocationRecords.cpp Memory/AllocationRecords.h Memory/AllocatorBase.cpp diff --git a/Code/Framework/AzCore/AzCore/std/string/conversions.h b/Code/Framework/AzCore/AzCore/std/string/conversions.h index be71e12275..2ccd82901c 100644 --- a/Code/Framework/AzCore/AzCore/std/string/conversions.h +++ b/Code/Framework/AzCore/AzCore/std/string/conversions.h @@ -286,6 +286,13 @@ namespace AZStd str = buf; } + template + auto to_string(Str& str, BoolType value) + -> std::enable_if_t, bool>> + { + str = value ? "true" : "false"; + } + inline AZStd::string to_string(int val) { AZStd::string str; to_string(str, val); return str; } inline AZStd::string to_string(unsigned int val) { AZStd::string str; to_string(str, val); return str; } inline AZStd::string to_string(float val) { AZStd::string str; to_string(str, val); return str; } @@ -295,6 +302,7 @@ namespace AZStd inline AZStd::string to_string(long long val) { AZStd::string str; to_string(str, val); return str; } inline AZStd::string to_string(unsigned long long val) { AZStd::string str; to_string(str, val); return str; } inline AZStd::string to_string(long double val) { AZStd::string str; to_string(str, val); return str; } + inline AZStd::string to_string(bool val) { AZStd::string str; to_string(str, val); return str; } // In our engine we assume AZStd::string is Utf8 encoded! template diff --git a/Code/Framework/AzCore/Tests/AZStd/String.cpp b/Code/Framework/AzCore/Tests/AZStd/String.cpp index 50450a898c..c3c031f4df 100644 --- a/Code/Framework/AzCore/Tests/AZStd/String.cpp +++ b/Code/Framework/AzCore/Tests/AZStd/String.cpp @@ -665,6 +665,8 @@ namespace UnitTest EXPECT_EQ("20", AZStd::to_string(static_cast(20))); EXPECT_EQ("20", AZStd::to_string(static_cast(20))); EXPECT_EQ("20", AZStd::to_string(static_cast(20))); + EXPECT_EQ("false", AZStd::to_string(false)); + EXPECT_EQ("true", AZStd::to_string(true)); // wstring to string AZStd::string str1; diff --git a/Code/Framework/AzCore/Tests/AZTestShared/Math/MathTestHelpers.cpp b/Code/Framework/AzCore/Tests/AZTestShared/Math/MathTestHelpers.cpp index fc707c9751..e34e586310 100644 --- a/Code/Framework/AzCore/Tests/AZTestShared/Math/MathTestHelpers.cpp +++ b/Code/Framework/AzCore/Tests/AZTestShared/Math/MathTestHelpers.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp b/Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp new file mode 100644 index 0000000000..50d13f2132 --- /dev/null +++ b/Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. + * For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace UnitTest +{ + class MathStrings : public AllocatorsTestFixture + { + + }; + + TEST_F(MathStrings, TestVectorStringConverters) + { + AZ::Vector2 vec2 = AZ::Vector2::CreateOne(); + AZ::Vector3 vec3 = AZ::Vector3::CreateOne(); + AZ::Vector4 vec4 = AZ::Vector4::CreateOne(); + AZ::Quaternion quat = AZ::Quaternion::CreateIdentity(); + + EXPECT_EQ(AZStd::to_string(vec2), "1.00000000,1.00000000"); + EXPECT_EQ(AZStd::to_string(vec3), "1.00000000,1.00000000,1.00000000"); + EXPECT_EQ(AZStd::to_string(vec4), "1.00000000,1.00000000,1.00000000,1.00000000"); + EXPECT_EQ(AZStd::to_string(quat), "0.00000000,0.00000000,0.00000000,1.00000000"); + } + + TEST_F(MathStrings, TestMatrixStringConverters) + { + AZ::Matrix3x3 mat33 = AZ::Matrix3x3::CreateIdentity(); + AZ::Matrix4x4 mat44 = AZ::Matrix4x4::CreateIdentity(); + AZ::Transform xform = AZ::Transform::CreateIdentity(); + + EXPECT_EQ(AZStd::to_string(mat33), "1.00000000,0.00000000,0.00000000\n0.00000000,1.00000000,0.00000000\n0.00000000,0.00000000,1.00000000"); + EXPECT_EQ(AZStd::to_string(mat44), "1.00000000,0.00000000,0.00000000,0.00000000\n0.00000000,1.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,1.00000000,0.00000000\n0.00000000,0.00000000,0.00000000,1.00000000"); + EXPECT_EQ(AZStd::to_string(xform), "0.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,0.00000000"); + + } + + TEST_F(MathStrings, TestAabbStringConverter) + { + AZ::Aabb aabb = AZ::Aabb::CreateFromMinMaxValues(0.f, 0.f, 0.f, 1.f, 1.f, 1.f); + EXPECT_EQ(AZStd::to_string(aabb), "0.00000000,0.00000000,0.00000000\n1.00000000,1.00000000,1.00000000"); + } + + TEST_F(MathStrings, TestColorStringConverter) + { + EXPECT_EQ(AZStd::to_string(AZ::Colors::Black), "R:0, G:0, B:0 A:0"); + } +} diff --git a/Code/Framework/AzCore/Tests/azcoretests_files.cmake b/Code/Framework/AzCore/Tests/azcoretests_files.cmake index b07cd32ec1..b8c13b5f40 100644 --- a/Code/Framework/AzCore/Tests/azcoretests_files.cmake +++ b/Code/Framework/AzCore/Tests/azcoretests_files.cmake @@ -140,6 +140,7 @@ set(FILES Math/FrustumPerformanceTests.cpp Math/IntersectionTests.cpp Math/MathIntrinsicsTests.cpp + Math/MathStringsTests.cpp Math/MathUtilsTests.cpp Math/Matrix3x3PerformanceTests.cpp Math/Matrix3x3Tests.cpp diff --git a/Code/Framework/AzFramework/AzFramework/Components/NonUniformScaleComponent.cpp b/Code/Framework/AzFramework/AzFramework/Components/NonUniformScaleComponent.cpp index 5b27efa616..d539e9b8d2 100644 --- a/Code/Framework/AzFramework/AzFramework/Components/NonUniformScaleComponent.cpp +++ b/Code/Framework/AzFramework/AzFramework/Components/NonUniformScaleComponent.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include namespace AzFramework @@ -65,7 +65,7 @@ namespace AzFramework { AZ::Vector3 clampedScale = scale.GetClamp(AZ::Vector3(AZ::MinTransformScale), AZ::Vector3(AZ::MaxTransformScale)); AZ_Warning("Non-uniform Scale Component", false, "SetScale value was clamped from %s to %s for entity %s", - AZ::ToString(scale).c_str(), AZ::ToString(clampedScale).c_str(), GetEntity()->GetName().c_str()); + AZStd::to_string(scale).c_str(), AZStd::to_string(clampedScale).c_str(), GetEntity()->GetName().c_str()); m_scale = clampedScale; } m_scaleChangedEvent.Signal(m_scale); diff --git a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h index 99f11c37da..cbdf0d6996 100644 --- a/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h +++ b/Code/Framework/AzManipulatorTestFramework/Include/AzManipulatorTestFramework/ActionDispatcher.h @@ -9,7 +9,7 @@ #pragma once #include -#include +#include #include #include @@ -278,7 +278,7 @@ namespace AzManipulatorTestFramework template DerivedDispatcherT* ActionDispatcher::SetEntityWorldTransform(AZ::EntityId entityId, const AZ::Transform& transform) { - Log("Setting entity world transform: %s", AZ::ToString(transform).c_str()); + Log("Setting entity world transform: %s", AZStd::to_string(transform).c_str()); SetEntityWorldTransformImpl(entityId, transform); return static_cast(this); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp index cc3870e27f..31d330434c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/EditorNonUniformScaleComponent.cpp @@ -6,7 +6,7 @@ * */ -#include +#include #include #include #include @@ -112,7 +112,7 @@ namespace AzToolsFramework AZ::Vector3 clampedScale = scale.GetClamp(AZ::Vector3(AZ::MinTransformScale), AZ::Vector3(AZ::MaxTransformScale)); AZ_Warning( "Editor Non-uniform Scale Component", false, "SetScale value was clamped from %s to %s for entity %s", - AZ::ToString(scale).c_str(), AZ::ToString(clampedScale).c_str(), GetEntity()->GetName().c_str()); + AZStd::to_string(scale).c_str(), AZStd::to_string(clampedScale).c_str(), GetEntity()->GetName().c_str()); m_scale = clampedScale; } m_scaleChangedEvent.Signal(m_scale); diff --git a/Code/Framework/AzToolsFramework/Tests/EditorTransformComponentSelectionTests.cpp b/Code/Framework/AzToolsFramework/Tests/EditorTransformComponentSelectionTests.cpp index 29d72a8270..006999e8b7 100644 --- a/Code/Framework/AzToolsFramework/Tests/EditorTransformComponentSelectionTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/EditorTransformComponentSelectionTests.cpp @@ -7,7 +7,6 @@ */ #include -#include #include #include #include diff --git a/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp b/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp index 88a22db245..29c9480a43 100644 --- a/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp +++ b/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp @@ -73,64 +73,3 @@ namespace MCore return result; } } - -namespace AZStd -{ - void to_string(string& str, bool value) - { - str = value ? "true" : "false"; - } - - void to_string(string& str, const AZ::Vector2& value) - { - str = AZStd::string::format("%.8f,%.8f", - static_cast(value.GetX()), - static_cast(value.GetY())); - } - - void to_string(string& str, const AZ::Vector3& value) - { - str = AZStd::string::format("%.8f,%.8f,%.8f", - static_cast(value.GetX()), - static_cast(value.GetY()), - static_cast(value.GetZ())); - } - - void to_string(string& str, const AZ::Vector4& value) - { - str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f", - static_cast(value.GetX()), - static_cast(value.GetY()), - static_cast(value.GetZ()), - static_cast(value.GetW())); - } - - void to_string(string& str, const AZ::Quaternion& value) - { - str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f", - static_cast(value.GetX()), - static_cast(value.GetY()), - static_cast(value.GetZ()), - static_cast(value.GetW())); - } - - void to_string(string& str, const AZ::Matrix4x4& value) - { - str = AZStd::string::format("%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f,%.8f", - static_cast(value(0, 0)), static_cast(value(1, 0)), static_cast(value(2, 0)), static_cast(value(3, 0)), - static_cast(value(0, 1)), static_cast(value(1, 1)), static_cast(value(2, 1)), static_cast(value(3, 1)), - static_cast(value(0, 2)), static_cast(value(1, 2)), static_cast(value(2, 2)), static_cast(value(3, 2)), - static_cast(value(0, 3)), static_cast(value(1, 3)), static_cast(value(2, 3)), static_cast(value(3, 3))); - } - - void to_string(string& str, const AZ::Transform& value) - { - AZ::Matrix3x4 matrix3x4 = AZ::Matrix3x4::CreateFromTransform(value); - - str = AZStd::string::format("%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f\n%.8f,%.8f,%.8f", - static_cast(matrix3x4(0, 0)), static_cast(matrix3x4(1, 0)), static_cast(matrix3x4(2, 0)), - static_cast(matrix3x4(0, 1)), static_cast(matrix3x4(1, 1)), static_cast(matrix3x4(2, 1)), - static_cast(matrix3x4(0, 2)), static_cast(matrix3x4(1, 2)), static_cast(matrix3x4(2, 2)), - static_cast(matrix3x4(0, 3)), static_cast(matrix3x4(1, 3)), static_cast(matrix3x4(2, 3))); - } -} diff --git a/Gems/EMotionFX/Code/MCore/Source/StringConversions.h b/Gems/EMotionFX/Code/MCore/Source/StringConversions.h index fd1c59208d..3a154739d7 100644 --- a/Gems/EMotionFX/Code/MCore/Source/StringConversions.h +++ b/Gems/EMotionFX/Code/MCore/Source/StringConversions.h @@ -9,20 +9,10 @@ #pragma once #include -#include +#include #include #include -namespace AZ -{ - class Matrix4x4; - class Quaternion; - class Transform; - class Vector2; - class Vector3; - class Vector4; -} - namespace MCore { AZStd::string GenerateUniqueString(const char* prefix, const AZStd::function& validationFunction); @@ -46,22 +36,3 @@ namespace MCore static const char* wordSeparators; }; } - -namespace AZStd -{ - void to_string(string& str, bool value); - void to_string(string& str, const AZ::Vector2& value); - void to_string(string& str, const AZ::Vector3& value); - void to_string(string& str, const AZ::Vector4& value); - void to_string(string& str, const AZ::Quaternion& value); - void to_string(string& str, const AZ::Matrix4x4& value); - void to_string(string& str, const AZ::Transform& value); - - inline AZStd::string to_string(bool val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Vector2& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Vector3& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Vector4& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Quaternion& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Matrix4x4& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Transform& val) { AZStd::string str; to_string(str, val); return str; } -} diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp index a53420da84..c85634f151 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugPerEntityReporter.cpp @@ -9,7 +9,6 @@ #include "MultiplayerDebugPerEntityReporter.h" #include -#include #include #include diff --git a/Gems/PhysX/Code/Editor/ColliderSphereMode.cpp b/Gems/PhysX/Code/Editor/ColliderSphereMode.cpp index ba0fd76ea9..343b79d7eb 100644 --- a/Gems/PhysX/Code/Editor/ColliderSphereMode.cpp +++ b/Gems/PhysX/Code/Editor/ColliderSphereMode.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/Gems/PhysX/Code/Source/RigidBody.cpp b/Gems/PhysX/Code/Source/RigidBody.cpp index 5b36376da5..7334f4abc4 100644 --- a/Gems/PhysX/Code/Source/RigidBody.cpp +++ b/Gems/PhysX/Code/Source/RigidBody.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -220,13 +220,13 @@ namespace PhysX { AZ_Warning("RigidBody", !computeCenterOfMass, "Rigid body '%s' cannot compute COM because it contains triangle mesh, plane or heightfield shapes, it will default to %s.", - GetName().c_str(), AZ::ToString(DefaultCenterOfMass).c_str()); + GetName().c_str(), AZStd::to_string(DefaultCenterOfMass).c_str()); AZ_Warning("RigidBody", !computeMass, "Rigid body '%s' cannot compute Mass because it contains triangle mesh, plane or heightfield shapes, it will default to %0.1f.", GetName().c_str(), DefaultMass); AZ_Warning("RigidBody", !computeInertiaTensor, "Rigid body '%s' cannot compute Inertia because it contains triangle mesh, plane or heightfield shapes, it will default to %s.", - GetName().c_str(), AZ::ToString(DefaultInertiaTensor.RetrieveScale()).c_str()); + GetName().c_str(), AZStd::to_string(DefaultInertiaTensor.RetrieveScale()).c_str()); SetCenterOfMassOffset(computeCenterOfMass ? DefaultCenterOfMass : centerOfMassOffsetOverride); SetMass(computeMass ? DefaultMass : massOverride); diff --git a/Gems/PhysX/Code/Source/Utils.cpp b/Gems/PhysX/Code/Source/Utils.cpp index cc4ef2a12c..e82ba167dc 100644 --- a/Gems/PhysX/Code/Source/Utils.cpp +++ b/Gems/PhysX/Code/Source/Utils.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -222,7 +222,7 @@ namespace PhysX if (!shapeConfiguration.m_scale.IsGreaterThan(AZ::Vector3::CreateZero())) { AZ_Error("PhysX Utils", false, "Negative or zero values are invalid for shape configuration scale values %s", - ToString(shapeConfiguration.m_scale).c_str()); + AZStd::to_string(shapeConfiguration.m_scale).c_str()); return false; } @@ -247,7 +247,7 @@ namespace PhysX if (!boxConfig.m_dimensions.IsGreaterThan(AZ::Vector3::CreateZero())) { AZ_Error("PhysX Utils", false, "Negative or zero values are invalid for box dimensions %s", - ToString(boxConfig.m_dimensions).c_str()); + AZStd::to_string(boxConfig.m_dimensions).c_str()); return false; } pxGeometry.storeAny(physx::PxBoxGeometry(PxMathConvert(boxConfig.m_dimensions * 0.5f * shapeConfiguration.m_scale))); diff --git a/Gems/WhiteBox/Code/Source/Core/WhiteBoxToolApi.cpp b/Gems/WhiteBox/Code/Source/Core/WhiteBoxToolApi.cpp index 8d5078dacd..a5241666a6 100644 --- a/Gems/WhiteBox/Code/Source/Core/WhiteBoxToolApi.cpp +++ b/Gems/WhiteBox/Code/Source/Core/WhiteBoxToolApi.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -1433,8 +1433,7 @@ namespace WhiteBox void TranslateEdge(WhiteBoxMesh& whiteBox, const EdgeHandle edgeHandle, const AZ::Vector3& displacement) { WHITEBOX_LOG( - "White Box", "TranslateEdge eh(%s) %s", ToString(edgeHandle).c_str(), - AZ::ToString(displacement).c_str()); + "White Box", "TranslateEdge eh(%s) %s", ToString(edgeHandle).c_str(), AZStd::to_string(displacement).c_str()); AZ_PROFILE_FUNCTION(AzToolsFramework); const auto vertexHandles = EdgeVertexHandles(whiteBox, edgeHandle); @@ -1674,8 +1673,7 @@ namespace WhiteBox WhiteBoxMesh& whiteBox, const EdgeHandle edgeHandle, const AZ::Vector3& displacement) { WHITEBOX_LOG( - "White Box", "TranslateEdgeAppend eh(%s) %s", ToString(edgeHandle).c_str(), - AZ::ToString(displacement).c_str()); + "White Box", "TranslateEdgeAppend eh(%s) %s", ToString(edgeHandle).c_str(), AZStd::to_string(displacement).c_str()); AZ_PROFILE_FUNCTION(AzToolsFramework); // the new and existing handles required for an edge append @@ -2605,8 +2603,7 @@ namespace WhiteBox void SetVertexPosition(WhiteBoxMesh& whiteBox, const VertexHandle vertexHandle, const AZ::Vector3& position) { WHITEBOX_LOG( - "White Box", "SetVertexPosition vh(%s) %s", ToString(vertexHandle).c_str(), - AZ::ToString(position).c_str()); + "White Box", "SetVertexPosition vh(%s) %s", ToString(vertexHandle).c_str(), AZStd::to_string(position).c_str()); AZ_PROFILE_FUNCTION(AzToolsFramework); whiteBox.mesh.set_point(om_vh(vertexHandle), position); @@ -2616,8 +2613,7 @@ namespace WhiteBox WhiteBoxMesh& whiteBox, const VertexHandle vertexHandle, const AZ::Vector3& position) { WHITEBOX_LOG( - "White Box", "SetVertexPositionAndUpdateUVs vh(%s) %s", ToString(vertexHandle).c_str(), - AZ::ToString(position).c_str()); + "White Box", "SetVertexPositionAndUpdateUVs vh(%s) %s", ToString(vertexHandle).c_str(), AZStd::to_string(position).c_str()); AZ_PROFILE_FUNCTION(AzToolsFramework); SetVertexPosition(whiteBox, vertexHandle, position); @@ -2626,7 +2622,7 @@ namespace WhiteBox VertexHandle AddVertex(WhiteBoxMesh& whiteBox, const AZ::Vector3& vertex) { - WHITEBOX_LOG("White Box", "AddVertex %s", AZ::ToString(vertex).c_str()); + WHITEBOX_LOG("White Box", "AddVertex %s", AZStd::to_string(vertex).c_str()); AZ_PROFILE_FUNCTION(AzToolsFramework); return wb_vh(whiteBox.mesh.add_vertex(vertex)); @@ -3362,7 +3358,7 @@ namespace WhiteBox { WHITEBOX_LOG( "White Box", "ScalePolygonRelative ph(%s) pivot %s scale: %f", ToString(polygonHandle).c_str(), - AZ::ToString(pivot).c_str(), scaleDelta); + AZStd::to_string(pivot).c_str(), scaleDelta); AZ_PROFILE_FUNCTION(AzToolsFramework); const AZ::Transform polygonSpace = PolygonSpace(whiteBox, polygonHandle, pivot); From e481f6bfcf6ffc427110bfd94dae337a0d234cb4 Mon Sep 17 00:00:00 2001 From: puvvadar Date: Fri, 11 Feb 2022 18:03:38 -0800 Subject: [PATCH 2/5] Fix math string unit test failures Signed-off-by: puvvadar --- Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp b/Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp index 50d13f2132..c976d1b1df 100644 --- a/Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp +++ b/Code/Framework/AzCore/Tests/Math/MathStringsTests.cpp @@ -47,7 +47,7 @@ namespace UnitTest EXPECT_EQ(AZStd::to_string(mat33), "1.00000000,0.00000000,0.00000000\n0.00000000,1.00000000,0.00000000\n0.00000000,0.00000000,1.00000000"); EXPECT_EQ(AZStd::to_string(mat44), "1.00000000,0.00000000,0.00000000,0.00000000\n0.00000000,1.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,1.00000000,0.00000000\n0.00000000,0.00000000,0.00000000,1.00000000"); - EXPECT_EQ(AZStd::to_string(xform), "0.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,0.00000000\n0.00000000,0.00000000,0.00000000"); + EXPECT_EQ(AZStd::to_string(xform), "1.00000000,0.00000000,0.00000000\n0.00000000,1.00000000,0.00000000\n0.00000000,0.00000000,1.00000000\n0.00000000,0.00000000,0.00000000"); } @@ -59,6 +59,6 @@ namespace UnitTest TEST_F(MathStrings, TestColorStringConverter) { - EXPECT_EQ(AZStd::to_string(AZ::Colors::Black), "R:0, G:0, B:0 A:0"); + EXPECT_EQ(AZStd::to_string(AZ::Colors::Black), "R:0, G:0, B:0 A:255"); } } From e9378efffe1d33bcc40c2c6405b738948aa36bf4 Mon Sep 17 00:00:00 2001 From: puvvadar Date: Mon, 14 Feb 2022 12:39:16 -0800 Subject: [PATCH 3/5] Fix std namespace usages Signed-off-by: puvvadar --- Code/Framework/AzCore/AzCore/std/string/conversions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/std/string/conversions.h b/Code/Framework/AzCore/AzCore/std/string/conversions.h index 2ccd82901c..9427eaccf6 100644 --- a/Code/Framework/AzCore/AzCore/std/string/conversions.h +++ b/Code/Framework/AzCore/AzCore/std/string/conversions.h @@ -288,7 +288,7 @@ namespace AZStd template auto to_string(Str& str, BoolType value) - -> std::enable_if_t, bool>> + -> enable_if_t, bool>> { str = value ? "true" : "false"; } From 056b308854132d8d174e63df0852a0c4c89f6a15 Mon Sep 17 00:00:00 2001 From: puvvadar Date: Tue, 15 Feb 2022 11:11:08 -0800 Subject: [PATCH 4/5] Cleanup doxygen comments in MathStringConverters Signed-off-by: puvvadar --- .../AzCore/AzCore/Math/MathStringConversions.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h index 48c37c51ee..3f52abf8ab 100644 --- a/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h +++ b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h @@ -27,31 +27,31 @@ namespace AZ namespace AZStd { - //! Prints a Vector2 with precision to 8 decimal points + //! Prints a Vector2 with precision to 8 decimal places. void to_string(string& str, const AZ::Vector2& value); - //! Prints a Vector3 with precision to 8 decimal points + //! Prints a Vector3 with precision to 8 decimal places. void to_string(string& str, const AZ::Vector3& value); - //! Prints a Vector4 with precision to 8 decimal points + //! Prints a Vector4 with precision to 8 decimal places. void to_string(string& str, const AZ::Vector4& value); - //! Prints a Quaternion with precision to 8 decimal points + //! Prints a Quaternion with precision to 8 decimal places. void to_string(string& str, const AZ::Quaternion& value); - //! Prints a 3x3 matrix in row major order over three lines with precision to 8 decimal points + //! Prints a 3x3 matrix in row major order over three lines with precision to 8 decimal places. void to_string(string& str, const AZ::Matrix3x3& value); - //! Prints a 4x4 matrix in row major order over four lines with precision to 8 decimal points + //! Prints a 4x4 matrix in row major order over four lines with precision to 8 decimal places. void to_string(string& str, const AZ::Matrix4x4& value); - //! Prints a transform as a 3x4 matrix in row major order over four lines with precision to 8 decimal points + //! Prints a transform as a 3x4 matrix in row major order over four lines with precision to 8 decimal places. void to_string(string& str, const AZ::Transform& value); - //! Prints an AABB as a pair of Vector3s with precision to 8 decimal points + //! Prints an AABB as a pair of Vector3s with precision to 8 decimal places. void to_string(string& str, const AZ::Aabb& value); - //! Prints a Color as four unsigned ints representing RGBA + //! Prints a Color as four unsigned ints representing RGBA. void to_string(string& str, const AZ::Color& value); inline AZStd::string to_string(const AZ::Vector2& val) { AZStd::string str; to_string(str, val); return str; } From 781769b0125c40fe0544ae52fac91c7653c70bad Mon Sep 17 00:00:00 2001 From: puvvadar Date: Wed, 16 Feb 2022 15:31:58 -0800 Subject: [PATCH 5/5] Clang format MathStringConversions.h Signed-off-by: puvvadar --- .../AzCore/Math/MathStringConversions.h | 74 ++++++++++++++++--- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h index 3f52abf8ab..f4861eba3f 100644 --- a/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h +++ b/Code/Framework/AzCore/AzCore/Math/MathStringConversions.h @@ -23,7 +23,7 @@ namespace AZ class Vector2; class Vector3; class Vector4; -} +} // namespace AZ namespace AZStd { @@ -54,13 +54,65 @@ namespace AZStd //! Prints a Color as four unsigned ints representing RGBA. void to_string(string& str, const AZ::Color& value); - inline AZStd::string to_string(const AZ::Vector2& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Vector3& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Vector4& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Quaternion& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Matrix3x3& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Matrix4x4& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Transform& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Aabb& val) { AZStd::string str; to_string(str, val); return str; } - inline AZStd::string to_string(const AZ::Color& val) { AZStd::string str; to_string(str, val); return str; } -} + inline AZStd::string to_string(const AZ::Vector2& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + + inline AZStd::string to_string(const AZ::Vector3& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + + inline AZStd::string to_string(const AZ::Vector4& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + + inline AZStd::string to_string(const AZ::Quaternion& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + + inline AZStd::string to_string(const AZ::Matrix3x3& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + + inline AZStd::string to_string(const AZ::Matrix4x4& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + inline AZStd::string to_string(const AZ::Transform& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + + inline AZStd::string to_string(const AZ::Aabb& val) + { + AZStd::string str; + to_string(str, val); + return str; + } + + inline AZStd::string to_string(const AZ::Color& val) + { + AZStd::string str; + to_string(str, val); + return str; + } +} // namespace AZStd