template <typename T = f32>
rll::point2d class

A two-dimensional point tagged with a unit.

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

Public types

using number_type = T
Underlying number type.
using size2d_type = size2d<number_type>
Associated size2d type.
using vector2d_type = vector2d<number_type>
Associated vector 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) →  point2d constexpr
Constructs new point2d from std::array.
static auto from_pair(std::pair<number_type, number_type> const& other) →  point2d constexpr
Constructs new point2d from std::pair.
static auto from_size2d(size2d_type const& other) →  point2d constexpr
Constructs new point from size2d.
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) →  point2d constexpr
Constructs new point2d from std::tuple.
static auto origin() →  point2d constexpr
Constructs new point with zero coordinates.
static auto splat(number_type value) →  point2d constexpr
Constructs new point2d, setting all components to the same value.
static auto zero() →  point2d 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.
point2d() constexpr
Constructs new point with zero coordinates.
point2d(number_type x, number_type y) constexpr
Constructs new point from given scalar values.
point2d(number_type value) explicit constexpr
Constructs new point, setting all components to the same value.
point2d(size2d_type const& other) explicit constexpr
Constructs new point from size2d.
point2d(vector2d<number_type> const& v) explicit constexpr
Constructs new point from a vector2d.

Public functions

auto abs() const →  point2d constexpr
Returns the absolute value of each component.
auto ceil() const →  point2d constexpr
Rounds each component to the smallest integer equal or greater than the original value.
auto clamp(point2d const& start, point2d const& end) const →  point2d constexpr
Returns the point2d each component of which clamped by corresponding components of start and end.
auto cross(point2d const& other) const →  number_type constexpr
Returns the norm of the cross product of this and another point2d.
template <typename Q>
auto div_euclid(Q const& other) const →  point2d constexpr
Calculates Euclidean division, the matching method for rem_euclid.
auto dot(point2d const& other) const →  number_type constexpr
Returns dot product of this and another point2d.
auto floor() const →  point2d constexpr
Rounds each component to the largest integer equal or less than the original value.
auto inverted() const →  point2d constexpr
Returns inverted point2d.
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(point2d const& other, f32 t) const →  point2d constexpr
Linearly interpolate between this point2d and another point2d.
template <typename F, typename = std::enable_if_t<std::is_invocable_v<F, number_type>>>
auto map(F&& fn) const →  auto constexpr
Applies the function fn to each component of the point.
auto max(point2d const& other) const →  point2d constexpr
Returns the largest x and y values of this and another point2d.
auto min(point2d const& other) const →  point2d constexpr
Returns the smallest x and y values of this and another point2d.
auto operator!() const →  bool constexpr
Returns false if underlying values is both not 0.
auto operator!=(point2d const& other) const →  bool constexpr
Checks if two points are not equal.
auto operator*(number_type const& other) const →  point2d constexpr
Multiplies point with scalar.
auto operator*=(number_type const& other) →  point2d& constexpr
Multiplies point with scalar.
auto operator+() const →  point2d constexpr
Returns the unchanged point.
template <typename Q>
auto operator+(Q const& other) const →  point2d constexpr
Sums point and either point2d, size2d or vector2d.
template <typename Q>
auto operator+=(Q const& other) →  point2d& constexpr
Adds point and either point2d, size2d or vector2d.
auto operator-() const →  point2d constexpr
Returns the negated point.
template <typename Q>
auto operator-(Q const& other) const →  point2d constexpr
Subtracts point and either point2d, size2d or vector2d.
template <typename Q>
auto operator-=(Q const& other) →  point2d& constexpr
Subtracts point and either point2d, size2d or vector2d.
auto operator/(number_type const& other) const →  point2d constexpr
Divides point with scalar.
auto operator/=(number_type const& other) →  point2d& constexpr
Divides point with scalar.
auto operator==(point2d const& other) const →  bool constexpr
Checks if two points are equal.
template <typename Q>
auto rem_euclid(Q const& other) const →  point2d constexpr
Calculates the least nonnegative remainder of self (mod other).
auto round() const →  point2d 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 →  point2d constexpr
Casts into f32 point2d.
auto to_f64() const →  point2d<f64> constexpr
Casts into f64 point2d.
auto to_i32() const →  point2d<i32> constexpr
Casts into i32 point2d.
auto to_i64() const →  point2d<i64> constexpr
Casts into i64 point2d.
auto to_isize() const →  point2d<isize> constexpr
Casts into isize point2d.
auto to_pair() const →  std::pair<number_type, number_type> constexpr
Casts into a pair of two values.
auto to_size2d() const →  size2d_type constexpr
Converts this point2d into size2d.
auto to_string() const →  std::string
Returns string representation of the point2d.
auto to_tuple() const →  std::tuple<number_type, number_type> constexpr
Casts into a tuple of two values.
auto to_u32() const →  point2d<u32> constexpr
Casts into u32 point2d.
auto to_u64() const →  point2d<u64> constexpr
Casts into u64 point2d.
auto to_usize() const →  point2d<usize> constexpr
Casts into usize point2d.
auto to_vector2d() const →  vector2d<number_type> constexpr
Converts this point2d into vector2d.
auto x() const →  number_type constexpr
Returns the x-coordinate of the point2d as scalar value.
auto x_mut() →  number_type& constexpr
Returns mutable reference to the x-coordinate of the point2d as scalar value.
auto y() const →  number_type constexpr
Returns the y-coordinate of the point2d as scalar value.
auto y_mut() →  number_type& constexpr
Returns mutable reference to the y-coordinate of the point2d as scalar value.
template <typename F, typename = std::enable_if_t<std::is_invocable_v<F, number_type, number_type>>>
auto zip(point2d const& other, F&& fn) const →  auto constexpr
Applies the function fn to each component of this point and the other point.

