code format
This commit is contained in:
@@ -4,19 +4,19 @@
|
||||
//! \~english Two-dimensional point class
|
||||
//! \~russian Класс двумерной точки
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Two-dimensional point class
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
PIP - Platform Independent Primitives
|
||||
Two-dimensional point class
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PIPOINT_H
|
||||
#define PIPOINT_H
|
||||
@@ -28,22 +28,23 @@
|
||||
//! \~english Two-dimensional point class
|
||||
//! \~russian Класс двумерной точки
|
||||
//! \details
|
||||
//! Данный класс позволяет хранить и работать с двумерными точками.
|
||||
//! Данный класс позволяет хранить и работать с двумерными точками.
|
||||
//! Для работы с объектами реализованы операторы сложения, вычитания и проверки на ревенство и неравенство.
|
||||
//! Также доступны методы для перемещения точек \a translate(), \a translated(), \a move(), \a moved()
|
||||
//! Также доступны методы для перемещения точек \a translate(), \a translated(), \a move(), \a moved()
|
||||
//! и перевода из декартовой системы координат в полярную \a toPolar() и обратно \a fromPolar().
|
||||
template<typename Type>
|
||||
class PIP_EXPORT PIPoint {
|
||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||
|
||||
public:
|
||||
Type x;
|
||||
Type y;
|
||||
|
||||
//! \~russian Создает новую точку.
|
||||
PIPoint() {x = y = Type();}
|
||||
PIPoint() { x = y = Type(); }
|
||||
|
||||
//! \~russian Создает новую точку с заданными координатами.
|
||||
PIPoint(Type x_, Type y_) {set(x_, y_);}
|
||||
PIPoint(Type x_, Type y_) { set(x_, y_); }
|
||||
|
||||
//! \~russian Задать новые координаты точке.
|
||||
PIPoint<Type> & set(Type x_, Type y_) {
|
||||
@@ -89,11 +90,11 @@ public:
|
||||
|
||||
//! \~russian Переместить точку.
|
||||
//! \details Является копией метода \a translate().
|
||||
PIPoint<Type> & move(Type x_, Type y_) {return translate(x_, y_);}
|
||||
PIPoint<Type> & move(Type x_, Type y_) { return translate(x_, y_); }
|
||||
|
||||
//! \~russian Переместить точку.
|
||||
//! \details Является копией метода \a translate().
|
||||
PIPoint<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
||||
PIPoint<Type> & move(const PIPoint<Type> & p) { return translate(p); }
|
||||
|
||||
//! \~russian Создать копию точки и переместить её.
|
||||
//! \details Является копией метода \a translated().
|
||||
@@ -112,47 +113,47 @@ public:
|
||||
}
|
||||
|
||||
//! \~russian Посчитать угол(радианы) в поолярной системе координат.
|
||||
double angleRad() const {return atan2(y, x);}
|
||||
double angleRad() const { return atan2(y, x); }
|
||||
|
||||
//! \~russian Посчитать угол(градусы) в поолярной системе координат.
|
||||
double angleDeg() const {return toDeg(atan2(y, x));}
|
||||
double angleDeg() const { return toDeg(atan2(y, x)); }
|
||||
|
||||
//! \~russian Перевести копию точки в полярную систему координат.
|
||||
PIPoint<Type> toPolar(bool isDeg = false) const {return PIPoint<Type>(sqrt(x*x + y*y), isDeg ? angleDeg() : angleRad());}
|
||||
PIPoint<Type> toPolar(bool isDeg = false) const { return PIPoint<Type>(sqrt(x * x + y * y), isDeg ? angleDeg() : angleRad()); }
|
||||
|
||||
//! \~russian Перевести копию точки из полярной системы координат в декартовую.
|
||||
static PIPoint<Type> fromPolar(const PIPoint<Type> & p) {return PIPoint<Type>(p.y * cos(p.x), p.y * sin(p.x));}
|
||||
static PIPoint<Type> fromPolar(const PIPoint<Type> & p) { return PIPoint<Type>(p.y * cos(p.x), p.y * sin(p.x)); }
|
||||
|
||||
//! \~russian
|
||||
//! \~russian
|
||||
//! Прибавить координаты второй точки и сохранить.
|
||||
//! \details Является копией метода \a translate().
|
||||
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
||||
void operator+=(const PIPoint<Type> & p) { translate(p); }
|
||||
|
||||
//! \~russian Сложить координаты двух точек.
|
||||
PIPoint<Type> operator +(const PIPoint<Type> & p) {return PIPoint<Type>(x + p.x, y + p.y);}
|
||||
PIPoint<Type> operator+(const PIPoint<Type> & p) { return PIPoint<Type>(x + p.x, y + p.y); }
|
||||
|
||||
//! \~russian Прибавить к координатам одинаковое значение.
|
||||
PIPoint<Type> operator +(const Type & p) {return PIPoint<Type>(x + p, y + p);}
|
||||
PIPoint<Type> operator+(const Type & p) { return PIPoint<Type>(x + p, y + p); }
|
||||
|
||||
//! \~russian Вычесть из координат координаты второй точки - найти смещение.
|
||||
PIPoint<Type> operator -(const PIPoint<Type> & p) {return PIPoint<Type>(x - p.x, y - p.y);}
|
||||
PIPoint<Type> operator-(const PIPoint<Type> & p) { return PIPoint<Type>(x - p.x, y - p.y); }
|
||||
|
||||
//! \~russian Вычесть из координат одинаковое значение.
|
||||
PIPoint<Type> operator -(const Type & p) {return PIPoint<Type>(x - p, y - p);}
|
||||
PIPoint<Type> operator-(const Type & p) { return PIPoint<Type>(x - p, y - p); }
|
||||
|
||||
//! \~russian Инвертировать координаты точки.
|
||||
PIPoint<Type> operator -() {return PIPoint<Type>(-x, -y);}
|
||||
PIPoint<Type> operator-() { return PIPoint<Type>(-x, -y); }
|
||||
|
||||
//! \~russian Проверить равенство координат двух точек.
|
||||
bool operator ==(const PIPoint<Type> & p) const {return (x == p.x && y == p.y);}
|
||||
bool operator==(const PIPoint<Type> & p) const { return (x == p.x && y == p.y); }
|
||||
|
||||
//! \~russian Проверить неравенство координат двух точек.
|
||||
bool operator !=(const PIPoint<Type> & p) const {return (x != p.x || y != p.y);}
|
||||
bool operator!=(const PIPoint<Type> & p) const { return (x != p.x || y != p.y); }
|
||||
};
|
||||
|
||||
//! \~russian Перегруженный оператор для вывода координат в \a PICout.
|
||||
template<typename Type>
|
||||
PICout operator <<(PICout & s, const PIPoint<Type> & v) {
|
||||
PICout operator<<(PICout & s, const PIPoint<Type> & v) {
|
||||
s.saveAndSetControls(0);
|
||||
s << "Point{" << v.x << ", " << v.y << "}";
|
||||
s.restoreControls();
|
||||
|
||||
Reference in New Issue
Block a user