From 8fa94c1519f47050ff7625ef81a1f4bcdd168085 Mon Sep 17 00:00:00 2001 From: josh Date: Tue, 6 Feb 2024 16:34:26 -0500 Subject: [PATCH] Implement Vector2::Abs() and Vector3::Abs() --- include/J3ML/LinearAlgebra/Vector2.h | 2 ++ src/J3ML/LinearAlgebra/Vector2.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/J3ML/LinearAlgebra/Vector2.h b/include/J3ML/LinearAlgebra/Vector2.h index d007503..286e80b 100644 --- a/include/J3ML/LinearAlgebra/Vector2.h +++ b/include/J3ML/LinearAlgebra/Vector2.h @@ -31,6 +31,8 @@ namespace J3ML::LinearAlgebra { void SetX(float newX); void SetY(float newY); + Vector2 Abs() const; + bool IsWithinMarginOfError(const Vector2& rhs, float margin=0.001f) const; bool IsNormalized(float epsilonSq = 1e-5f) const; diff --git a/src/J3ML/LinearAlgebra/Vector2.cpp b/src/J3ML/LinearAlgebra/Vector2.cpp index 388d578..5e15bbc 100644 --- a/src/J3ML/LinearAlgebra/Vector2.cpp +++ b/src/J3ML/LinearAlgebra/Vector2.cpp @@ -253,4 +253,6 @@ namespace J3ML::LinearAlgebra { Vector2 Vector2::Div(const Vector2 &v) const { return {this->x/v.x, this->y/v.y}; } + + Vector2 Vector2::Abs() const { return {std::abs(x), std::abs(y)};} } \ No newline at end of file