35template <
typename T,
size_t dimension>
39 static_assert(dimension >= 2,
"A Point must consist of at least two coordinates (x,y)!");
40 static_assert(std::is_arithmetic<T>::value,
"A point must be created from an arithmetic type!");
58 constexpr explicit PointXd(std::array<T, dimension> coordinates)
59 : m_coordinates{ coordinates }
69 PEAK_COMMON_NO_DISCARD
constexpr T
GetX()
const
71 return m_coordinates.at(0);
81 PEAK_COMMON_NO_DISCARD
constexpr T
GetY()
const
83 return m_coordinates.at(1);
101 typename std::enable_if_t<std::is_integral<H>::value,
int> = 0
106 return std::equal(this->m_coordinates.begin(), this->m_coordinates.end(), rhs.
GetCoordinates().begin());
120 template <
typename H,
size_t d>
123 return !(*
this == rhs);
138 template <
typename H,
142 typename std::enable_if_t<std::is_floating_point<H>::value,
int> = 0
147 using common_type = std::common_type_t<T, H>;
150 constexpr uint32_t ulp = 4;
152 return std::equal(this->m_coordinates.begin(), this->m_coordinates.end(), rhs.
GetCoordinates().begin(),
153 [ulp](
const auto& left,
const auto& right) {
154 return detail::AreAlmostEqual<common_type>(static_cast<common_type>(left), static_cast<common_type>(right), ulp);
167 return m_coordinates;
171 std::array<T, dimension> m_coordinates{};
193 static_assert(std::is_arithmetic<T>::value,
"Template argument of Point must be arithmetic.");
228 return os <<
"{ x: " << point.
GetX() <<
", y: " << point.
GetY() <<
" }";
240 PEAK_COMMON_NO_DISCARD std::string
ToString()
const
242 std::ostringstream ss;
248 friend detail::BackendAccessor<PointT<T>>;
250 template <
typename U = T,
typename std::enable_if<has_c_type_of<Po
intT<U>>::value,
bool>::type = false>
251 constexpr explicit PointT(peak::common::detail::c_type_of_t<
PointT<U>> point)
252 :
PointT(static_cast<T>(point.x), static_cast<T>(point.y))
255 template <
typename U = T,
typename std::enable_if<has_c_type_of<Po
intT<U>>::value,
bool>::type = false>
256 constexpr explicit operator peak::common::detail::c_type_of_t<PointT<U>>()
const
258 return { this->
GetX(), this->
GetY() };
261 friend detail::BackendAccessor<PointType>;
2D point template type.
Definition peak_common_point.hpp:187
constexpr PointT()=default
Default constructor for PointT (2D point).
std::string ToString() const
Returns a string representation of the point.
Definition peak_common_point.hpp:240
constexpr PointT(T x, T y)
Point constructor from x and y coordinates.
Definition peak_common_point.hpp:211
friend std::ostream & operator<<(std::ostream &os, PointT point)
Stream output operator for PointT.
Definition peak_common_point.hpp:226
constexpr std::array< T, dimension > GetCoordinates() const
Returns the coordinates of the point as an array.
Definition peak_common_point.hpp:165
constexpr PointXd(std::array< T, dimension > coordinates)
Constructs a PointXd from an array of coordinates.
Definition peak_common_point.hpp:58
constexpr T GetY() const
Returns the y-coordinate (second component).
Definition peak_common_point.hpp:81
constexpr bool operator!=(const PointXd< H, d > &rhs) const
Inequality operator for comparing coordinates.
Definition peak_common_point.hpp:121
constexpr T GetX() const
Returns the x-coordinate (first component).
Definition peak_common_point.hpp:69
constexpr bool operator==(const PointXd< H, d > &rhs) const
Equality operator for comparing integral coordinates.
Definition peak_common_point.hpp:104
constexpr PointXd()=default
Default constructor for PointXd.
detail::PointT< float > PointF
2D point with single-precision floating-point coordinates.
Definition peak_common_point.hpp:292
detail::PointT< int32_t > Point
2D point with 32-bit signed integer coordinates.
Definition peak_common_point.hpp:278
detail::PointT< uint32_t > PointU
2D point with 32-bit unsigned integer coordinates.
Definition peak_common_point.hpp:306
Namespace for internal implementation details and low-level types.
Definition peak_common_math.hpp:19
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17