#include <Magnum/Math/Vector2.h>
template<class T>
Vector2 class
Two-component vector.
Template parameters | |
---|---|
T | Data type |
See Operations with matrices and vectors for brief introduction. The vectors are columns, see Matrix2x1 for a row vector.
Base classes
-
template<std::class Vector<2, T>
size_t size, class T> - Vector.
Public static functions
- static auto xAxis(T length = T(1)) -> Vector2<T> constexpr
- Vector in a direction of X axis (right)
- static auto yAxis(T length = T(1)) -> Vector2<T> constexpr
- Vector in a direction of Y axis (up)
- static auto xScale(T scale) -> Vector2<T> constexpr
- Scaling vector in a direction of X axis (width)
- static auto yScale(T scale) -> Vector2<T> constexpr
- Scaling vector in a direction of Y axis (height)
Constructors, destructors, conversion operators
- Vector2() constexpr noexcept
- Default constructor.
- Vector2(ZeroInitT) explicit constexpr noexcept
- Construct a zero vector.
-
Vector2(Magnum::
NoInitT) explicit noexcept - Construct a vector without initializing the contents.
- Vector2(T value) explicit constexpr noexcept
- Construct a vector with one value for all components.
- Vector2(T x, T y) constexpr noexcept
- Constructor.
-
template<std::Vector2(const T(&data)[size_]) explicit constexpr noexcept new in Git master
size_t size_> - Construct a vector from a fixed-size array.
-
template<class U>Vector2(const Vector<2, U>& other) explicit constexpr noexcept
- Construct a vector from another of different type.
- Vector2(const BitVector2& other) explicit constexpr noexcept new in Git master
- Construct a vector from a BitVector.
-
template<class U, class = decltype(Implementation::VectorConverter<2, T, U>::from(std::Vector2(const U& other) explicit constexpr
declval<U>()))> - Construct a vector from external representation.
- Vector2(const Vector<2, T>& other) constexpr noexcept
- Copy constructor.
Public functions
- auto x() -> T&
- X component.
- auto x() const -> const T& constexpr
- auto y() -> T&
- Y component.
- auto y() const -> const T& constexpr
- auto r() -> T& new in Git master
- R component.
- auto r() const -> const T& constexpr new in Git master
- auto g() -> T& new in Git master
- Y component.
- auto g() const -> const T& constexpr new in Git master
- auto perpendicular() const -> Vector2<T>
- Perpendicular vector.
- auto aspectRatio() const -> T
- Aspect ratio.
Function documentation
template<class T>
Magnum:: Math:: Vector2<T>:: Vector2() constexpr noexcept
Default constructor.
Equivalent to Vector2(ZeroInitT).
template<class T>
Magnum:: Math:: Vector2<T>:: Vector2(T x,
T y) constexpr noexcept
Constructor.
template<class T>
template<std:: size_t size_>
Magnum:: Math:: Vector2<T>:: Vector2(const T(&data)[size_]) explicit constexpr noexcept new in Git master
Construct a vector from a fixed-size array.
Use from(const T*) to reinterpret an arbitrary pointer to a vector.
template<class T>
template<class U>
Magnum:: Math:: Vector2<T>:: Vector2(const Vector<2, U>& other) explicit constexpr noexcept
Construct a vector from another of different type.
Performs only default casting on the values, no rounding or anything else. Example usage:
Vector4 floatingPoint{1.3f, 2.7f, -15.0f, 7.0f}; Vector4i integral{floatingPoint}; // {1, 2, -15, 7}
template<class T>
Magnum:: Math:: Vector2<T>:: Vector2(const BitVector2& other) explicit constexpr noexcept new in Git master
Construct a vector from a BitVector.
Bits that are unset are converted to 0
, set bits to 1
. If you need a different behavior, for example converting a bit mask to 0
or 255
for a color representation, use lerp(const Vector<size, T>&, const Vector<size, T>&, const BitVector<size>&) instead, for example:
BitVector3 mask = …; Vector3ub a = Math::lerp(Vector3ub{0}, Vector3ub{255}, mask);
template<class T>
T& Magnum:: Math:: Vector2<T>:: x()
X component.
template<class T>
const T& Magnum:: Math:: Vector2<T>:: x() const constexpr
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T& Magnum:: Math:: Vector2<T>:: y()
Y component.
template<class T>
const T& Magnum:: Math:: Vector2<T>:: y() const constexpr
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T& Magnum:: Math:: Vector2<T>:: r() new in Git master
R component.
Equivalent to x().
template<class T>
const T& Magnum:: Math:: Vector2<T>:: r() const constexpr new in Git master
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
T& Magnum:: Math:: Vector2<T>:: g() new in Git master
Y component.
Equivalent to y().
template<class T>
const T& Magnum:: Math:: Vector2<T>:: g() const constexpr new in Git master
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T>
Vector2<T> Magnum:: Math:: Vector2<T>:: perpendicular() const
Perpendicular vector.
Returns vector rotated 90° counterclockwise. Enabled only for signed types.
template<class T>
T Magnum:: Math:: Vector2<T>:: aspectRatio() const
Aspect ratio.
Returns quotient of the two elements. Enabled only for floating-point types.