36 #include <initializer_list>
59 constexpr
Vec2() =
default;
68 constexpr
Vec2(
double inX,
double inY) noexcept :
79 Vec2(
const std::initializer_list<double>& inList)
81 if (inList.size() != 2)
87 y = *(inList.begin() + 1);
98 if (ndArray.
size() != 2)
116 double dotProduct =
dot(otherVec);
117 dotProduct /=
norm();
118 dotProduct /= otherVec.norm();
123 return std::acos(dotProduct);
136 const double magnitude =
norm();
137 if (magnitude <= maxLength)
142 Vec2 returnVec =
Vec2(*this).normalize();
143 returnVec *= maxLength;
156 return (
Vec2(*
this) -= otherVec).norm();
166 double dot(
const Vec2& otherVec)
const noexcept
168 return x * otherVec.x +
y * otherVec.y;
179 return Vec2(0.0, -1.0);
190 return Vec2(-1.0, 0.0);
205 Vec2 trajectory = otherVec;
210 return Vec2(*
this) +=
Vec2(xInterp, yInterp);
245 return otherVec.normalize() *= projectedMagnitude;
256 return Vec2(1.0, 0.0);
267 std::stringstream stream;
268 stream <<
"Vec2[" <<
x <<
", " <<
y <<
"]";
292 return Vec2(0.0, 1.0);
316 return !(*
this == rhs);
414 return Vec2(lhs) += rhs;
427 return Vec2(rhs) += lhs;
440 return Vec2(lhs) += rhs;
451 return {-vec.x, -vec.y};
464 return Vec2(lhs) -= rhs;
477 return -
Vec2(rhs) += lhs;
490 return Vec2(lhs) -= rhs;
503 return Vec2(lhs) *= rhs;
516 return Vec2(rhs) *= lhs;
543 return Vec2(lhs) /= rhs;
556 stream << vec.
toString() << std::endl;
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4497
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4841
Holds a 2D vector.
Definition: Vec2.hpp:49
Vec2 & operator-=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:368
Vec2 & operator/=(double scaler) noexcept
Definition: Vec2.hpp:396
Vec2 & operator+=(double scaler) noexcept
Definition: Vec2.hpp:326
double dot(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:166
static constexpr Vec2 down() noexcept
Definition: Vec2.hpp:177
double angle(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:114
double x
Definition: Vec2.hpp:52
double distance(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:154
Vec2 & operator*=(double scaler) noexcept
Definition: Vec2.hpp:382
static constexpr Vec2 up() noexcept
Definition: Vec2.hpp:290
Vec2 normalize() const noexcept
Definition: Vec2.hpp:230
Vec2 lerp(const Vec2 &otherVec, double t) const noexcept
Definition: Vec2.hpp:201
Vec2(const NdArray< double > &ndArray)
Definition: Vec2.hpp:96
Vec2 project(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:242
double norm() const noexcept
Definition: Vec2.hpp:219
static constexpr Vec2 right() noexcept
Definition: Vec2.hpp:254
Vec2 clampMagnitude(double maxLength) const noexcept
Definition: Vec2.hpp:134
Vec2 & operator-=(double scaler) noexcept
Definition: Vec2.hpp:354
Vec2(const std::initializer_list< double > &inList)
Definition: Vec2.hpp:79
bool operator!=(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:314
std::string toString() const
Definition: Vec2.hpp:265
NdArray< double > toNdArray() const
Definition: Vec2.hpp:278
double y
Definition: Vec2.hpp:53
static constexpr Vec2 left() noexcept
Definition: Vec2.hpp:188
constexpr Vec2(double inX, double inY) noexcept
Definition: Vec2.hpp:68
bool operator==(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:302
Vec2 & operator+=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:340
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition: Utils/interp.hpp:43
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
Definition: Coordinate.hpp:45
NdArray< dtype > operator<<(const NdArray< dtype > &lhs, uint8 inNumBits)
Definition: NdArrayOperators.hpp:2413
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:57
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:45
NdArrayConstIterator< dtype, PointerType, DifferenceType > operator+(typename NdArrayConstIterator< dtype, PointerType, DifferenceType >::difference_type offset, NdArrayConstIterator< dtype, PointerType, DifferenceType > next) noexcept
Definition: NdArrayIterators.hpp:310
auto cos(dtype inValue) noexcept
Definition: cos.hpp:51
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:45
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:801
NdArray< dtype > operator-(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:443
NdArray< dtype > operator/(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:1090