31#include <initializer_list>
59 constexpr Vec2() =
default;
68 constexpr Vec2(
double inX,
double inY) noexcept :
80 Vec2(
const std::initializer_list<double>& inList)
82 if (inList.size() != 2)
88 y = *(inList.begin() + 1);
99 if (ndArray.
size() != 2)
115 [[nodiscard]]
double angle(
const Vec2& otherVec)
const noexcept
117 double dotProduct =
dot(otherVec);
118 dotProduct /=
norm();
119 dotProduct /= otherVec.norm();
124 return std::acos(dotProduct);
137 const double magnitude =
norm();
138 if (magnitude <= maxLength)
143 Vec2 returnVec =
Vec2(*this).normalize();
144 returnVec *= maxLength;
157 return (
Vec2(*
this) -= otherVec).norm();
167 [[nodiscard]]
double dot(
const Vec2& otherVec)
const noexcept
169 return x * otherVec.x +
y * otherVec.y;
180 return Vec2(0., -1.);
191 return Vec2(-1., 0.);
206 Vec2 trajectory = otherVec;
211 return Vec2(*
this) +=
Vec2(xInterp, yInterp);
220 [[nodiscard]]
double norm() const noexcept
246 return otherVec.normalize() *= projectedMagnitude;
268 std::stringstream stream;
269 stream <<
"Vec2[" <<
x <<
", " <<
y <<
"]";
317 return !(*
this == rhs);
415 return Vec2(lhs) += rhs;
428 return Vec2(rhs) += lhs;
441 return Vec2(lhs) += rhs;
452 return Vec2(-vec.x, -vec.y);
465 return Vec2(lhs) -= rhs;
478 return -
Vec2(rhs) += lhs;
491 return Vec2(lhs) -= rhs;
504 return Vec2(lhs) *= rhs;
517 return Vec2(rhs) *= lhs;
544 return Vec2(lhs) /= rhs;
557 stream << vec.
toString() << std::endl;
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
self_type transpose() const
Definition: NdArrayCore.hpp:4882
Holds a 2D vector.
Definition: Vec2.hpp:49
double dot(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:167
static constexpr Vec2 down() noexcept
Definition: Vec2.hpp:178
double angle(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:115
double x
Definition: Vec2.hpp:52
Vec2 & operator*=(double scalar) noexcept
Definition: Vec2.hpp:383
Vec2 & operator/=(double scalar) noexcept
Definition: Vec2.hpp:397
double distance(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:155
Vec2 & operator-=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:369
static constexpr Vec2 up() noexcept
Definition: Vec2.hpp:291
Vec2 normalize() const noexcept
Definition: Vec2.hpp:231
Vec2 lerp(const Vec2 &otherVec, double t) const noexcept
Definition: Vec2.hpp:202
Vec2(const NdArray< double > &ndArray)
Definition: Vec2.hpp:97
Vec2 & operator-=(double scalar) noexcept
Definition: Vec2.hpp:355
Vec2 project(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:243
double norm() const noexcept
Definition: Vec2.hpp:220
static constexpr Vec2 right() noexcept
Definition: Vec2.hpp:255
Vec2 clampMagnitude(double maxLength) const noexcept
Definition: Vec2.hpp:135
Vec2(const std::initializer_list< double > &inList)
Definition: Vec2.hpp:80
bool operator!=(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:315
Vec2 & operator+=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:341
std::string toString() const
Definition: Vec2.hpp:266
double y
Definition: Vec2.hpp:53
static constexpr Vec2 left() noexcept
Definition: Vec2.hpp:189
Vec2 & operator+=(double scalar) noexcept
Definition: Vec2.hpp:327
constexpr Vec2(double inX, double inY) noexcept
Definition: Vec2.hpp:68
bool operator==(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:303
NdArray< double > toNdArray() const
Definition: Vec2.hpp:279
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition: Utils/interp.hpp:41
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:49
Definition: Cartesian.hpp:40
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:44
Duration operator-(const DateTime &lhs, const DateTime &rhs) noexcept
Subtraction operator.
Definition: DateTime/DateTime.hpp:551
NdArray< dtype > operator/(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:819
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:56
auto cos(dtype inValue) noexcept
Definition: cos.hpp:49
std::ostream & operator<<(std::ostream &os, Duration duration)
Output stream operator for the Duration type.
Definition: Clock.hpp:30
NdArrayConstIterator< dtype, PointerType, DifferenceType > operator+(typename NdArrayConstIterator< dtype, PointerType, DifferenceType >::difference_type offset, NdArrayConstIterator< dtype, PointerType, DifferenceType > next) noexcept
Definition: NdArrayIterators.hpp:302
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:604
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44