 |
NumCpp
2.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)
143 Vec2 returnVec =
Vec2(*this).normalize();
144 returnVec *= maxLength;
157 return (
Vec2(*
this) -= otherVec).norm();
167 double dot(
const Vec2& otherVec)
const noexcept
169 return x * otherVec.x +
y * otherVec.y;
180 return Vec2(0.0, -1.0);
191 return Vec2(-1.0, 0.0);
206 Vec2 trajectory = otherVec;
211 return Vec2(*
this) +=
Vec2(xInterp, yInterp);
246 return otherVec.normalize() *= projectedMagnitude;
257 return Vec2(1.0, 0.0);
268 std::stringstream stream;
269 stream <<
"Vec2[" <<
x <<
", " <<
y <<
"]";
293 return Vec2(0.0, 1.0);
317 return !(*
this == rhs);
415 return Vec2(lhs) += rhs;
428 return Vec2(rhs) += lhs;
441 return Vec2(lhs) += rhs;
452 return {-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;
double dot(const Vec2 &otherVec) const noexcept
Definition: Vec2.hpp:167
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:2644
Vec2 & operator-=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:369
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:243
static constexpr Vec2 right() noexcept
Definition: Vec2.hpp:255
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:53
Vec2 & operator+=(const Vec2 &rhs) noexcept
Definition: Vec2.hpp:341
std::string toString() const
Definition: Vec2.hpp:266
Vec2(const NdArray< double > &ndArray)
Definition: Vec2.hpp:97
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4608
static constexpr Vec2 up() noexcept
Definition: Vec2.hpp:291
auto cos(dtype inValue) noexcept
Definition: cos.hpp:52
Vec2 lerp(const Vec2 &otherVec, double t) const noexcept
Definition: Vec2.hpp:202
bool operator==(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:303
size_type size() const noexcept
Definition: NdArrayCore.hpp:4326
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:220
#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:383
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:155
Vec2 normalize() const noexcept
Definition: Vec2.hpp:231
Vec2 & operator-=(double scaler) noexcept
Definition: Vec2.hpp:355
static constexpr Vec2 down() noexcept
Definition: Vec2.hpp:178
Vec2 & operator/=(double scaler) noexcept
Definition: Vec2.hpp:397
bool operator!=(const Vec2 &rhs) const noexcept
Definition: Vec2.hpp:315
NdArray< dtype > operator*(const NdArray< dtype > &lhs, const NdArray< dtype > &rhs)
Definition: NdArrayOperators.hpp:802
Vec2 & operator+=(double scaler) noexcept
Definition: Vec2.hpp:327
static constexpr Vec2 left() noexcept
Definition: Vec2.hpp:189
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:46
NdArray< double > toNdArray() const
Definition: Vec2.hpp:279