16#include <peak_common_c/detail/peak_common_defines.h>
40template <
typename T,
size_t dimension>
44 static_assert(dimension >= 2,
"A Point must consist of at least two coordinates (x,y)!");
45 static_assert(std::is_arithmetic<T>::value,
"A point must be created from an arithmetic type!");
63 constexpr explicit PointXd(std::array<T, dimension> coordinates)
64 : m_coordinates{ coordinates }
74 PEAK_COMMON_NO_DISCARD
constexpr T
GetX()
const
76 return m_coordinates.at(0);
86 PEAK_COMMON_NO_DISCARD
constexpr T
GetY()
const
88 return m_coordinates.at(1);
102 template <
typename H,
106 typename std::enable_if_t<std::is_integral<H>::value,
int> = 0
111 return std::equal(this->m_coordinates.begin(), this->m_coordinates.end(), rhs.
GetCoordinates().begin());
125 template <
typename H,
size_t d>
128 return !(*
this == rhs);
143 template <
typename H,
147 typename std::enable_if_t<std::is_floating_point<H>::value,
int> = 0
152 using common_type = std::common_type_t<T, H>;
155 constexpr uint32_t ulp = 4;
157 return std::equal(this->m_coordinates.begin(), this->m_coordinates.end(), rhs.
GetCoordinates().begin(),
158 [ulp](
const auto& left,
const auto& right) {
159 return detail::AreAlmostEqual<common_type>(static_cast<common_type>(left), static_cast<common_type>(right), ulp);
172 return m_coordinates;
176 std::array<T, dimension> m_coordinates{};
191class PointT :
public PointXd<T, 2>
198 static_assert(std::is_arithmetic<T>::value,
"Template argument of Point must be arithmetic.");
233 return os <<
"{ x: " << point.GetX() <<
", y: " << point.GetY() <<
" }";
245 PEAK_COMMON_NO_DISCARD std::string
ToString()
const
247 std::ostringstream ss;
253 friend detail::BackendAccessor<PointT<T>>;
255 template <
typename U = T,
typename std::enable_if<has_c_type_of<Po
intT<U>>::value,
bool>::type = false>
257 :
PointT(static_cast<T>(point.x), static_cast<T>(point.y))
260 template <
typename U = T,
typename std::enable_if<has_c_type_of<Po
intT<U>>::value,
bool>::type = false>
263 return { this->
GetX(), this->
GetY() };
266 friend detail::BackendAccessor<PointType>;
constexpr PointT()=default
Default constructor for PointT (2D point).
std::string ToString() const
Returns a string representation of the point.
constexpr PointT(T x, T y)
Point constructor from x and y coordinates.
friend std::ostream & operator<<(std::ostream &os, PointT point)
Stream output operator for PointT.
A point in space with configurable dimensionality and coordinate type.
constexpr std::array< T, dimension > GetCoordinates() const
Returns the coordinates of the point as an array.
constexpr PointXd(std::array< T, dimension > coordinates)
Constructs a PointXd from an array of coordinates.
constexpr T GetY() const
Returns the y-coordinate (second component).
constexpr bool operator!=(const PointXd< H, d > &rhs) const
Inequality operator for comparing coordinates.
constexpr T GetX() const
Returns the x-coordinate (first component).
constexpr bool operator==(const PointXd< H, d > &rhs) const
Equality operator for comparing integral coordinates.
constexpr PointXd()=default
Default constructor for PointXd.
typename c_type_of_< Type >::type c_type_of_t