2020-12-25 03:18:36 +01:00
|
|
|
#pragma once
|
2016-04-27 00:27:24 +02:00
|
|
|
|
|
|
|
|
#include <cmath>
|
2021-11-28 08:19:44 +01:00
|
|
|
#include <type_traits>
|
2016-04-27 00:27:24 +02:00
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct size2_base
|
|
|
|
|
{
|
|
|
|
|
T width, height;
|
|
|
|
|
|
|
|
|
|
constexpr size2_base() : width{}, height{}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base(T width, T height) : width{width}, height{height}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator-(const size2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width - rhs.width, height - rhs.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator-(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width - rhs, height - rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator+(const size2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width + rhs.width, height + rhs.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator+(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width + rhs, height + rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator/(const size2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width / rhs.width, height / rhs.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator/(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width / rhs, height / rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator*(const size2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width * rhs.width, height * rhs.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr size2_base operator*(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {width * rhs, height * rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator-=(const size2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width -= rhs.width;
|
|
|
|
|
height -= rhs.height;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator-=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width -= rhs;
|
|
|
|
|
height -= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator+=(const size2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width += rhs.width;
|
|
|
|
|
height += rhs.height;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator+=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width += rhs;
|
|
|
|
|
height += rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator/=(const size2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width /= rhs.width;
|
|
|
|
|
height /= rhs.height;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator/=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width /= rhs;
|
|
|
|
|
height /= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator*=(const size2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width *= rhs.width;
|
|
|
|
|
height *= rhs.height;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
size2_base& operator*=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
width *= rhs;
|
|
|
|
|
height *= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const size2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return width == rhs.width && height == rhs.height;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator size2_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(width), static_cast<NT>(height)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct position1_base
|
|
|
|
|
{
|
|
|
|
|
T x;
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base operator-(const position1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs.x};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base operator-(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base operator+(const position1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs.x};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base operator+(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
position1_base operator*(RhsT rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<T>(x * rhs)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base operator*(const position1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<T>(x * rhs.x)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
position1_base operator/(RhsT rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x / rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base operator/(const position1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x / rhs.x};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base& operator-=(const position1_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs.x;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base& operator-=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base& operator+=(const position1_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs.x;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base& operator+=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
position1_base& operator*=(RhsT rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x *= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base& operator*=(const position1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x *= rhs.x;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
position1_base& operator/=(RhsT rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x /= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position1_base& operator/=(const position1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x /= rhs.x;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
bool operator==(const position1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs.x;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
bool operator==(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit operator position1_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double distance(const position1_base& to)
|
|
|
|
|
{
|
|
|
|
|
return abs(x - to.x);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct position2_base
|
|
|
|
|
{
|
|
|
|
|
T x, y;
|
|
|
|
|
|
|
|
|
|
constexpr position2_base() : x{}, y{}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base(T x, T y) : x{x}, y{y}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator>(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x > rhs.x && y > rhs.y;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator>(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x > rhs && y > rhs;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator<(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x < rhs.x && y < rhs.y;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator<(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x < rhs && y < rhs;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator>=(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x >= rhs.x && y >= rhs.y;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator>=(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x >= rhs && y >= rhs;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator<=(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x <= rhs.x && y <= rhs.y;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator<=(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x <= rhs && y <= rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base operator-(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs.x, y - rhs.y};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base operator-(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs, y - rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base operator+(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs.x, y + rhs.y};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base operator+(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs, y + rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
constexpr position2_base operator*(RhsT rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<T>(x * rhs), static_cast<T>(y * rhs)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base operator*(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<T>(x * rhs.x), static_cast<T>(y * rhs.y)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
constexpr position2_base operator/(RhsT rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x / rhs, y / rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base operator/(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x / rhs.x, y / rhs.y};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position2_base operator/(const size2_base<T>& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x / rhs.width, y / rhs.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
position2_base& operator-=(const position2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs.x;
|
|
|
|
|
y -= rhs.y;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position2_base& operator-=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs;
|
|
|
|
|
y -= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position2_base& operator+=(const position2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs.x;
|
|
|
|
|
y += rhs.y;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position2_base& operator+=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs;
|
|
|
|
|
y += rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
position2_base& operator*=(RhsT rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x *= rhs;
|
|
|
|
|
y *= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position2_base& operator*=(const position2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x *= rhs.x;
|
|
|
|
|
y *= rhs.y;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename RhsT>
|
|
|
|
|
position2_base& operator/=(RhsT rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x /= rhs;
|
|
|
|
|
y /= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position2_base& operator/=(const position2_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x /= rhs.x;
|
|
|
|
|
y /= rhs.y;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const position2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs.x && y == rhs.y;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs && y == rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator position2_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double distance(const position2_base& to) const
|
|
|
|
|
{
|
2019-11-30 00:11:28 +01:00
|
|
|
return std::sqrt((x - to.x) * (x - to.x) + (y - to.y) * (y - to.y));
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct position3_base
|
|
|
|
|
{
|
|
|
|
|
T x, y, z;
|
|
|
|
|
/*
|
|
|
|
|
position3_base() : x{}, y{}, z{}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
position3_base(T x, T y, T z) : x{ x }, y{ y }, z{ z }
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base operator-(const position3_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs.x, y - rhs.y, z - rhs.z};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base operator-(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs, y - rhs, z - rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base operator+(const position3_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs.x, y + rhs.y, z + rhs.z};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base operator+(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs, y + rhs, z + rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base& operator-=(const position3_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs.x;
|
|
|
|
|
y -= rhs.y;
|
|
|
|
|
z -= rhs.z;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base& operator-=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs;
|
|
|
|
|
y -= rhs;
|
|
|
|
|
z -= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base& operator+=(const position3_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs.x;
|
|
|
|
|
y += rhs.y;
|
|
|
|
|
z += rhs.z;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position3_base& operator+=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs;
|
|
|
|
|
y += rhs;
|
|
|
|
|
z += rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
bool operator==(const position3_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs.x && y == rhs.y && z == rhs.z;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
bool operator==(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs && y == rhs && z == rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit operator position3_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y), static_cast<NT>(z)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct position4_base
|
|
|
|
|
{
|
|
|
|
|
T x, y, z, w;
|
|
|
|
|
|
|
|
|
|
constexpr position4_base() : x{}, y{}, z{}, w{}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position4_base(T x, T y = {}, T z = {}, T w = {T(1)}) : x{x}, y{y}, z{z}, w{w}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position4_base operator-(const position4_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position4_base operator-(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x - rhs, y - rhs, z - rhs, w - rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position4_base operator+(const position4_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr position4_base operator+(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x + rhs, y + rhs, z + rhs, w + rhs};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
position4_base& operator-=(const position4_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs.x;
|
|
|
|
|
y -= rhs.y;
|
|
|
|
|
z -= rhs.z;
|
|
|
|
|
w -= rhs.w;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position4_base& operator-=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x -= rhs;
|
|
|
|
|
y -= rhs;
|
|
|
|
|
z -= rhs;
|
|
|
|
|
w -= rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position4_base& operator+=(const position4_base& rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs.x;
|
|
|
|
|
y += rhs.y;
|
|
|
|
|
z += rhs.z;
|
|
|
|
|
w += rhs.w;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
position4_base& operator+=(T rhs)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
x += rhs;
|
|
|
|
|
y += rhs;
|
|
|
|
|
z += rhs;
|
|
|
|
|
w += rhs;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const position4_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(T rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x == rhs && y == rhs && z == rhs && w == rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator position4_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y), static_cast<NT>(z), static_cast<NT>(w)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
using position_base = position2_base<T>;
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct coord_base
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
position_base<T> position;
|
2025-04-05 21:50:45 +02:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T x, y;
|
|
|
|
|
};
|
2016-04-27 00:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
size2_base<T> size;
|
2025-04-05 21:50:45 +02:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T width, height;
|
|
|
|
|
};
|
2016-04-27 00:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr coord_base() : position{}, size{}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr coord_base(const position_base<T>& position, const size2_base<T>& size)
|
2025-04-05 21:50:45 +02:00
|
|
|
: position{position}, size{size}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 18:27:48 +02:00
|
|
|
constexpr coord_base(T x, T y, T width, T height)
|
2025-04-05 21:50:45 +02:00
|
|
|
: x{x}, y{y}, width{width}, height{height}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr bool test(const position_base<T>& position) const
|
|
|
|
|
{
|
|
|
|
|
if (position.x < x || position.x >= x + width)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (position.y < y || position.y >= y + height)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const coord_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return position == rhs.position && size == rhs.size;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator coord_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y), static_cast<NT>(width), static_cast<NT>(height)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct area_base
|
|
|
|
|
{
|
|
|
|
|
T x1, x2;
|
|
|
|
|
T y1, y2;
|
|
|
|
|
|
|
|
|
|
constexpr area_base() : x1{}, x2{}, y1{}, y2{}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr area_base(T x1, T y1, T x2, T y2) : x1{x1}, x2{x2}, y1{y1}, y2{y2}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename N>
|
|
|
|
|
constexpr area_base(const coord_base<N>& coord) : x1{T(coord.x)}, x2{T(coord.x + coord.width)}, y1{T(coord.y)}, y2{T(coord.y + coord.height)}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr operator coord_base<T>() const
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1, y1, x2 - x1, y2 - y1};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-16 11:58:15 +01:00
|
|
|
constexpr T width() const
|
|
|
|
|
{
|
|
|
|
|
return (x1 < x2) ? (x2 - x1) : (x1 - x2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr T height() const
|
|
|
|
|
{
|
|
|
|
|
return (y1 < y2) ? (y2 - y1) : (y1 - y2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-27 00:27:24 +02:00
|
|
|
void flip_vertical()
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
T _y = y1;
|
|
|
|
|
y1 = y2;
|
|
|
|
|
y2 = _y;
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void flip_horizontal()
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
T _x = x1;
|
|
|
|
|
x1 = x2;
|
|
|
|
|
x2 = _x;
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr area_base flipped_vertical() const
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1, y2, x2, y1};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr area_base flipped_horizontal() const
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x2, y1, x1, y2};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-16 11:58:15 +01:00
|
|
|
constexpr bool is_flipped() const
|
|
|
|
|
{
|
|
|
|
|
return (x1 > x2 || y1 > y2);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const area_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return x1 == rhs.x1 && x2 == rhs.x2 && y1 == rhs.y1 && y2 == rhs.y2;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr area_base operator-(const size2_base<T>& size) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1 - size.width, y1 - size.height, x2 - size.width, y2 - size.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr area_base operator-(const T& value) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1 - value, y1 - value, x2 - value, y2 - value};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr area_base operator+(const size2_base<T>& size) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1 + size.width, y1 + size.height, x2 + size.width, y2 + size.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr area_base operator+(const T& value) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1 + value, y1 + value, x2 + value, y2 + value};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr area_base operator/(const size2_base<T>& size) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1 / size.width, y1 / size.height, x2 / size.width, y2 / size.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2021-11-28 08:19:44 +01:00
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename U>
|
|
|
|
|
requires(std::is_arithmetic_v<U>)
|
|
|
|
|
constexpr area_base operator/(const U& value) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2021-11-28 08:19:44 +01:00
|
|
|
return area_base{static_cast<T>(x1 / value), static_cast<T>(y1 / value), static_cast<T>(x2 / value), static_cast<T>(y2 / value)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2021-11-28 08:19:44 +01:00
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr area_base operator*(const size2_base<T>& size) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {x1 * size.width, y1 * size.height, x2 * size.width, y2 * size.height};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
2021-11-28 08:19:44 +01:00
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename U>
|
|
|
|
|
requires(std::is_arithmetic_v<U>)
|
|
|
|
|
constexpr area_base operator*(const U& value) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2021-11-28 08:19:44 +01:00
|
|
|
return area_base{static_cast<T>(x1 * value), static_cast<T>(y1 * value), static_cast<T>(x2 * value), static_cast<T>(y2 * value)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator area_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x1), static_cast<NT>(y1), static_cast<NT>(x2), static_cast<NT>(y2)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct size3_base
|
|
|
|
|
{
|
|
|
|
|
T width, height, depth;
|
2022-06-05 17:21:59 +02:00
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2022-06-05 17:21:59 +02:00
|
|
|
explicit constexpr operator size3_base<NT>() const
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(width), static_cast<NT>(height), static_cast<NT>(depth)};
|
2022-06-05 17:21:59 +02:00
|
|
|
}
|
2016-04-27 00:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct coord3_base
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
position3_base<T> position;
|
2025-04-05 21:50:45 +02:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T x, y, z;
|
|
|
|
|
};
|
2016-04-27 00:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
size3_base<T> size;
|
2025-04-05 21:50:45 +02:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T width, height, depth;
|
|
|
|
|
};
|
2016-04-27 00:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr coord3_base() : position{}, size{}
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr coord3_base(const position3_base<T>& position, const size3_base<T>& size) : position{position}, size{size}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr coord3_base(T x, T y, T z, T width, T height, T depth) : x{x}, y{y}, z{z}, width{width}, height{height}, depth{depth}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr bool test(const position3_base<T>& position) const
|
|
|
|
|
{
|
|
|
|
|
if (position.x < x || position.x >= x + width)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (position.y < y || position.y >= y + height)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (position.z < z || position.z >= z + depth)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator coord3_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y), static_cast<NT>(z), static_cast<NT>(width), static_cast<NT>(height), static_cast<NT>(depth)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct color4_base
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T r, g, b, a;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T x, y, z, w;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
T rgba[4];
|
|
|
|
|
T xyzw[4];
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-03 08:04:51 +02:00
|
|
|
constexpr color4_base()
|
2025-04-05 21:50:45 +02:00
|
|
|
: x{T{0}}, y{T{0}}, z{T{0}}, w{T(1)}
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 15:10:15 +01:00
|
|
|
constexpr color4_base(T x, T y, T z, T w)
|
2025-04-05 21:50:45 +02:00
|
|
|
: x(x), y(y), z(z), w(w)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 15:10:15 +01:00
|
|
|
constexpr color4_base(T value)
|
2025-04-05 21:50:45 +02:00
|
|
|
: x(value), y(value), z(value), w(value)
|
2020-01-07 15:10:15 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const color4_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
void operator*=(const color4_base<T>& rhs)
|
2020-01-07 15:10:15 +01:00
|
|
|
{
|
|
|
|
|
r *= rhs.r;
|
|
|
|
|
g *= rhs.g;
|
|
|
|
|
b *= rhs.b;
|
|
|
|
|
a *= rhs.a;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
void operator*=(const T& rhs)
|
2020-01-07 15:10:15 +01:00
|
|
|
{
|
|
|
|
|
r *= rhs;
|
|
|
|
|
g *= rhs;
|
|
|
|
|
b *= rhs;
|
|
|
|
|
a *= rhs;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr color4_base<T> operator*(const color4_base<T>& rhs) const
|
2020-01-07 15:10:15 +01:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {r * rhs.r, g * rhs.g, b * rhs.b, a * rhs.a};
|
2020-01-07 15:10:15 +01:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr color4_base<T> operator*(const T& rhs) const
|
2020-01-07 15:10:15 +01:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {r * rhs, g * rhs, b * rhs, a * rhs};
|
2020-01-07 15:10:15 +01:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr color4_base<T> operator+(const color4_base<T>& rhs) const
|
2020-01-07 15:10:15 +01:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {r + rhs.r, g + rhs.g, b + rhs.b, a + rhs.a};
|
2020-01-07 15:10:15 +01:00
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator color4_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y), static_cast<NT>(z), static_cast<NT>(w)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct color3_base
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T r, g, b;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T x, y, z;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
T rgb[3];
|
|
|
|
|
T xyz[3];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr color3_base(T x = {}, T y = {}, T z = {})
|
2025-04-05 21:50:45 +02:00
|
|
|
: x(x), y(y), z(z)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const color3_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return r == rhs.r && g == rhs.g && b == rhs.b;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator color3_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y), static_cast<NT>(z)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct color2_base
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T r, g;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
T x, y;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
T rg[2];
|
|
|
|
|
T xy[2];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr color2_base(T x = {}, T y = {})
|
2025-04-05 21:50:45 +02:00
|
|
|
: x(x), y(y)
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const color2_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return r == rhs.r && g == rhs.g;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator color2_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x), static_cast<NT>(y)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename T>
|
2016-04-27 00:27:24 +02:00
|
|
|
struct color1_base
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
T r;
|
|
|
|
|
T x;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr color1_base(T x = {})
|
|
|
|
|
: x(x)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
constexpr bool operator==(const color1_base& rhs) const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
|
|
|
|
return r == rhs.r;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
template <typename NT>
|
2020-02-10 15:27:57 +01:00
|
|
|
explicit constexpr operator color1_base<NT>() const
|
2016-04-27 00:27:24 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
return {static_cast<NT>(x)};
|
2016-04-27 00:27:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
// specializations
|
2018-06-10 18:31:40 +02:00
|
|
|
using positionu = position_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using positioni = position_base<int>;
|
|
|
|
|
using positionf = position_base<float>;
|
|
|
|
|
using positiond = position_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using coordu = coord_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using coordi = coord_base<int>;
|
|
|
|
|
using coordf = coord_base<float>;
|
|
|
|
|
using coordd = coord_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using areau = area_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using areai = area_base<int>;
|
|
|
|
|
using areaf = area_base<float>;
|
|
|
|
|
using aread = area_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using position1u = position1_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using position1i = position1_base<int>;
|
|
|
|
|
using position1f = position1_base<float>;
|
|
|
|
|
using position1d = position1_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using position2u = position2_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using position2i = position2_base<int>;
|
|
|
|
|
using position2f = position2_base<float>;
|
|
|
|
|
using position2d = position2_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using position3u = position3_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using position3i = position3_base<int>;
|
|
|
|
|
using position3f = position3_base<float>;
|
|
|
|
|
using position3d = position3_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using position4u = position4_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using position4i = position4_base<int>;
|
|
|
|
|
using position4f = position4_base<float>;
|
|
|
|
|
using position4d = position4_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using size2u = size2_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using size2i = size2_base<int>;
|
|
|
|
|
using size2f = size2_base<float>;
|
|
|
|
|
using size2d = size2_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using sizeu = size2u;
|
2016-04-27 00:27:24 +02:00
|
|
|
using sizei = size2i;
|
|
|
|
|
using sizef = size2f;
|
|
|
|
|
using sized = size2d;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using size3u = size3_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using size3i = size3_base<int>;
|
|
|
|
|
using size3f = size3_base<float>;
|
|
|
|
|
using size3d = size3_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using coord3u = coord3_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using coord3i = coord3_base<int>;
|
|
|
|
|
using coord3f = coord3_base<float>;
|
|
|
|
|
using coord3d = coord3_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using color4u = color4_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using color4i = color4_base<int>;
|
|
|
|
|
using color4f = color4_base<float>;
|
|
|
|
|
using color4d = color4_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using color3u = color3_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using color3i = color3_base<int>;
|
|
|
|
|
using color3f = color3_base<float>;
|
|
|
|
|
using color3d = color3_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using color2u = color2_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using color2i = color2_base<int>;
|
|
|
|
|
using color2f = color2_base<float>;
|
|
|
|
|
using color2d = color2_base<double>;
|
|
|
|
|
|
2018-06-10 18:31:40 +02:00
|
|
|
using color1u = color1_base<unsigned int>;
|
2016-04-27 00:27:24 +02:00
|
|
|
using color1i = color1_base<int>;
|
|
|
|
|
using color1f = color1_base<float>;
|
|
|
|
|
using color1d = color1_base<double>;
|