template <typename T = f32>
rll::size2d struct

A two-dimensional size2d tagged with a unit.

Template parameters
T Number type. Must satisfy concept rll::concepts::num. Default is f32.

Public types

using number_type = T
Underlying number type.

Public static functions

template <std::size_t N2, typename = std::enable_if_t<N2 == 2>>
static auto from_array(std::array<number_type, N2> const& other) →  size2d constexpr
Constructs new size2d from std::array.
static auto from_pair(std::pair<number_type, number_type> const& other) →  size2d constexpr
Constructs new size2d from std::pair.
template <typename... Args, typename = std::enable_if_t<std::tuple_size_v<std::tuple<Args...>> == 2>>
static auto from_tuple(std::tuple<Args...> const& other) →  size2d constexpr
Constructs new size2d from std::tuple.
static auto splat(number_type value) →  size2d constexpr
Constructs new size2d, setting all components to the same value.
static auto zero() →  size2d constexpr
The same as origin.

Constructors, destructors, conversion operators

operator bool() const explicit constexpr
Returns true if underlying values is both not 0 and not NaN or Infinity in case of floating point.
size2d(size2d const&) defaulted constexpr
Default copy constructor.
size2d(size2d&&) defaulted constexpr
Default move constructor.
size2d() constexpr
Constructs new size2d with zero coordinates.
size2d(number_type x, number_type y) constexpr
Constructs new size2d from given scalar values.
size2d(number_type value) explicit constexpr
Constructs new size2d, setting all components to the same value.
size2d(point2d<number_type> const& p) explicit constexpr
Constructs new size2d from a point2d.
size2d(vector2d<number_type> const& v) explicit constexpr
Constructs new size2d from a vector2d.

Public functions

auto abs() const →  size2d constexpr
Returns the absolute value of each component.
auto area() const →  number_type constexpr
Returns result of multiplication of both scalars.
template <typename U, typename = std::enable_if_t<is_num_v<T>>>
auto cast() const →  size2d<U> constexpr
Cast from one numeric representation to another, preserving the units.
auto ceil() const →  size2d constexpr
Rounds each component to the smallest integer equal or greater than the original value.
auto clamp(size2d const& start, size2d const& end) const →  size2d constexpr
Returns the size2d each component of which clamped by corresponding components of start and end.
auto cross(size2d const& other) const →  number_type constexpr
Returns the norm of the cross product of this and another size2d.
auto dot(size2d const& other) const →  number_type constexpr
Returns dot product of this and another size2d.
auto floor() const →  size2d constexpr
auto height() const →  number_type constexpr
Alias to y member function.
auto height_mut() →  number_type& constexpr
Alias to y_mut member function.
auto inverted() const →  size2d constexpr
Returns inverted size2d.
auto is_finite() const →  bool constexpr
Returns true if all members are finite.
auto is_positive() const →  bool constexpr
Returns true if all members are positive.
auto lerp(size2d const& other, f32 t) const →  size2d constexpr
Linearly interpolate between this size2d and another size2d.
auto max(size2d const& other) const →  size2d constexpr
Returns the largest x and y values of this and another size2d.
auto min(size2d const& other) const →  size2d constexpr
Returns the smallest x and y values of this and another size2d.
auto operator!() const →  bool constexpr
Returns false if underlying values is both not 0.
auto operator!=(size2d const& other) const →  bool constexpr
Inequality comparison.
auto operator*(number_type const& other) const →  size2d constexpr
Multiplies size2d with a scalar.
auto operator*=(number_type const& other) →  size2d& constexpr
Multiplication assignment operator.
auto operator+() const →  size2d constexpr
Returns the unchanged size2d.
auto operator+(size2d const& other) const →  size2d constexpr
Addition operator.
auto operator+=(size2d const& other) →  size2d& constexpr
Addition assignment operator.
auto operator-() const →  size2d constexpr
Returns the negated size2d.
auto operator-(size2d const& other) const →  size2d constexpr
Subtraction operator.
auto operator-=(size2d const& other) →  size2d& constexpr
Subtraction assignment operator.
auto operator/(number_type const& other) const →  size2d constexpr
Divides size2d by a scalar.
auto operator/=(number_type const& other) →  size2d& constexpr
Division assignment operator.
auto operator=(size2d const&) →  size2d& defaulted constexpr
Default copy assignment operator.
auto operator=(size2d&&) →  size2d& defaulted constexpr
Default move assignment operator.
auto operator==(size2d const& other) const →  bool constexpr
Equality comparison.
auto round() const →  size2d constexpr
Rounds each component to the nearest integer value.
auto to_array() const →  std::array<number_type, 2> constexpr
Casts into an array of two values.
auto to_f32() const →  size2d constexpr
Casts into f32 size2d.
auto to_f64() const →  size2d<f64> constexpr
Casts into f64 size2d.
auto to_i32() const →  size2d<i32> constexpr
Casts into i32 size2d.
auto to_i64() const →  size2d<i64> constexpr
Casts into i64 size2d.
auto to_isize() const →  size2d<isize> constexpr
Casts into isize size2d.
auto to_pair() const →  std::pair<number_type, number_type> constexpr
Casts into a pair of two values.
auto to_point2d() const →  point2d<number_type> constexpr
Converts this size2d into point2d.
auto to_string() const →  std::string
Returns string representation of the size2d.
auto to_tuple() const →  std::tuple<number_type, number_type> constexpr
Casts into a tuple of two values.
auto to_u32() const →  size2d<u32> constexpr
Casts into u32 size2d.
auto to_u64() const →  size2d<u64> constexpr
Casts into u64 size2d.
auto to_usize() const →  size2d<usize> constexpr
Casts into usize size2d.
auto to_vector2d() const →  vector2d<number_type> constexpr
Converts this size2d into vector2d.
auto width() const →  number_type constexpr
Alias to x member function.
auto width_mut() →  number_type& constexpr
Alias to x_mut member function.
auto x() const →  number_type constexpr
Returns the x-coordinate of the size2d as scalar value.
auto x_mut() →  number_type& constexpr
Returns mutable reference to the x-coordinate of the size2d as scalar value.
auto y() const →  number_type constexpr
Returns the y-coordinate of the size2d as scalar value.
auto y_mut() →  number_type& constexpr
Returns mutable reference to the y-coordinate of the size2d as scalar value.

