merged AI doc, some new pages
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
//! \file pipoint.h
|
||||
//! \ingroup Math
|
||||
//! \brief
|
||||
//! \~english Two-dimensional point class
|
||||
//! \~russian Класс двумерной точки
|
||||
//! \~\file pipoint.h
|
||||
//! \~\ingroup Math
|
||||
//! \~\brief
|
||||
//! \~english The PIPoint class provides a two-dimensional point on the plane.
|
||||
//! \~russian Класс PIPoint представляет точку на плоскости с двумя координатами.
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Two-dimensional point class
|
||||
@@ -24,154 +24,185 @@
|
||||
#include "pimathbase.h"
|
||||
|
||||
|
||||
//! \brief
|
||||
//! \~english Two-dimensional point class
|
||||
//! \~russian Класс двумерной точки
|
||||
//! \details
|
||||
//! Данный класс позволяет хранить и работать с двумерными точками.
|
||||
//! Для работы с объектами реализованы операторы сложения, вычитания и проверки на ревенство и неравенство.
|
||||
//! Также доступны методы для перемещения точек \a translate(), \a translated(), \a move(), \a moved()
|
||||
//! и перевода из декартовой системы координат в полярную \a toPolar() и обратно \a fromPolar().
|
||||
//! \~\ingroup Math
|
||||
//! \~\brief
|
||||
//! \~english Two-dimensional point.
|
||||
//! \~russian Двумерная точка.
|
||||
//! \~\details
|
||||
//! \~english Stores point coordinates and provides basic translation and conversion helpers.
|
||||
//! \~russian Хранит координаты точки и предоставляет базовые методы смещения и преобразования.
|
||||
template<typename Type>
|
||||
class PIP_EXPORT PIPoint {
|
||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||
|
||||
public:
|
||||
//! \~english Horizontal coordinate.
|
||||
//! \~russian Горизонтальная координата.
|
||||
Type x;
|
||||
|
||||
//! \~english Vertical coordinate.
|
||||
//! \~russian Вертикальная координата.
|
||||
Type y;
|
||||
|
||||
//! \~russian Создает новую точку.
|
||||
//! \~english Constructs point at the origin.
|
||||
//! \~russian Создает точку в начале координат.
|
||||
PIPoint() { x = y = Type(); }
|
||||
|
||||
//! \~russian Создает новую точку с заданными координатами.
|
||||
//! \~english Constructs point from coordinates.
|
||||
//! \~russian Создает точку с заданными координатами.
|
||||
PIPoint(Type x_, Type y_) { set(x_, y_); }
|
||||
|
||||
//! \~russian Задать новые координаты точке.
|
||||
//! \~english Sets point coordinates.
|
||||
//! \~russian Задает координаты точки.
|
||||
PIPoint<Type> & set(Type x_, Type y_) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~russian Задать новые координаты точке.
|
||||
//! \~english Copies coordinates from another point.
|
||||
//! \~russian Копирует координаты из другой точки.
|
||||
PIPoint<Type> & set(const PIPoint<Type> & p) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~russian Переместить точку.
|
||||
//! \~english Shifts the point by `x_` and `y_`.
|
||||
//! \~russian Сдвигает точку на `x_` и `y_`.
|
||||
PIPoint<Type> & translate(Type x_, Type y_) {
|
||||
x += x_;
|
||||
y += y_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~russian Переместить точку.
|
||||
//! \~english Shifts the point by another point.
|
||||
//! \~russian Сдвигает точку на координаты другой точки.
|
||||
PIPoint<Type> & translate(const PIPoint<Type> & p) {
|
||||
x += p.x;
|
||||
y += p.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~russian Создать копию точки и переместить её.
|
||||
//! \~english Returns translated copy of the point.
|
||||
//! \~russian Возвращает смещенную копию точки.
|
||||
PIPoint<Type> translated(Type x_, Type y_) const {
|
||||
PIPoint<Type> rp(*this);
|
||||
rp.translate(x_, y_);
|
||||
return rp;
|
||||
}
|
||||
|
||||
//! \~russian Создать копию точки и переместить её.
|
||||
//! \~english Returns copy shifted by another point.
|
||||
//! \~russian Возвращает копию, смещенную на другую точку.
|
||||
PIPoint<Type> translated(const PIPoint<Type> & p) const {
|
||||
PIPoint<Type> rp(*this);
|
||||
rp.translate(p);
|
||||
return rp;
|
||||
}
|
||||
|
||||
//! \~russian Переместить точку.
|
||||
//! \details Является копией метода \a translate().
|
||||
//! \~english Same as \a translate().
|
||||
//! \~russian Синоним \a translate().
|
||||
PIPoint<Type> & move(Type x_, Type y_) { return translate(x_, y_); }
|
||||
|
||||
//! \~russian Переместить точку.
|
||||
//! \details Является копией метода \a translate().
|
||||
//! \~english Same as \a translate().
|
||||
//! \~russian Синоним \a translate().
|
||||
PIPoint<Type> & move(const PIPoint<Type> & p) { return translate(p); }
|
||||
|
||||
//! \~russian Создать копию точки и переместить её.
|
||||
//! \details Является копией метода \a translated().
|
||||
//! \~english Same as \a translated().
|
||||
//! \~russian Синоним \a translated().
|
||||
PIPoint<Type> moved(Type x_, Type y_) const {
|
||||
PIPoint<Type> rp(*this);
|
||||
rp.translate(x_, y_);
|
||||
return rp;
|
||||
}
|
||||
|
||||
//! \~russian Создать копию точки и переместить её.
|
||||
//! \details Является копией метода \a translated().
|
||||
//! \~english Same as \a translated().
|
||||
//! \~russian Синоним \a translated().
|
||||
PIPoint<Type> moved(const PIPoint<Type> & p) const {
|
||||
PIPoint<Type> rp(*this);
|
||||
rp.translate(p);
|
||||
return rp;
|
||||
}
|
||||
|
||||
//! \~russian Посчитать угол(радианы) в поолярной системе координат.
|
||||
//! \~english Returns polar angle in radians.
|
||||
//! \~russian Возвращает полярный угол в радианах.
|
||||
double angleRad() const { return atan2(y, x); }
|
||||
|
||||
//! \~russian Посчитать угол(градусы) в поолярной системе координат.
|
||||
//! \~english Returns polar angle in degrees.
|
||||
//! \~russian Возвращает полярный угол в градусах.
|
||||
double angleDeg() const { return toDeg(atan2(y, x)); }
|
||||
|
||||
//! \~russian Перевести копию точки в полярную систему координат.
|
||||
//! \~english Returns polar form with radius in \a x and angle in \a y.
|
||||
//! \~russian Возвращает полярную форму, где радиус хранится в \a x, а угол в \a y.
|
||||
PIPoint<Type> toPolar(bool isDeg = false) const { return PIPoint<Type>(sqrt(x * x + y * y), isDeg ? angleDeg() : angleRad()); }
|
||||
|
||||
//! \~russian Перевести копию точки из полярной системы координат в декартовую.
|
||||
//! \~english Builds Cartesian point from polar pair with angle in \a x and radius in \a y.
|
||||
//! \~russian Строит декартову точку из полярной пары, где угол хранится в \a x, а радиус в \a y.
|
||||
static PIPoint<Type> fromPolar(const PIPoint<Type> & p) { return PIPoint<Type>(p.y * cos(p.x), p.y * sin(p.x)); }
|
||||
|
||||
//! \~russian
|
||||
//! Прибавить координаты второй точки и сохранить.
|
||||
//! \details Является копией метода \a translate().
|
||||
//! \~english Same as \a translate().
|
||||
//! \~russian Синоним \a translate().
|
||||
PIPoint<Type> & operator+=(const PIPoint<Type> & p) {
|
||||
translate(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Multiplies both coordinates by `v`.
|
||||
//! \~russian Умножает обе координаты на `v`.
|
||||
PIPoint<Type> & operator*=(Type v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Divides both coordinates by `v`.
|
||||
//! \~russian Делит обе координаты на `v`.
|
||||
PIPoint<Type> & operator/=(Type v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~russian Сложить координаты двух точек.
|
||||
//! \~english Returns sum of two points.
|
||||
//! \~russian Возвращает сумму двух точек.
|
||||
PIPoint<Type> operator+(const PIPoint<Type> & p) { return PIPoint<Type>(x + p.x, y + p.y); }
|
||||
|
||||
//! \~russian Прибавить к координатам одинаковое значение.
|
||||
//! \~english Returns point with `p` added to both coordinates.
|
||||
//! \~russian Возвращает точку с добавлением `p` к обеим координатам.
|
||||
PIPoint<Type> operator+(const Type & p) { return PIPoint<Type>(x + p, y + p); }
|
||||
|
||||
//! \~russian Вычесть из координат координаты второй точки - найти смещение.
|
||||
//! \~english Returns difference between two points.
|
||||
//! \~russian Возвращает разность двух точек.
|
||||
PIPoint<Type> operator-(const PIPoint<Type> & p) { return PIPoint<Type>(x - p.x, y - p.y); }
|
||||
|
||||
//! \~russian Вычесть из координат одинаковое значение.
|
||||
//! \~english Returns point with `p` subtracted from both coordinates.
|
||||
//! \~russian Возвращает точку с вычитанием `p` из обеих координат.
|
||||
PIPoint<Type> operator-(const Type & p) { return PIPoint<Type>(x - p, y - p); }
|
||||
|
||||
//! \~russian Инвертировать координаты точки.
|
||||
//! \~english Returns point with inverted coordinates.
|
||||
//! \~russian Возвращает точку с инвертированными координатами.
|
||||
PIPoint<Type> operator-() { return PIPoint<Type>(-x, -y); }
|
||||
|
||||
//! \~russian Умножить координаты точки.
|
||||
//! \~english Returns point scaled by `v`.
|
||||
//! \~russian Возвращает точку, масштабированную на `v`.
|
||||
PIPoint<Type> operator*(Type v) { return PIPoint<Type>(x * v, y * v); }
|
||||
|
||||
//! \~russian Делить координаты точки.
|
||||
//! \~english Returns point divided by `v`.
|
||||
//! \~russian Возвращает точку, деленную на `v`.
|
||||
PIPoint<Type> operator/(Type v) { return PIPoint<Type>(x / v, y / v); }
|
||||
|
||||
//! \~russian Проверить равенство координат двух точек.
|
||||
//! \~english Checks whether point coordinates are equal.
|
||||
//! \~russian Проверяет равенство координат точек.
|
||||
bool operator==(const PIPoint<Type> & p) const { return (x == p.x && y == p.y); }
|
||||
|
||||
//! \~russian Проверить неравенство координат двух точек.
|
||||
//! \~english Checks whether point coordinates differ.
|
||||
//! \~russian Проверяет неравенство координат точек.
|
||||
bool operator!=(const PIPoint<Type> & p) const { return (x != p.x || y != p.y); }
|
||||
};
|
||||
|
||||
//! \~russian Перегруженный оператор для вывода координат в \a PICout.
|
||||
//! \relatesalso PICout
|
||||
//! \~english Writes point coordinates to \a PICout.
|
||||
//! \~russian Выводит координаты точки в \a PICout.
|
||||
template<typename Type>
|
||||
PICout operator<<(PICout & s, const PIPoint<Type> & v) {
|
||||
s.space();
|
||||
@@ -182,9 +213,20 @@ PICout operator<<(PICout & s, const PIPoint<Type> & v) {
|
||||
}
|
||||
|
||||
|
||||
//! \~english Alias for point with `int` coordinates.
|
||||
//! \~russian Псевдоним точки с координатами типа `int`.
|
||||
typedef PIPoint<int> PIPointi;
|
||||
|
||||
//! \~english Alias for point with `uint` coordinates.
|
||||
//! \~russian Псевдоним точки с координатами типа `uint`.
|
||||
typedef PIPoint<uint> PIPointu;
|
||||
|
||||
//! \~english Alias for point with `float` coordinates.
|
||||
//! \~russian Псевдоним точки с координатами типа `float`.
|
||||
typedef PIPoint<float> PIPointf;
|
||||
|
||||
//! \~english Alias for point with `double` coordinates.
|
||||
//! \~russian Псевдоним точки с координатами типа `double`.
|
||||
typedef PIPoint<double> PIPointd;
|
||||
|
||||
#endif // PIPOINT_H
|
||||
|
||||
Reference in New Issue
Block a user