Template Class vector2
Defined in File vector2.hpp
Nested Relationships
Nested Types
Inheritance Relationships
Base Type
public rcppsw::er::stringizable
(Class stringizable)
Class Documentation
-
template<typename T>
class vector2 : public rcppsw::er::stringizable Base template class encapsulating mathematical actions on a pair of numbers. Is specialized by vector2i, vector2d.
All operations are performed in whatever the template parameter is, so take care if you are trying to do scaling, trigonometric things with integers…
Public Functions
-
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline vector2(const T &length, const radians &angle) noexcept Initializes the vector coordinates from polar coordinates.
- Parameters:
length – The vector length.
angle – The vector angle.
-
inline constexpr vector2(const T &x, const T &y) noexcept
Initializes the vector from Cartesian coordinates.
- Parameters:
x – The X coordinate.
y – The Y coordinate.
-
vector2(void) noexcept = default
Initializes vector to (0,0)
-
inline bool is_pd(void) const
Is the vector is positive definite?
-
inline bool is_psd(void) const
Is the vector is positive semi-definite?
-
inline double length(void) const
Returns the length of this vector.
-
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline vector2 &normalize(void) Normalizes this vector.
After this method is called, the vector has length 1. If the vector is (0,0), this call results in a division by zero error, and your program will probably crash.
- Returns:
A reference to the normalized vector.
-
inline bool operator!=(const vector2 &other) const
Returns if this vector and the passed one are not equal by checking coordinates for equality.
Should generally not be called if the template parameter type is not an integer, as floating point comparisons in general are unsafe.
-
template<typename U = T, typename std::enable_if<!std::is_floating_point<U>::value, int>::type = 0>
inline bool operator<(const vector2 &other) const Needed for using vectors as keys in a map.
-
template<typename U = T, typename std::enable_if<!std::is_floating_point<U>::value, int>::type = 0>
inline bool operator==(const vector2 &other) const Returns if this vector and the argument are considered equal, determined by coordinate comparison.
Only available if the template argument is not floating point.
-
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline bool operator==(const vector2 &other) const Returns if this vector and the argument are considered equal, determined by coordinate comparison.
Only available if the template argument is floating point.
-
template<typename U = T, typename std::enable_if<!std::is_floating_point<U>::value, int>::type = 0>
inline bool operator>(const vector2 &other) const
-
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline vector2 &rotate(const radians &angle) Rotate this vector by the specified angle.
This is only available if the template parameter is not an integer.
- Parameters:
angle – The rotation angle.
- Returns:
A reference to the rotated vector.
-
inline vector2 &scale(const T &factor)
Scales the vector by the specified values.
- Parameters:
factor – The scaling factor applied to both X and Y.
- Returns:
A reference to the scaled vector.
-
inline vector2 &scale(const T &scale_x, const T &scale_y)
Scales the vector by the specified values.
- Parameters:
scale_x – the scale factor for the X coordinate.
scale_y – the scale factor for the Y coordinate.
- Returns:
A reference to the scaled vector.
-
inline void set(const T &x, const T &y)
Sets the vector contents from Cartesian coordinates.
- Parameters:
x – The new X coordinate.
y – The new Y coordinate.
-
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline void set_from_polar(const T &length, const radians &angle) Sets the vector contents from polar coordinates.
- Parameters:
length – The length of the vector.
angle – The angle of the vector (range [0,2pi)
-
inline virtual std::string to_str(void) const override
Return a string representation of a class.
Public Static Functions
Public Static Attributes
-
static constexpr size_t kDIMENSIONALITY = 2
Friends
-
struct componentwise_compare
Needed to compare in mathematical contexts.
-
struct key_compare
Needed for using vectors as keys in a map.
-
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>