Function documentation

template <typename T>
template <std::size_t N2, typename = std::enable_if_t<N2 == 2>>
static size2d rll::size2d::from_array(std::array<number_type, N2> const& other) constexpr

Constructs new size2d from std::array.

Template parameters
N2 The size of the array. Must be equal to 2.
Parameters
other The other std::array.

template <typename T>
static size2d rll::size2d::from_pair(std::pair<number_type, number_type> const& other) constexpr

Constructs new size2d from std::pair.

Parameters
other The other std::pair.

template <typename T>
template <typename... Args, typename = std::enable_if_t<std::tuple_size_v<std::tuple<Args...>> == 2>>
static size2d rll::size2d::from_tuple(std::tuple<Args...> const& other) constexpr

Constructs new size2d from std::tuple.

Parameters
other The other std::tuple.

template <typename T>
static size2d rll::size2d::splat(number_type value) constexpr

Constructs new size2d, setting all components to the same value.

Parameters
value The value to set all components to.

template <typename T>
rll::size2d::operator bool() const explicit constexpr

Returns true if underlying values is both not 0 and not NaN or Infinity in case of floating point.

template <typename T>
rll::size2d::size2d(number_type x, number_type y) constexpr

Constructs new size2d from given scalar values.

Parameters
x The x-coordinate.
y The y-coordinate.

template <typename T>
rll::size2d::size2d(number_type value) explicit constexpr

Constructs new size2d, setting all components to the same value.

Parameters
value The value to set all components to.

template <typename T>
rll::size2d::size2d(point2d<number_type> const& p) explicit constexpr

Constructs new size2d from a point2d.

Parameters
p The point2d to copy.

template <typename T>
rll::size2d::size2d(vector2d<number_type> const& v) explicit constexpr

Constructs new size2d from a vector2d.

Parameters
v The vector2d to copy.

template <typename T>
size2d rll::size2d::abs() const constexpr

Returns the absolute value of each component.

Returns The absolute value of each component.

template <typename T>
number_type rll::size2d::area() const constexpr

Returns result of multiplication of both scalars.

Returns Area of the size2d.

template <typename T>
template <typename U, typename = std::enable_if_t<is_num_v<T>>>
size2d<U> rll::size2d::cast() const constexpr

Cast from one numeric representation to another, preserving the units.

Template parameters
U New number type.
Returns The size2d with the new number type and the same value.

template <typename T>
size2d rll::size2d::ceil() const constexpr

Rounds each component to the smallest integer equal or greater than the original value.

This behavior is preserved for negative values (unlike the basic cast).

template <typename T>
size2d rll::size2d::clamp(size2d const& start, size2d const& end) const constexpr

Returns the size2d each component of which clamped by corresponding components of start and end.

Parameters
start The start size2d.
end The end size2d.
Returns The clamped size2d.

template <typename T>
number_type rll::size2d::cross(size2d const& other) const constexpr

Returns the norm of the cross product of this and another size2d.

Parameters
other The other size2d.
Returns The norm of the cross product of this and another size2d.

Cross product is defined as [x1, y1] x [x2, y2] = x1 * y2 - y1 * x2.

template <typename T>
number_type rll::size2d::dot(size2d const& other) const constexpr

Returns dot product of this and another size2d.

