merged AI doc, some new pages

This commit is contained in:
2026-03-12 14:46:57 +03:00
parent 07ae277f9e
commit ed13838237
206 changed files with 14088 additions and 5152 deletions

View File

@@ -1,11 +1,11 @@
//! \file pirect.h
//! \ingroup Math
//! \brief
//! \~english Rect class
//! \~russian Класс прямоугольника
//! \~\file pirect.h
//! \~\ingroup Math
//! \~\brief
//! \~english Rect class for 2D geometry
//! \~russian Класс прямоугольника для 2D геометрии
/*
PIP - Platform Independent Primitives
Rect class
Rect class for 2D geometry
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
@@ -27,29 +27,28 @@
#include "pipoint.h"
//! \brief
//! \~english Rect class
//! \~russian Класс прямоугольника
//! \~\details
//! \~russian
//! Этот класс описывает прямоугольник на плоскости в прямоугольной системе координат
//! \~\ingroup Math
//! \~\brief
//! \~english The PIRect class provides a two-dimensional rectangle class for 2D geometry.
//! \~russian Класс PIRect предоставляет двумерный класс прямоугольника для 2D геометрии.
template<typename Type>
class PIP_EXPORT PIRect {
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
public:
//!
//! \~english Constructs empty rectangle.
//! \~russian Создает пустой прямоугольник.
PIRect() {}
//! \brief
//! \~russian Конструктор прямоугольника из координат левого нижнего угла и размеров ширины и высоты
//! \~english Constructs rectangle from bottom-left corner, width and height.
//! \~russian Создает прямоугольник по левому нижнему углу, ширине и высоте.
PIRect(Type left_, Type bottom_, Type width_, Type height_) {
set(left_, bottom_, width_, height_);
normalize();
}
//! \brief
//! \~russian Конструктор прямоугольника из координат левого нижнего угла и правого верхнего угла
//! \~english Constructs rectangle from opposite corners.
//! \~russian Создает прямоугольник по двум противоположным углам.
PIRect(const PIPoint<Type> & bottom_left, const PIPoint<Type> & top_right) {
bl = bottom_left;
tr = top_right;
@@ -61,128 +60,148 @@ public:
// piMax<Type>(p0.x, p1.x, p2.x), piMax<Type>(p0.y, p1.y, p2.y));
// }
//!
//! \~english Sets rectangle from bottom-left corner, width and height.
//! \~russian Задает прямоугольник по левому нижнему углу, ширине и высоте.
PIRect<Type> & set(Type left_, Type bottom_, Type width_, Type height_) {
bl = PIPoint<Type>(left_, bottom_);
tr = PIPoint<Type>(left_ + width_, bottom_ + height_);
return normalize();
}
//!
//! \~english Sets rectangle from two opposite corners.
//! \~russian Задает прямоугольник по двум противоположным углам.
PIRect<Type> & set(const PIPoint<Type> & top_left, const PIPoint<Type> & bottom_right) {
bl = top_left;
tr = bottom_right;
return normalize();
}
//! \brief
//! \~russian Возвращает true если точка с указанными координатами принадлежит прямоугольнику
//! \~english Checks point against current rectangle bounds.
//! \~russian Проверяет точку относительно текущих границ прямоугольника.
bool pointIn(Type x, Type y) const { return (x <= bl.x && x >= tr.x && y <= bl.y && y >= tr.y); }
//! \brief
//! \~russian Возвращает true если точка с указанными координатами принадлежит прямоугольнику
//! \~english Checks point against current rectangle bounds.
//! \~russian Проверяет точку относительно текущих границ прямоугольника.
bool pointIn(const PIPoint<Type> & p) const { return pointIn(p.x, p.y); }
//!
//! \~english Returns `true` if width and height are zero.
//! \~russian Возвращает `true`, если ширина и высота равны нулю.
bool isEmpty() const { return (width() == 0 && height() == 0); }
//!
//! \~english Shifts the rectangle by `x` and `y`.
//! \~russian Сдвигает прямоугольник на `x` и `y`.
PIRect<Type> & translate(Type x, Type y) {
bl.translate(x, y);
tr.translate(x, y);
return *this;
}
//!
//! \~english Shifts the rectangle by a point offset.
//! \~russian Сдвигает прямоугольник на смещение, заданное точкой.
PIRect<Type> & translate(const PIPoint<Type> & p) {
bl.translate(p);
tr.translate(p);
return *this;
}
//!
//! \~english Returns translated copy of the rectangle.
//! \~russian Возвращает смещенную копию прямоугольника.
PIRect<Type> translated(Type x, Type y) const {
PIRect<Type> r(*this);
r.translate(x, y);
return r;
}
//!
//! \~english Returns copy shifted by a point offset.
//! \~russian Возвращает копию, смещенную на точку.
PIRect<Type> translated(const PIPoint<Type> & p) const {
PIRect<Type> r(*this);
r.translate(p);
return r;
}
//!
//! \~english Same as \a translate().
//! \~russian Синоним \a translate().
PIRect<Type> & move(Type x, Type y) { return translate(x, y); }
//!
//! \~english Same as \a translate().
//! \~russian Синоним \a translate().
PIRect<Type> & move(const PIPoint<Type> & p) { return translate(p); }
//!
//! \~english Same as \a translated().
//! \~russian Синоним \a translated().
PIRect<Type> moved(Type x, Type y) const {
PIRect<Type> r(*this);
r.translate(x, y);
return r;
}
//!
//! \~english Same as \a translated().
//! \~russian Синоним \a translated().
PIRect<Type> moved(const PIPoint<Type> & p) const {
PIRect<Type> r(*this);
r.translate(p);
return r;
}
//!
//! \~english Scales rectangle extents by `x` and `y`.
//! \~russian Масштабирует размеры прямоугольника по `x` и `y`.
PIRect<Type> & scale(Type x, Type y) {
setWidth(width() * x);
setHeight(height() * y);
return normalize();
}
//!
//! \~english Scales both extents by `s`.
//! \~russian Масштабирует обе стороны на `s`.
PIRect<Type> & scale(Type s) { return scale(s, s); }
//!
//! \~english Scales extents by point components.
//! \~russian Масштабирует стороны по компонентам точки.
PIRect<Type> & scale(const PIPoint<Type> & p) { return scale(p.x, p.y); }
//!
//! \~english Returns scaled copy of the rectangle.
//! \~russian Возвращает масштабированную копию прямоугольника.
PIRect<Type> scaled(Type x, Type y) const {
PIRect<Type> r(*this);
r.scale(x, y);
return r;
}
//!
//! \~english Returns copy scaled uniformly.
//! \~russian Возвращает копию с равномерным масштабированием.
PIRect<Type> scaled(Type s) const {
PIRect<Type> r(*this);
r.scale(s);
return r;
}
//!
//! \~english Returns copy scaled by point components.
//! \~russian Возвращает копию, масштабированную по компонентам точки.
PIRect<Type> scaled(const PIPoint<Type> & p) const {
PIRect<Type> r(*this);
r.scale(p);
return r;
}
//!
//! \~english Normalizes corner order.
//! \~russian Нормализует порядок углов.
PIRect<Type> & normalize() {
if (bl.x > tr.x) piSwap<Type>(bl.x, tr.x);
if (bl.y > tr.y) piSwap<Type>(bl.y, tr.y);
return *this;
}
//!
//! \~english Returns normalized copy of the rectangle.
//! \~russian Возвращает нормализованную копию прямоугольника.
PIRect<Type> normalized() const {
PIRect<Type> r(*this);
r.normalize();
return r;
}
//!
//! \~english Updates bounds using rectangle `r` and normalizes the result.
//! \~russian Обновляет границы по прямоугольнику `r` и нормализует результат.
PIRect<Type> & unite(const PIRect<Type> & r) {
bl.x = piMax<Type>(bl.x, r.left());
bl.y = piMax<Type>(bl.y, r.bottom());
@@ -191,14 +210,16 @@ public:
return normalize();
}
//!
//! \~english Returns copy after \a unite().
//! \~russian Возвращает копию после \a unite().
PIRect<Type> united(const PIRect<Type> & rect) const {
PIRect<Type> r(*this);
r.unite(rect);
return r;
}
//!
//! \~english Replaces rectangle with intersection with `r`.
//! \~russian Заменяет прямоугольник пересечением с `r`.
PIRect<Type> & intersect(const PIRect<Type> & r) {
bl.x = piMax<Type>(bl.x, r.left());
bl.y = piMax<Type>(bl.y, r.bottom());
@@ -208,101 +229,124 @@ public:
return *this;
}
//!
//! \~english Returns copy after \a intersect().
//! \~russian Возвращает копию после \a intersect().
PIRect<Type> intersected(const PIRect<Type> & rect) const {
PIRect<Type> r(*this);
r.intersect(rect);
return r;
}
//!
//! \~english Returns top edge coordinate.
//! \~russian Возвращает координату верхней границы.
Type top() const { return tr.y; }
//!
//! \~english Returns left edge coordinate.
//! \~russian Возвращает координату левой границы.
Type left() const { return bl.x; }
//!
//! \~english Returns right edge coordinate.
//! \~russian Возвращает координату правой границы.
Type right() const { return tr.x; }
//!
//! \~english Returns bottom edge coordinate.
//! \~russian Возвращает координату нижней границы.
Type bottom() const { return bl.y; }
//!
//! \~english Returns rectangle width.
//! \~russian Возвращает ширину прямоугольника.
Type width() const { return tr.x - bl.x; }
//!
//! \~english Returns rectangle height.
//! \~russian Возвращает высоту прямоугольника.
Type height() const { return tr.y - bl.y; }
//!
//! \~english Returns top-left corner.
//! \~russian Возвращает левый верхний угол.
PIPoint<Type> topLeft() const { return PIPoint<Type>(bl.x, tr.y); }
//!
//! \~english Returns top-right corner.
//! \~russian Возвращает правый верхний угол.
PIPoint<Type> topRigth() const { return tr; }
//!
//! \~english Returns bottom-left corner.
//! \~russian Возвращает левый нижний угол.
PIPoint<Type> bottomLeft() const { return bl; }
//!
//! \~english Returns bottom-right corner.
//! \~russian Возвращает правый нижний угол.
PIPoint<Type> bottomRight() const { return PIPoint<Type>(tr.x, bl.y); }
//!
//! \~english Returns rectangle center.
//! \~russian Возвращает центр прямоугольника.
PIPoint<Type> center() const { return bl.moved(width() / 2, height() / 2); }
//!
//! \~english Sets top edge coordinate.
//! \~russian Задает координату верхней границы.
void setTop(Type v) {
tr.y = v;
normalize();
}
//!
//! \~english Sets left edge coordinate.
//! \~russian Задает координату левой границы.
void setLeft(Type v) {
bl.x = v;
normalize();
}
//!
//! \~english Sets right edge coordinate.
//! \~russian Задает координату правой границы.
void setRigth(Type v) {
tr.x = v;
normalize();
}
//!
//! \~english Sets bottom edge coordinate.
//! \~russian Задает координату нижней границы.
void setBottom(Type v) {
bl.y = v;
normalize();
}
//!
//! \~english Updates stored width-related extent.
//! \~russian Обновляет хранимую горизонтальную размерность.
void setWidth(Type v) { setTop(bl.x + v); }
//!
//! \~english Updates stored height-related extent.
//! \~russian Обновляет хранимую вертикальную размерность.
void setHeight(Type v) { setRigth(bl.y + v); }
//!
//! \~english Sets top-left corner.
//! \~russian Задает левый верхний угол.
void setTopLeft(const PIPoint<Type> & p) {
setLeft(p.x);
setTop(p.y);
}
//!
//! \~english Sets bottom-right corner.
//! \~russian Задает правый нижний угол.
void setBottomRight(const PIPoint<Type> & p) {
setRigth(p.x);
setBottom(p.y);
}
//!
//! \~english Sets bottom-left corner.
//! \~russian Задает левый нижний угол.
void setBottomLeft(const PIPoint<Type> & p) {
bl = p;
normalize();
}
//!
//! \~english Sets top-right corner.
//! \~russian Задает правый верхний угол.
void setTopRigth(const PIPoint<Type> & p) {
tr = p;
normalize();
}
//!
//! \~english Repositions rectangle around center point `p`.
//! \~russian Перемещает прямоугольник так, чтобы его центром стала точка `p`.
void setCenter(const PIPoint<Type> & p) {
Type w = width();
Type h = height();
@@ -310,46 +354,59 @@ public:
tr = PIPoint<Type>(bl.x + w, bl.y + h);
}
//!
//! \~english Sets rectangle size from current bottom-left corner.
//! \~russian Задает размер прямоугольника от текущего левого нижнего угла.
void setSize(Type w, Type h) {
tr = PIPoint<Type>(bl.x + w, bl.y + h);
normalize();
}
//!
//! \~english Shifts both coordinates by `x`.
//! \~russian Сдвигает обе координаты на `x`.
void operator+=(Type x) { translate(x, x); }
//!
//! \~english Shifts rectangle by a point offset.
//! \~russian Сдвигает прямоугольник на смещение, заданное точкой.
void operator+=(const PIPoint<Type> & p) { translate(p); }
//!
//! \~english Shifts both coordinates by `-x`.
//! \~russian Сдвигает обе координаты на `-x`.
void operator-=(Type x) { translate(-x, -x); }
//!
//! \~english Shifts rectangle by the negated point offset.
//! \~russian Сдвигает прямоугольник на отрицательное смещение точки.
void operator-=(const PIPoint<Type> & p) { translate(-p); }
//!
//! \~english Same as \a unite().
//! \~russian Синоним \a unite().
void operator|=(const PIRect<Type> & r) { unite(r); }
//!
//! \~english Same as \a intersect().
//! \~russian Синоним \a intersect().
void operator&=(const PIRect<Type> & r) { intersect(r); }
//!
//! \~english Returns translated copy of the rectangle.
//! \~russian Возвращает смещенную копию прямоугольника.
PIRect<Type> operator+(const PIPoint<Type> & p) { return translated(p); }
//!
//! \~english Returns copy shifted by the negated point offset.
//! \~russian Возвращает копию, смещенную на отрицательное смещение точки.
PIRect<Type> operator-(const PIPoint<Type> & p) { return translated(-p); }
//!
//! \~english Returns copy after \a unite().
//! \~russian Возвращает копию после \a unite().
PIRect<Type> operator|(const PIRect<Type> & r) { return united(r); }
//!
//! \~english Returns copy after \a intersect().
//! \~russian Возвращает копию после \a intersect().
PIRect<Type> operator&(const PIRect<Type> & r) { return intersected(r); }
//!
//! \~english Checks whether rectangle corners are equal.
//! \~russian Проверяет равенство углов прямоугольников.
bool operator==(const PIRect<Type> & r) const { return (bl == r.bl && tr == r.tr); }
//!
//! \~english Checks whether rectangle corners differ.
//! \~russian Проверяет различие углов прямоугольников.
bool operator!=(const PIRect<Type> & r) const { return (bl != r.bl || tr != r.tr); }
private:
@@ -358,6 +415,9 @@ private:
};
//! \relatesalso PICout
//! \~english Writes rectangle description to \a PICout.
//! \~russian Выводит описание прямоугольника в \a PICout.
template<typename Type>
PICout operator<<(PICout & s, const PIRect<Type> & v) {
s.space();
@@ -368,9 +428,20 @@ PICout operator<<(PICout & s, const PIRect<Type> & v) {
}
//! \~english Alias for rectangle with `int` coordinates.
//! \~russian Псевдоним прямоугольника с координатами типа `int`.
typedef PIRect<int> PIRecti;
//! \~english Alias for rectangle with `uint` coordinates.
//! \~russian Псевдоним прямоугольника с координатами типа `uint`.
typedef PIRect<uint> PIRectu;
//! \~english Alias for rectangle with `float` coordinates.
//! \~russian Псевдоним прямоугольника с координатами типа `float`.
typedef PIRect<float> PIRectf;
//! \~english Alias for rectangle with `double` coordinates.
//! \~russian Псевдоним прямоугольника с координатами типа `double`.
typedef PIRect<double> PIRectd;
#endif // PIRECT_H