From 22b47799dca667341c2a49286771b7f27367248d Mon Sep 17 00:00:00 2001 From: peri4 Date: Sat, 28 Mar 2026 22:23:41 +0300 Subject: [PATCH] PIPoint: const fixes, add some methods --- CMakeLists.txt | 2 +- libs/main/math/pipoint.h | 47 ++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 754101b4..3c04ec22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(PIP) set(PIP_MAJOR 5) set(PIP_MINOR 7) set(PIP_REVISION 0) -set(PIP_SUFFIX _alpha) +set(PIP_SUFFIX _beta) set(PIP_COMPANY SHS) set(PIP_DOMAIN org.SHS) diff --git a/libs/main/math/pipoint.h b/libs/main/math/pipoint.h index ef9eef14..20e88e8e 100644 --- a/libs/main/math/pipoint.h +++ b/libs/main/math/pipoint.h @@ -132,6 +132,10 @@ public: //! \~russian Возвращает полярный угол в градусах. double angleDeg() const { return toDeg(atan2(y, x)); } + //! \~english Returns |x| + |y|. + //! \~russian Возвращает |x| + |y|. + Type manhattanLength() const { return piAbs(x) + piAbs(y); } + //! \~english Returns polar form with radius in \a x and angle in \a y. //! \~russian Возвращает полярную форму, где радиус хранится в \a x, а угол в \a y. PIPoint toPolar(bool isDeg = false) const { return PIPoint(sqrt(x * x + y * y), isDeg ? angleDeg() : angleRad()); } @@ -165,31 +169,31 @@ public: //! \~english Returns sum of two points. //! \~russian Возвращает сумму двух точек. - PIPoint operator+(const PIPoint & p) { return PIPoint(x + p.x, y + p.y); } + PIPoint operator+(const PIPoint & p) const { return PIPoint(x + p.x, y + p.y); } //! \~english Returns point with `p` added to both coordinates. //! \~russian Возвращает точку с добавлением `p` к обеим координатам. - PIPoint operator+(const Type & p) { return PIPoint(x + p, y + p); } + PIPoint operator+(const Type & p) const { return PIPoint(x + p, y + p); } //! \~english Returns difference between two points. //! \~russian Возвращает разность двух точек. - PIPoint operator-(const PIPoint & p) { return PIPoint(x - p.x, y - p.y); } + PIPoint operator-(const PIPoint & p) const { return PIPoint(x - p.x, y - p.y); } //! \~english Returns point with `p` subtracted from both coordinates. //! \~russian Возвращает точку с вычитанием `p` из обеих координат. - PIPoint operator-(const Type & p) { return PIPoint(x - p, y - p); } + PIPoint operator-(const Type & p) const { return PIPoint(x - p, y - p); } //! \~english Returns point with inverted coordinates. //! \~russian Возвращает точку с инвертированными координатами. - PIPoint operator-() { return PIPoint(-x, -y); } + PIPoint operator-() const { return PIPoint(-x, -y); } //! \~english Returns point scaled by `v`. //! \~russian Возвращает точку, масштабированную на `v`. - PIPoint operator*(Type v) { return PIPoint(x * v, y * v); } + PIPoint operator*(Type v) const { return PIPoint(x * v, y * v); } //! \~english Returns point divided by `v`. //! \~russian Возвращает точку, деленную на `v`. - PIPoint operator/(Type v) { return PIPoint(x / v, y / v); } + PIPoint operator/(Type v) const { return PIPoint(x / v, y / v); } //! \~english Checks whether point coordinates are equal. //! \~russian Проверяет равенство координат точек. @@ -200,6 +204,35 @@ public: bool operator!=(const PIPoint & p) const { return (x != p.x || y != p.y); } }; +template +inline PIPoint operator+(const Type & f, const PIPoint & s) { + return PIPoint(f + s.x, f + s.y); +} + +template +inline PIPoint operator-(const Type & f, const PIPoint & s) { + return PIPoint(f - s.x, f - s.y); +} + +template +inline PIPoint operator*(const Type & f, const PIPoint & s) { + return PIPoint(f * s.x, f * s.y); +} + +template +inline PIPoint operator/(const Type & f, const PIPoint & s) { + return PIPoint(f / s.x, f / s.y); +} + + +//! \~english Returns {|x|, |y|}. +//! \~russian Возвращает {|x|, |y|}. +template +inline constexpr PIPoint piAbs(const PIPoint & v) { + return PIPoint(piAbs(v.x), piAbs(v.y)); +} + + //! \relatesalso PICout //! \~english Writes point coordinates to \a PICout. //! \~russian Выводит координаты точки в \a PICout.