Function documentation

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

Constructs new point2d from std::array.

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

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

Constructs new point2d from std::pair.

Parameters
other The other std::pair.

template <typename T>
static point2d rll::point2d::from_size2d(size2d_type const& other) constexpr

Constructs new point from size2d.

Parameters
other The other size2d.

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

Constructs new point2d from std::tuple.

Parameters
other The other std::tuple.

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

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

Parameters
value The value to set all components to.

template <typename T>
rll::point2d::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::point2d::point2d(number_type x, number_type y) constexpr

Constructs new point from given scalar values.

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

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

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

Parameters
value The value to set all components to.

template <typename T>
rll::point2d::point2d(size2d_type const& other) explicit constexpr

Constructs new point from size2d.

Parameters
other The other size2d.

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

Constructs new point from a vector2d.

Parameters
v The vector2d to copy.

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

Returns the absolute value of each component.

Returns The absolute value of each component.

template <typename T>
point2d rll::point2d::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>
point2d rll::point2d::clamp(point2d const& start, point2d const& end) const constexpr

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

Parameters
start The start point2d.
end The end point2d.
Returns The clamped point2d.

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

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

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

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

template <typename T>
template <typename Q>
point2d rll::point2d::div_euclid(Q const& other) const constexpr

Calculates Euclidean division, the matching method for rem_euclid.

Template parameters
Q The type of the divisor. Can be point2d or size2d.
Parameters
other The divisor.
Returns The quotient.

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

Returns dot product of this and another point2d.

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

template <typename T>
point2d rll::point2d::floor() const constexpr

Rounds each component to the largest integer equal or less than the original value.

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

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

Returns inverted point2d.

Returns Inverted point2d.

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

Linearly interpolate between this point2d and another point2d.

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

Example:

using rll::point2d;
auto const from = point2d(0.0F, 10.0F);
auto const to = point2d(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>
template <typename F, typename = std::enable_if_t<std::is_invocable_v<F, number_type>>>
auto rll::point2d::map(F&& fn) const constexpr

Applies the function fn to each component of the point.

Template parameters
F The type of function to apply.
Parameters
fn The function to apply.

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

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

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

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

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

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

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

Checks if two points are not equal.

Parameters
other The other point.

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

Multiplies point with scalar.

Parameters
other The scalar.
Returns The product.

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

Multiplies point with scalar.

Parameters
other The scalar.
Returns The product.

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

Sums point and either point2d, size2d or vector2d.

Template parameters
Q The type of the summand. Can be point2d, vector2d or size2d.
Parameters
other The summand.
Returns The sum.

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

Adds point and either point2d, size2d or vector2d.

Template parameters
Q The type of the summand. Can be point2d, vector2d or size2d.
Parameters
other The summand.
Returns The sum.

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

Subtracts point and either point2d, size2d or vector2d.

Template parameters
Q The type of the subtrahend. Can be point2d, vector2d or size2d.
Parameters
other The subtrahend.
Returns The difference.

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

Subtracts point and either point2d, size2d or vector2d.

Template parameters
Q The type of the subtrahend. Can be point2d, vector2d or size2d.
Parameters
other The subtrahend.
Returns The difference.

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

Divides point with scalar.

Parameters
other The scalar.
Returns The quotient.

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

Divides point with scalar.

Parameters
other The scalar.
Returns The quotient.

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

Checks if two points are equal.

Parameters
other The other point.

template <typename T>
template <typename Q>
point2d rll::point2d::rem_euclid(Q const& other) const constexpr

Calculates the least nonnegative remainder of self (mod other).

Template parameters
Q The type of the divisor. Can be point2d or size2d.
Parameters
other The divisor.
Returns The remainder.

template <typename T>
point2d rll::point2d::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>
size2d_type rll::point2d::to_size2d() const constexpr

Converts this point2d into size2d.

Returns The resulting size2d.

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

Returns string representation of the point2d.

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::point2d::to_vector2d() const constexpr

Converts this point2d into vector2d.

Returns The resulting vector2d.

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

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

Returns The x-coordinate of the point2d.

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

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

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

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

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

Returns The y-coordinate of the point2d.

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

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

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

template <typename T>
template <typename F, typename = std::enable_if_t<std::is_invocable_v<F, number_type, number_type>>>
auto rll::point2d::zip(point2d const& other, F&& fn) const constexpr

Applies the function fn to each component of this point and the other point.

Template parameters
F The type of function to apply.
Parameters
other The other point to apply.
fn The function to apply.