15 template <
typename T1,
typename T2>
class Point;
30 template <
typename T1 =
int,
typename T2 = T1>
class Point {
37 template <
typename,
typename>
friend class Point;
50 constexpr Point() : _xcoord{}, _ycoord{} {}
66 : _xcoord{std::move(
xcoord)}, _ycoord{std::move(
ycoord)} {}
72 constexpr auto xcoord() const -> const T1& {
return this->_xcoord; }
78 constexpr auto ycoord() const -> const T2& {
return this->_ycoord; }
97 template <
typename U1,
typename U2>
99 return std::tie(this->
xcoord(), this->
ycoord()) == std::tie(rhs.xcoord(), rhs.ycoord());
113 template <
typename U1,
typename U2>
115 return std::tie(this->
xcoord(), this->
ycoord()) < std::tie(rhs.xcoord(), rhs.ycoord());
130 template <
typename U1,
typename U2>
132 return !(*
this == rhs);
152 template <
typename U1,
typename U2>
154 this->_xcoord += right_point.x();
155 this->_ycoord += right_point.y();
169 template <
typename U1,
typename U2>
186 template <
typename U1,
typename U2>
188 this->_xcoord -= right_point.x();
189 this->_ycoord -= right_point.y();
203 template <
typename U1,
typename U2>
216 constexpr auto operator-(
const Self& other_point)
const {
254 template <
typename U1,
typename U2>
268 template <
typename U1,
typename U2>
283 template <
typename U1,
typename U2>
298 template <
typename U1,
typename U2>
312 template <
typename U1,
typename U2>
315 &&
contain(other_point.ycoord(), this->ycoord()))
317 &&
contain(other_point.xcoord(), this->xcoord()));
328 template <
typename U1,
typename U2>
342 template <
typename U1,
typename U2>
354 template <
typename T>
constexpr auto enlarge_with(
const T& value)
const {
357 return Point<
decltype(xb),
decltype(yb)>{std::move(xb), std::move(yb)};
366 template <
typename U1,
typename U2>
379 if constexpr (std::is_same_v<T1, Point>) {
381 auto pt2 =
Point(pt.ycoord(), _ycoord).rotates();
382 auto pt3 =
Point(pt.xcoord(), pt2.ycoord()).rotates();
383 return Point(
Point(pt3.xcoord(), pt2.xcoord()), pt3.ycoord());
385 auto xcoord = _xcoord - _ycoord;
386 auto ycoord = _xcoord + _ycoord;
397 if constexpr (std::is_same_v<T1, Point>) {
399 auto pt2 =
Point(_xcoord.ycoord(), pt.ycoord()).inv_rotates();
400 auto pt3 =
Point(pt.xcoord(), pt2.xcoord()).inv_rotates();
401 return Point(
Point(pt3.xcoord(), pt3.ycoord()), pt2.ycoord());
403 auto xcoord = (_xcoord + _ycoord) / 2;
404 auto ycoord = (-_xcoord + _ycoord) / 2;
449 template <
class Stream>
friend auto operator<<(Stream& output_stream,
const Point& obj)
451 output_stream <<
"(" << obj.xcoord() <<
", " << obj.ycoord() <<
")";
452 return output_stream;
468 constexpr auto get_xcoord() const -> const T1& {
return this->_xcoord; }
482 constexpr auto get_ycoord() const -> const T2& {
return this->_ycoord; }
Point.
Definition point.hpp:30
CONSTEXPR14 auto operator-=(const Vector2< U1, U2 > &right_point) -> Self &
Subtracts a vector (translation) from this Point.
Definition point.hpp:187
friend auto operator<<(Stream &output_stream, const Point &obj) -> Stream &
Definition point.hpp:449
constexpr auto intersect_with(const Point< U1, U2 > &other_point) const
Definition point.hpp:269
constexpr auto rotates() const -> Point< T1, T2 >
Rotate the point by 45 degrees (used for ManhattanArc).
Definition point.hpp:378
constexpr Point()
Default constructor.
Definition point.hpp:50
friend constexpr auto operator+(Point lhs, const Vector2< U1, U2 > &vector)
Adds a vector (translation) to this Point.
Definition point.hpp:170
constexpr auto inv_rotates() const -> Point< T1, T2 >
Inverse rotate the point (used for ManhattanArc).
Definition point.hpp:396
constexpr Point(T1 xcoord, T2 ycoord) noexcept
Construct a new Point object.
Definition point.hpp:65
T1 value_type
Definition point.hpp:44
constexpr auto operator==(const Point< U1, U2 > &rhs) const -> bool
Compares this Point object with another Point object for equality.
Definition point.hpp:98
constexpr auto xcoord() const -> const T1 &
Gets the x coordinate of this Point.
Definition point.hpp:72
constexpr auto blocks(const Point< U1, U2 > &other_point) const -> bool
Definition point.hpp:313
constexpr auto get_center() const
Calculate the center of the point.
Definition point.hpp:414
constexpr auto min_dist_with(const Point< U1, U2 > &other_point) const
minimum distance between this point and another point
Definition point.hpp:329
constexpr auto operator-(const Self &other_point) const
Calculates the displacement vector between this point and another point.
Definition point.hpp:216
friend constexpr auto operator-(Point lhs, const Vector2< U1, U2 > &vector)
Definition point.hpp:204
CONSTEXPR14 auto operator+=(const Vector2< U1, U2 > &right_point) -> Self &
Adds a vector (translation) to this Point.
Definition point.hpp:153
constexpr auto hull_with(const Point< U1, U2 > &other_point) const
Definition point.hpp:284
CONSTEXPR14 auto get_xcoord() -> T1 &
Returns a mutable reference to the x-coordinate of the point.
Definition point.hpp:461
constexpr auto nearest_to(const Point< U1, U2 > &other_point) const
Definition point.hpp:367
constexpr auto operator<(const Point< U1, U2 > &rhs) const -> bool
Compares this Point object with another Point object to check if it is less than.
Definition point.hpp:114
constexpr auto get_xcoord() const -> const T1 &
Returns a const reference to the x-coordinate of the point.
Definition point.hpp:468
constexpr auto measure() const
measure (area, volume etc.)
Definition point.hpp:228
constexpr auto lower_corner() const
Calculate the lower corner of the point.
Definition point.hpp:425
constexpr auto min_dist_change_with(Point< U1, U2 > &other_point)
minimum distance between this point and another point
Definition point.hpp:343
constexpr auto contains(const Point< U1, U2 > &other_point) const -> bool
Definition point.hpp:299
constexpr auto flip_xy() const -> Point< T2, T1 >
flip_xy according to xcoord-ycoord diagonal line
Definition point.hpp:237
constexpr auto get_ycoord() const -> const T2 &
Returns a const reference to the y-coordinate of the point.
Definition point.hpp:482
constexpr auto operator!=(const Point< U1, U2 > &rhs) const -> bool
Compares this Point object with another Point object for inequality.
Definition point.hpp:131
constexpr auto upper_corner() const
Calculate the upper corner of the point.
Definition point.hpp:436
constexpr auto ycoord() const -> const T2 &
Gets the y coordinate of this Point.
Definition point.hpp:78
constexpr auto overlaps(const Point< U1, U2 > &other_point) const -> bool
Definition point.hpp:255
constexpr auto enlarge_with(const T &value) const
Enlarge the point by value
Definition point.hpp:354
constexpr auto flip_y() const -> Point< T1, T2 >
flip according to ycoord-axis
Definition point.hpp:244
CONSTEXPR14 auto get_ycoord() -> T2 &
Returns a mutable reference to the y-coordinate of the point.
Definition point.hpp:475
2D vector template class.
Definition vector2.hpp:28
constexpr auto x() const noexcept -> const T1 &
Returns a const reference to the x-coordinate of the vector.
Definition vector2.hpp:72
constexpr auto y() const noexcept -> const T2 &
Returns a const reference to the y-coordinate of the vector.
Definition vector2.hpp:81
Generic free functions for geometric operations (overlap, intersection, hull, distance).
Definition svg_utils.hpp:12
constexpr auto contain(const U1 &lhs, const U2 &rhs) -> bool
Check if one object contains another object.
Definition generic.hpp:90
constexpr auto nearest(const U1 &lhs, const U2 &rhs)
Returns the nearest point on lhs to rhs.
Definition generic.hpp:227
constexpr auto hull(const U1 &left, const U2 &right)
Computes the hull of two objects.
Definition interval.hpp:554
constexpr auto enlarge(const U1 &left, const U2 &right)
Enlarges an interval or scalar value by adding and subtracting a given value.
Definition interval.hpp:579
constexpr auto intersection(const U1 &lhs, const U2 &rhs)
Computes the intersection of two objects.
Definition generic.hpp:128
constexpr auto min_dist_change(U1 &lhs, U2 &rhs)
Calculates the minimum distance between two objects lhs and rhs, with the ability to handle a change ...
Definition generic.hpp:195
constexpr auto min_dist(const U1 &lhs, const U2 &rhs)
Calculates the minimum distance between two objects lhs and rhs.
Definition generic.hpp:166
constexpr auto lower(const U &obj)
Calculates the lower corner of an object.
Definition generic.hpp:281
constexpr auto overlap(const U1 &lhs, const U2 &rhs) -> bool
Checks if two objects overlap.
Definition generic.hpp:54
constexpr auto measure_of(const U &obj)
Calculates the measure (length, area, etc.) of an object.
Definition generic.hpp:245
constexpr auto upper(const U &obj)
Calculates the upper corner of an object.
Definition generic.hpp:299
constexpr auto center(const U &obj)
Calculates the center of an object.
Definition generic.hpp:263
2D vector template class with arithmetic and comparison operations.
#define CONSTEXPR14
Definition vector2.hpp:13