 |
NumCpp
1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
37 #include <initializer_list>
60 constexpr
Vec2() =
default;
69 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)
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)
144 Vec2 returnVec =
Vec2(*this).normalize();
145 returnVec *= maxLength;
159 return (
Vec2(*
this) -= otherVec).norm();
169 double dot(
const Vec2& otherVec)
const noexcept
171 return x * otherVec.x +
y * otherVec.y;
182 return Vec2(0.0, -1.0);
193 return Vec2(-1.0, 0.0);
208 Vec2 trajectory = otherVec;
213 return Vec2(*
this) +=
Vec2(xInterp, yInterp);
248 return otherVec.normalize() *= projectedMagnitude;
259 return Vec2(1.0, 0.0);
270 std::stringstream stream;
271 stream <<
"Vec2[" <<
x <<
", " <<
y <<
"]";
295 return Vec2(0.0, 1.0);
319 return !(*
this == rhs);
417 return Vec2(lhs) += rhs;
430 return Vec2(rhs) += lhs;
443 return Vec2(lhs) += rhs;
454 return Vec2(-vec.x, -vec.y);
467 return Vec2(lhs) -= rhs;
480 return -
Vec2(rhs) += lhs;
493 return Vec2(lhs) -= rhs;
506 return Vec2(lhs) *= rhs;
519 return Vec2(rhs) *= lhs;
546 return Vec2(lhs) /= rhs;
559 stream << vec.
toString() << std::endl;
double dot(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:169
double y
Definition: Vec2.hpp:54
Holds a 2D vector.
Definition: Vec2.hpp:49
NdArrayConstIterator< dtype, PointerType, DifferenceType > operator+(typename NdArrayConstIterator< dtype, PointerType, DifferenceType >::difference_type offset, NdArrayConstIterator< dtype, PointerType, DifferenceType > next) noexcept
Definition: NdArrayIterators.hpp:305
NdArray< dtype > dot(const NdArray< dtype > &inOtherArray) const
Definition: NdArrayCore.hpp:2635
Vec2 & operator-=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:371
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition: Utils/interp.hpp:44
double x
Definition: Vec2.hpp:53
NdArray< dtype > operator/(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:1091
Vec2 project(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:245
static constexpr Vec2 right() noexcept
Definition: Vec2.hpp:257
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:53
Vec2 & operator+=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:343
std::string toString() const
Definition: Vec2.hpp:268
Vec2(const NdArray< double > &ndArray)
Definition: Vec2.hpp:97
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4591
static constexpr Vec2 up() noexcept
Definition: Vec2.hpp:293
auto cos(dtype inValue) noexcept
Definition: cos.hpp:52
Vec2 lerp(const Vec2 &otherVec, double t) const noexcept
Definition: Vec2.hpp:204
bool operator==(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:305
size_type size() const noexcept
Definition: NdArrayCore.hpp:4310
double angle(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:115
double hypot(dtype inValue1, dtype inValue2) noexcept
Definition: hypot.hpp:58
constexpr Vec2(double inX, double inY) noexcept
Definition: Vec2.hpp:69
NdArray< dtype > operator-(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:444
Definition: Coordinate.hpp:45
Vec2(const std::initializer_list< double > &inList)
Definition: Vec2.hpp:80
double norm() const noexcept
Definition: Vec2.hpp:222
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
Vec2 clampMagnitude(double maxLength) const noexcept
Definition: Vec2.hpp:135
NdArray< dtype > operator<<(const NdArray< dtype > &lhs, uint8 inNumBits)
Definition: NdArrayOperators.hpp:2414
Vec2 & operator*=(double scaler) noexcept
Definition: Vec2.hpp:385
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:46
double distance(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:157
Vec2 normalize() const noexcept
Definition: Vec2.hpp:233
Vec2 & operator-=(double scaler) noexcept
Definition: Vec2.hpp:357
static constexpr Vec2 down() noexcept
Definition: Vec2.hpp:180
Vec2 & operator/=(double scaler) noexcept
Definition: Vec2.hpp:399
bool operator!=(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:317
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:802
Vec2 & operator+=(double scaler) noexcept
Definition: Vec2.hpp:329
static constexpr Vec2 left() noexcept
Definition: Vec2.hpp:191
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:46
NdArray< double > toNdArray() const
Definition: Vec2.hpp:281