Parameters
other The other size2d.
Returns The dot product of this and another size2d.

Dot product is defined as [x1, y1] . [x2, y2] = x1 * x2 + y1 * y2.

template <typename T>
size2d rll::size2d::inverted() const constexpr

Returns inverted size2d.

Returns Inverted size2d.

template <typename T>
size2d rll::size2d::lerp(size2d const& other, f32 t) const constexpr

Linearly interpolate between this size2d and another size2d.

Parameters
other The other size2d.
t Interpolation factor.
Returns The interpolated size2d.

Example:

using rll::size2d;
auto const from = size2d(0.0F, 10.0F);
auto const to = size2d(8.0F, -4.0F);
fmt::println("{}", from.lerp(to, -1.0F));
fmt::println("{}", from.lerp(to, 0.0F));
fmt::println("{}", from.lerp(to, 0.5F));
fmt::println("{}", from.lerp(to, 1.0F));
fmt::println("{}", from.lerp(to, 2.0F));

Output:

[-8.0, 24.0]
[0.0, 10.0]
[4.0, 3.0]
[8.0, -4.0]
[16.0, -18.0]

template <typename T>
size2d rll::size2d::max(size2d const& other) const constexpr

Returns the largest x and y values of this and another size2d.

Parameters
other The other size2d.
Returns size2d with the largest x and y values.

template <typename T>
size2d rll::size2d::min(size2d const& other) const constexpr

Returns the smallest x and y values of this and another size2d.

Parameters
other The other size2d.
Returns size2d with the smallest x and y values.

template <typename T>
bool rll::size2d::operator!=(size2d const& other) const constexpr

Inequality comparison.

Parameters
other The other size2d.
Returns true if the size2ds are not equal, false otherwise.

template <typename T>
size2d rll::size2d::operator*(number_type const& other) const constexpr

Multiplies size2d with a scalar.

Parameters
other Scalar value.
Returns The product of the size2d and the scalar.

template <typename T>
size2d& rll::size2d::operator*=(number_type const& other) constexpr

Multiplication assignment operator.

Parameters
other Scalar value.
Returns The result of the multiplication.

template <typename T>
size2d rll::size2d::operator+(size2d const& other) const constexpr

Addition operator.

Parameters
other The other size2d.
Returns The sum of both size2ds.

template <typename T>
size2d& rll::size2d::operator+=(size2d const& other) constexpr

Addition assignment operator.

Parameters
other The other size2d.
Returns The result of the addition.

template <typename T>
size2d rll::size2d::operator-(size2d const& other) const constexpr

Subtraction operator.

Parameters
other The other size2d.
Returns The difference of both size2ds.

template <typename T>
size2d& rll::size2d::operator-=(size2d const& other) constexpr

Subtraction assignment operator.

Parameters
other The other size2d.
Returns The result of the subtraction.

template <typename T>
size2d rll::size2d::operator/(number_type const& other) const constexpr

Divides size2d by a scalar.

Parameters
other Scalar value.
Returns The quotient of the size2d and the scalar.

template <typename T>
size2d& rll::size2d::operator/=(number_type const& other) constexpr

Division assignment operator.

Parameters
other Scalar value.
Returns The result of the division.

template <typename T>
bool rll::size2d::operator==(size2d const& other) const constexpr

Equality comparison.

Parameters
other The other size2d.
Returns true if the size2ds are equal, false otherwise.

template <typename T>
size2d rll::size2d::round() const constexpr

Rounds each component to the nearest integer value.

This behavior is preserved for negative values (unlike the basic cast).

template <typename T>
point2d<number_type> rll::size2d::to_point2d() const constexpr

Converts this size2d into point2d.

Returns The resulting point2d.

template <typename T>
std::string rll::size2d::to_string() const

Returns string representation of the size2d.

Returns String representation of the object.

Size is represented as it's numeric values. If the underlying number type is floating point2d, it is rounded to two decimal places.

template <typename T>
vector2d<number_type> rll::size2d::to_vector2d() const constexpr

Converts this size2d into vector2d.

Returns The resulting vector2d.

template <typename T>
number_type rll::size2d::x() const constexpr

Returns the x-coordinate of the size2d as scalar value.

Returns The x-coordinate of the size2d.

template <typename T>
number_type& rll::size2d::x_mut() constexpr

Returns mutable reference to the x-coordinate of the size2d as scalar value.

Returns Mutable reference to the x-coordinate of the size2d.

template <typename T>
number_type rll::size2d::y() const constexpr

Returns the y-coordinate of the size2d as scalar value.

Returns The y-coordinate of the size2d.

template <typename T>
number_type& rll::size2d::y_mut() constexpr

Returns mutable reference to the y-coordinate of the size2d as scalar value.

Returns Mutable reference to the y-coordinate of the size2d.