code style
This commit is contained in:
@@ -34,6 +34,14 @@
|
|||||||
|
|
||||||
#include "pipoint.h"
|
#include "pipoint.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief
|
||||||
|
* \~english Two-dimensional line class
|
||||||
|
* \~russian Класс отрезка двумерной линии
|
||||||
|
* \~\details
|
||||||
|
* \~russian
|
||||||
|
* Этот класс описывает линию на плоскости в прямоугольной системе координат
|
||||||
|
*/
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class PIP_EXPORT PILine {
|
class PIP_EXPORT PILine {
|
||||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||||
@@ -41,82 +49,120 @@ public:
|
|||||||
PIPoint<Type> p0;
|
PIPoint<Type> p0;
|
||||||
PIPoint<Type> p1;
|
PIPoint<Type> p1;
|
||||||
|
|
||||||
|
//!
|
||||||
PILine() {}
|
PILine() {}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine(const PIPoint<Type> & p0_, const PIPoint<Type> & p1_) {
|
PILine(const PIPoint<Type> & p0_, const PIPoint<Type> & p1_) {
|
||||||
p0 = p0_;
|
p0 = p0_;
|
||||||
p1 = p1_;
|
p1 = p1_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine(Type x0, Type y0, Type x1, Type y1) {
|
PILine(Type x0, Type y0, Type x1, Type y1) {
|
||||||
p0.set(x0, y0);
|
p0.set(x0, y0);
|
||||||
p1.set(x1, y1);
|
p1.set(x1, y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> & set(const PIPoint<Type> & p0_, const PIPoint<Type> & p1_) {
|
PILine<Type> & set(const PIPoint<Type> & p0_, const PIPoint<Type> & p1_) {
|
||||||
p0 = p0_;
|
p0 = p0_;
|
||||||
p1 = p1_;
|
p1 = p1_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> & set(Type x0, Type y0, Type x1, Type y1) {
|
PILine<Type> & set(Type x0, Type y0, Type x1, Type y1) {
|
||||||
p0.set(x0, y0);
|
p0.set(x0, y0);
|
||||||
p1.set(x1, y1);
|
p1.set(x1, y1);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
bool isEmpty() const {
|
bool isEmpty() const {
|
||||||
return (p0 == p1);
|
return (p0 == p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
Type width() const {return piAbs<Type>(p1.x - p0.x);}
|
Type width() const {return piAbs<Type>(p1.x - p0.x);}
|
||||||
|
|
||||||
|
//!
|
||||||
Type height() const {return piAbs<Type>(p1.y - p0.y);}
|
Type height() const {return piAbs<Type>(p1.y - p0.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> & translate(Type x, Type y) {
|
PILine<Type> & translate(Type x, Type y) {
|
||||||
p0.translate(x, y);
|
p0.translate(x, y);
|
||||||
p1.translate(x, y);
|
p1.translate(x, y);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> & translate(const PIPoint<Type> & p) {
|
PILine<Type> & translate(const PIPoint<Type> & p) {
|
||||||
p0.translate(p);
|
p0.translate(p);
|
||||||
p1.translate(p);
|
p1.translate(p);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> translated(Type x, Type y) const {
|
PILine<Type> translated(Type x, Type y) const {
|
||||||
PILine<Type> l(*this);
|
PILine<Type> l(*this);
|
||||||
l.translate(x, y);
|
l.translate(x, y);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> translated(const PIPoint<Type> & p) const {
|
PILine<Type> translated(const PIPoint<Type> & p) const {
|
||||||
PILine<Type> l(*this);
|
PILine<Type> l(*this);
|
||||||
l.translate(p);
|
l.translate(p);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> & move(Type x, Type y) {return translate(x, y);}
|
PILine<Type> & move(Type x, Type y) {return translate(x, y);}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
PILine<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> moved(Type x, Type y) const {
|
PILine<Type> moved(Type x, Type y) const {
|
||||||
PILine<Type> l(*this);
|
PILine<Type> l(*this);
|
||||||
l.translate(x, y);
|
l.translate(x, y);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> moved(const PIPoint<Type> & p) const {
|
PILine<Type> moved(const PIPoint<Type> & p) const {
|
||||||
PILine<Type> l(*this);
|
PILine<Type> l(*this);
|
||||||
l.translate(p);
|
l.translate(p);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator +=(Type x) {translate(x, x);}
|
void operator +=(Type x) {translate(x, x);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator -=(Type x) {translate(-x, -x);}
|
void operator -=(Type x) {translate(-x, -x);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator -=(const PIPoint<Type> & p) {translate(-p);}
|
void operator -=(const PIPoint<Type> & p) {translate(-p);}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> operator +(const PIPoint<Type> & p) {return translated(p);}
|
PILine<Type> operator +(const PIPoint<Type> & p) {return translated(p);}
|
||||||
|
|
||||||
|
//!
|
||||||
PILine<Type> operator -(const PIPoint<Type> & p) {return translated(-p);}
|
PILine<Type> operator -(const PIPoint<Type> & p) {return translated(-p);}
|
||||||
|
|
||||||
|
//!
|
||||||
bool operator ==(const PILine<Type> & r) const {return (p0 == r.p0 && p1 == r.p1);}
|
bool operator ==(const PILine<Type> & r) const {return (p0 == r.p0 && p1 == r.p1);}
|
||||||
|
|
||||||
|
//!
|
||||||
bool operator !=(const PILine<Type> & r) const {return (p1 != r.p1 || p1 != r.p1);}
|
bool operator !=(const PILine<Type> & r) const {return (p1 != r.p1 || p1 != r.p1);}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
PICout operator <<(PICout & s, const PILine<Type> & v) {
|
PICout operator <<(PICout & s, const PILine<Type> & v) {
|
||||||
s.setControl(0, true);
|
s.setControl(0, true);
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
/*! \file pipoint.h
|
//! \file pipoint.h
|
||||||
* \ingroup Math
|
//! \ingroup Math
|
||||||
* \brief
|
//! \brief
|
||||||
* \~english Two-dimensional point class
|
//! \~english Two-dimensional point class
|
||||||
* \~russian Класс двумерной точки
|
//! \~russian Класс двумерной точки
|
||||||
* \~\authors
|
//! \~\authors
|
||||||
* \~english
|
//! \~english
|
||||||
* Ivan Pelipenko peri4ko@yandex.ru;
|
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||||
* Andrey Bychkov work.a.b@yandex.ru;
|
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||||
* \~russian
|
//! \~russian
|
||||||
* Иван Пелипенко peri4ko@yandex.ru;
|
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||||
* Андрей Бычков work.a.b@yandex.ru;
|
//! Андрей Бычков work.a.b@yandex.ru;
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
Two-dimensional point class
|
Two-dimensional point class
|
||||||
@@ -31,10 +30,10 @@
|
|||||||
|
|
||||||
#include "pimathbase.h"
|
#include "pimathbase.h"
|
||||||
|
|
||||||
/*! \brief
|
|
||||||
* \~english Two-dimensional point class
|
//! \brief
|
||||||
* \~russian Класс двумерной точки
|
//! \~english Two-dimensional point class
|
||||||
*/
|
//! \~russian Класс двумерной точки
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class PIP_EXPORT PIPoint {
|
class PIP_EXPORT PIPoint {
|
||||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||||
@@ -42,65 +41,109 @@ public:
|
|||||||
Type x;
|
Type x;
|
||||||
Type y;
|
Type y;
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint() {x = y = Type();}
|
PIPoint() {x = y = Type();}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint(Type x_, Type y_) {set(x_, y_);}
|
PIPoint(Type x_, Type y_) {set(x_, y_);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> & set(Type x_, Type y_) {
|
PIPoint<Type> & set(Type x_, Type y_) {
|
||||||
x = x_;
|
x = x_;
|
||||||
y = y_;
|
y = y_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> & set(const PIPoint<Type> & p) {
|
PIPoint<Type> & set(const PIPoint<Type> & p) {
|
||||||
x = p.x;
|
x = p.x;
|
||||||
y = p.y;
|
y = p.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> & translate(Type x_, Type y_) {
|
PIPoint<Type> & translate(Type x_, Type y_) {
|
||||||
x += x_;
|
x += x_;
|
||||||
y += y_;
|
y += y_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> & translate(const PIPoint<Type> & p) {
|
PIPoint<Type> & translate(const PIPoint<Type> & p) {
|
||||||
x += p.x;
|
x += p.x;
|
||||||
y += p.y;
|
y += p.y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> translated(Type x_, Type y_) const {
|
PIPoint<Type> translated(Type x_, Type y_) const {
|
||||||
PIPoint<Type> rp(*this);
|
PIPoint<Type> rp(*this);
|
||||||
rp.translate(x_, y_);
|
rp.translate(x_, y_);
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> translated(const PIPoint<Type> & p) const {
|
PIPoint<Type> translated(const PIPoint<Type> & p) const {
|
||||||
PIPoint<Type> rp(*this);
|
PIPoint<Type> rp(*this);
|
||||||
rp.translate(p);
|
rp.translate(p);
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> & move(Type x_, Type y_) {return translate(x_, y_);}
|
PIPoint<Type> & move(Type x_, Type y_) {return translate(x_, y_);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
PIPoint<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> moved(Type x_, Type y_) const {
|
PIPoint<Type> moved(Type x_, Type y_) const {
|
||||||
PIPoint<Type> rp(*this);
|
PIPoint<Type> rp(*this);
|
||||||
rp.translate(x_, y_);
|
rp.translate(x_, y_);
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> moved(const PIPoint<Type> & p) const {
|
PIPoint<Type> moved(const PIPoint<Type> & p) const {
|
||||||
PIPoint<Type> rp(*this);
|
PIPoint<Type> rp(*this);
|
||||||
rp.translate(p);
|
rp.translate(p);
|
||||||
return rp;
|
return rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
double angleRad() const {return atan2(y, x);}
|
double angleRad() const {return atan2(y, x);}
|
||||||
|
|
||||||
|
//!
|
||||||
double angleDeg() const {return toDeg(atan2(y, x));}
|
double angleDeg() const {return toDeg(atan2(y, x));}
|
||||||
|
|
||||||
|
//!
|
||||||
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());}
|
||||||
|
|
||||||
|
//!
|
||||||
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));}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
||||||
PIPoint<Type> operator +(const PIPoint<Type> & p) {return PIPoint<Type>(x + p.x, y + p.y);}
|
|
||||||
PIPoint<Type> operator +(const Type & p) {return PIPoint<Type>(x + p, y + p);}
|
|
||||||
PIPoint<Type> operator -(const PIPoint<Type> & p) {return PIPoint<Type>(x - p.x, y - p.y);}
|
|
||||||
PIPoint<Type> operator -(const Type & p) {return PIPoint<Type>(x - p, y - p);}
|
|
||||||
PIPoint<Type> operator -() {return PIPoint<Type>(-x, -y);}
|
|
||||||
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);}
|
|
||||||
|
|
||||||
|
//!
|
||||||
|
PIPoint<Type> operator +(const PIPoint<Type> & p) {return PIPoint<Type>(x + p.x, y + p.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
|
PIPoint<Type> operator +(const Type & p) {return PIPoint<Type>(x + p, y + p);}
|
||||||
|
|
||||||
|
//!
|
||||||
|
PIPoint<Type> operator -(const PIPoint<Type> & p) {return PIPoint<Type>(x - p.x, y - p.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
|
PIPoint<Type> operator -(const Type & p) {return PIPoint<Type>(x - p, y - p);}
|
||||||
|
|
||||||
|
//!
|
||||||
|
PIPoint<Type> operator -() {return PIPoint<Type>(-x, -y);}
|
||||||
|
|
||||||
|
//!
|
||||||
|
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);}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
/*! \file pirect.h
|
//! \file pirect.h
|
||||||
* \ingroup Math
|
//! \ingroup Math
|
||||||
* \brief
|
//! \brief
|
||||||
* \~english Rect class
|
//! \~english Rect class
|
||||||
* \~russian Класс прямоугольника
|
//! \~russian Класс прямоугольника
|
||||||
* \~\authors
|
//! \~\authors
|
||||||
* \~english
|
//! \~english
|
||||||
* Ivan Pelipenko peri4ko@yandex.ru;
|
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||||
* Andrey Bychkov work.a.b@yandex.ru;
|
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||||
* \~russian
|
//! \~russian
|
||||||
* Иван Пелипенко peri4ko@yandex.ru;
|
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||||
* Андрей Бычков work.a.b@yandex.ru;
|
//! Андрей Бычков work.a.b@yandex.ru;
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
Rect class
|
Rect class
|
||||||
@@ -34,121 +33,168 @@
|
|||||||
|
|
||||||
#include "pipoint.h"
|
#include "pipoint.h"
|
||||||
|
|
||||||
/*! \brief
|
|
||||||
* \~english Rect class
|
//! \brief
|
||||||
* \~russian Класс прямоугольника
|
//! \~english Rect class
|
||||||
* \~\details
|
//! \~russian Класс прямоугольника
|
||||||
* \~russian
|
//! \~\details
|
||||||
* Этот класс описывает прямоугольник на плоскости в прямоугольной системе координат
|
//! \~russian
|
||||||
*/
|
//! Этот класс описывает прямоугольник на плоскости в прямоугольной системе координат
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class PIP_EXPORT PIRect {
|
class PIP_EXPORT PIRect {
|
||||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||||
public:
|
public:
|
||||||
|
//!
|
||||||
PIRect() {}
|
PIRect() {}
|
||||||
|
|
||||||
/*! \brief
|
//! \brief
|
||||||
* \~russian Конструктор прямоугольника из координат левого нижнего угла и размеров ширины и высоты
|
//! \~russian Конструктор прямоугольника из координат левого нижнего угла и размеров ширины и высоты
|
||||||
*/
|
|
||||||
PIRect(Type left_, Type bottom_, Type width_, Type height_) {
|
PIRect(Type left_, Type bottom_, Type width_, Type height_) {
|
||||||
set(left_, bottom_, width_, height_);
|
set(left_, bottom_, width_, height_);
|
||||||
normalize();
|
normalize();
|
||||||
}
|
}
|
||||||
/*! \brief
|
|
||||||
* \~russian Конструктор прямоугольника из координат левого нижнего угла и правого верхнего угла
|
//! \brief
|
||||||
*/
|
//! \~russian Конструктор прямоугольника из координат левого нижнего угла и правого верхнего угла
|
||||||
PIRect(const PIPoint<Type> & bottom_left, const PIPoint<Type> & top_right) {
|
PIRect(const PIPoint<Type> & bottom_left, const PIPoint<Type> & top_right) {
|
||||||
bl = bottom_left;
|
bl = bottom_left;
|
||||||
tr = top_right;
|
tr = top_right;
|
||||||
normalize();
|
normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PIRect(const PIPoint<Type> & p0, const PIPoint<Type> & p1, const PIPoint<Type> & p2) {
|
// PIRect(const PIPoint<Type> & p0, const PIPoint<Type> & p1, const PIPoint<Type> & p2) {
|
||||||
// set(piMin<Type>(p0.x, p1.x, p2.x), piMin<Type>(p0.y, p1.y, p2.y),
|
// set(piMin<Type>(p0.x, p1.x, p2.x), piMin<Type>(p0.y, p1.y, p2.y),
|
||||||
// piMax<Type>(p0.x, p1.x, p2.x), piMax<Type>(p0.y, p1.y, p2.y));
|
// piMax<Type>(p0.x, p1.x, p2.x), piMax<Type>(p0.y, p1.y, p2.y));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & set(Type left_, Type bottom_, Type width_, Type height_) {
|
PIRect<Type> & set(Type left_, Type bottom_, Type width_, Type height_) {
|
||||||
bl = PIPoint<Type>(left_, bottom_);
|
bl = PIPoint<Type>(left_, bottom_);
|
||||||
tr = PIPoint<Type>(left_ + width_, bottom_ + height_);
|
tr = PIPoint<Type>(left_ + width_, bottom_ + height_);
|
||||||
return normalize();
|
return normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & set(const PIPoint<Type> & top_left, const PIPoint<Type> & bottom_right) {
|
PIRect<Type> & set(const PIPoint<Type> & top_left, const PIPoint<Type> & bottom_right) {
|
||||||
bl = top_left;
|
bl = top_left;
|
||||||
tr = bottom_right;
|
tr = bottom_right;
|
||||||
return normalize();
|
return normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~russian Возвращает true если точка с указанными координатами принадлежит прямоугольнику
|
||||||
bool pointIn(Type x, Type y) const {
|
bool pointIn(Type x, Type y) const {
|
||||||
return (x <= bl.x && x >= tr.x && y <= bl.y && y >= tr.y);
|
return (x <= bl.x && x >= tr.x && y <= bl.y && y >= tr.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief
|
||||||
|
//! \~russian Возвращает true если точка с указанными координатами принадлежит прямоугольнику
|
||||||
bool pointIn(const PIPoint<Type> & p) const {
|
bool pointIn(const PIPoint<Type> & p) const {
|
||||||
return pointIn(p.x, p.y);
|
return pointIn(p.x, p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
bool isEmpty() const {
|
bool isEmpty() const {
|
||||||
return (width() == 0 && height() == 0);
|
return (width() == 0 && height() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & translate(Type x, Type y) {
|
PIRect<Type> & translate(Type x, Type y) {
|
||||||
bl.translate(x, y);
|
bl.translate(x, y);
|
||||||
tr.translate(x, y);
|
tr.translate(x, y);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & translate(const PIPoint<Type> & p) {
|
PIRect<Type> & translate(const PIPoint<Type> & p) {
|
||||||
bl.translate(p);
|
bl.translate(p);
|
||||||
tr.translate(p);
|
tr.translate(p);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> translated(Type x, Type y) const {
|
PIRect<Type> translated(Type x, Type y) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.translate(x, y);
|
r.translate(x, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> translated(const PIPoint<Type> & p) const {
|
PIRect<Type> translated(const PIPoint<Type> & p) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.translate(p);
|
r.translate(p);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & move(Type x, Type y) {return translate(x, y);}
|
PIRect<Type> & move(Type x, Type y) {return translate(x, y);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
PIRect<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> moved(Type x, Type y) const {
|
PIRect<Type> moved(Type x, Type y) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.translate(x, y);
|
r.translate(x, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> moved(const PIPoint<Type> & p) const {
|
PIRect<Type> moved(const PIPoint<Type> & p) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.translate(p);
|
r.translate(p);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & scale(Type x, Type y) {
|
PIRect<Type> & scale(Type x, Type y) {
|
||||||
setWidth(width() * x);
|
setWidth(width() * x);
|
||||||
setHeight(height() * y);
|
setHeight(height() * y);
|
||||||
return normalize();
|
return normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & scale(Type s) {return scale(s, s);}
|
PIRect<Type> & scale(Type s) {return scale(s, s);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & scale(const PIPoint<Type> & p) {return scale(p.x, p.y);}
|
PIRect<Type> & scale(const PIPoint<Type> & p) {return scale(p.x, p.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> scaled(Type x, Type y) const {
|
PIRect<Type> scaled(Type x, Type y) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.scale(x, y);
|
r.scale(x, y);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> scaled(Type s) const {
|
PIRect<Type> scaled(Type s) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.scale(s);
|
r.scale(s);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> scaled(const PIPoint<Type> & p) const {
|
PIRect<Type> scaled(const PIPoint<Type> & p) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.scale(p);
|
r.scale(p);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & normalize() {
|
PIRect<Type> & normalize() {
|
||||||
if (bl.x > tr.x) piSwap<Type>(bl.x, tr.x);
|
if (bl.x > tr.x) piSwap<Type>(bl.x, tr.x);
|
||||||
if (bl.y > tr.y) piSwap<Type>(bl.y, tr.y);
|
if (bl.y > tr.y) piSwap<Type>(bl.y, tr.y);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> normalized() const {
|
PIRect<Type> normalized() const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.normalize();
|
r.normalize();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & unite(const PIRect<Type> & r) {
|
PIRect<Type> & unite(const PIRect<Type> & r) {
|
||||||
bl.x = piMax<Type>(bl.x, r.left());
|
bl.x = piMax<Type>(bl.x, r.left());
|
||||||
bl.y = piMax<Type>(bl.y, r.bottom());
|
bl.y = piMax<Type>(bl.y, r.bottom());
|
||||||
@@ -156,11 +202,15 @@ public:
|
|||||||
tr.y = piMin<Type>(tr.y, r.top());
|
tr.y = piMin<Type>(tr.y, r.top());
|
||||||
return normalize();
|
return normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> united(const PIRect<Type> & rect) const {
|
PIRect<Type> united(const PIRect<Type> & rect) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.unite(rect);
|
r.unite(rect);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> & intersect(const PIRect<Type> & r) {
|
PIRect<Type> & intersect(const PIRect<Type> & r) {
|
||||||
bl.x = piMax<Type>(bl.x, r.left());
|
bl.x = piMax<Type>(bl.x, r.left());
|
||||||
bl.y = piMax<Type>(bl.y, r.bottom());
|
bl.y = piMax<Type>(bl.y, r.bottom());
|
||||||
@@ -169,54 +219,125 @@ public:
|
|||||||
if (bl.x > tr.x || bl.y > tr.y) bl = tr = PIPoint<Type>();
|
if (bl.x > tr.x || bl.y > tr.y) bl = tr = PIPoint<Type>();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> intersected(const PIRect<Type> & rect) const {
|
PIRect<Type> intersected(const PIRect<Type> & rect) const {
|
||||||
PIRect<Type> r(*this);
|
PIRect<Type> r(*this);
|
||||||
r.intersect(rect);
|
r.intersect(rect);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
Type top() const {return tr.y;}
|
Type top() const {return tr.y;}
|
||||||
|
|
||||||
|
//!
|
||||||
Type left() const {return bl.x;}
|
Type left() const {return bl.x;}
|
||||||
|
|
||||||
|
//!
|
||||||
Type right() const {return tr.x;}
|
Type right() const {return tr.x;}
|
||||||
|
|
||||||
|
//!
|
||||||
Type bottom() const {return bl.y;}
|
Type bottom() const {return bl.y;}
|
||||||
|
|
||||||
|
//!
|
||||||
Type width() const {return tr.x - bl.x;}
|
Type width() const {return tr.x - bl.x;}
|
||||||
|
|
||||||
|
//!
|
||||||
Type height() const {return tr.y - bl.y;}
|
Type height() const {return tr.y - bl.y;}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> topLeft() const {return PIPoint<Type>(bl.x, tr.y);}
|
PIPoint<Type> topLeft() const {return PIPoint<Type>(bl.x, tr.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> topRigth() const {return tr;}
|
PIPoint<Type> topRigth() const {return tr;}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> bottomLeft() const {return bl;}
|
PIPoint<Type> bottomLeft() const {return bl;}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> bottomRight() const {return PIPoint<Type>(tr.x, bl.y);}
|
PIPoint<Type> bottomRight() const {return PIPoint<Type>(tr.x, bl.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIPoint<Type> center() const {return bl.moved(width()/2, height()/2);}
|
PIPoint<Type> center() const {return bl.moved(width()/2, height()/2);}
|
||||||
|
|
||||||
|
//!
|
||||||
void setTop(Type v) {tr.y = v; normalize();}
|
void setTop(Type v) {tr.y = v; normalize();}
|
||||||
|
|
||||||
|
//!
|
||||||
void setLeft(Type v) {bl.x = v; normalize();}
|
void setLeft(Type v) {bl.x = v; normalize();}
|
||||||
|
|
||||||
|
//!
|
||||||
void setRigth(Type v) {tr.x = v; normalize();}
|
void setRigth(Type v) {tr.x = v; normalize();}
|
||||||
|
|
||||||
|
//!
|
||||||
void setBottom(Type v) {bl.y = v; normalize();}
|
void setBottom(Type v) {bl.y = v; normalize();}
|
||||||
|
|
||||||
|
//!
|
||||||
void setWidth(Type v) {setTop(bl.x + v);}
|
void setWidth(Type v) {setTop(bl.x + v);}
|
||||||
|
|
||||||
|
//!
|
||||||
void setHeight(Type v) {setRigth(bl.y + v);}
|
void setHeight(Type v) {setRigth(bl.y + v);}
|
||||||
|
|
||||||
|
//!
|
||||||
void setTopLeft(const PIPoint<Type> & p) {setLeft(p.x); setTop(p.y);}
|
void setTopLeft(const PIPoint<Type> & p) {setLeft(p.x); setTop(p.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
void setBottomRight(const PIPoint<Type> & p) {setRigth(p.x); setBottom(p.y);}
|
void setBottomRight(const PIPoint<Type> & p) {setRigth(p.x); setBottom(p.y);}
|
||||||
|
|
||||||
|
//!
|
||||||
void setBottomLeft(const PIPoint<Type> & p) {bl = p; normalize();}
|
void setBottomLeft(const PIPoint<Type> & p) {bl = p; normalize();}
|
||||||
|
|
||||||
|
//!
|
||||||
void setTopRigth(const PIPoint<Type> & p) {tr = p; normalize();}
|
void setTopRigth(const PIPoint<Type> & p) {tr = p; normalize();}
|
||||||
|
|
||||||
|
//!
|
||||||
void setCenter(const PIPoint<Type> & p) {
|
void setCenter(const PIPoint<Type> & p) {
|
||||||
Type w = width();
|
Type w = width();
|
||||||
Type h = height();
|
Type h = height();
|
||||||
bl = p.translated(-w/2, -h/2);
|
bl = p.translated(-w/2, -h/2);
|
||||||
tr = PIPoint<Type>(bl.x + w, bl.y + h);
|
tr = PIPoint<Type>(bl.x + w, bl.y + h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
void setSize(Type w, Type h) {
|
void setSize(Type w, Type h) {
|
||||||
tr = PIPoint<Type>(bl.x + w, bl.y + h);
|
tr = PIPoint<Type>(bl.x + w, bl.y + h);
|
||||||
normalize();
|
normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator +=(Type x) {translate(x, x);}
|
void operator +=(Type x) {translate(x, x);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator -=(Type x) {translate(-x, -x);}
|
void operator -=(Type x) {translate(-x, -x);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator -=(const PIPoint<Type> & p) {translate(-p);}
|
void operator -=(const PIPoint<Type> & p) {translate(-p);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator |=(const PIRect<Type> & r) {unite(r);}
|
void operator |=(const PIRect<Type> & r) {unite(r);}
|
||||||
|
|
||||||
|
//!
|
||||||
void operator &=(const PIRect<Type> & r) {intersect(r);}
|
void operator &=(const PIRect<Type> & r) {intersect(r);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> operator +(const PIPoint<Type> & p) {return translated(p);}
|
PIRect<Type> operator +(const PIPoint<Type> & p) {return translated(p);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> operator -(const PIPoint<Type> & p) {return translated(-p);}
|
PIRect<Type> operator -(const PIPoint<Type> & p) {return translated(-p);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> operator |(const PIRect<Type> & r) {return united(r);}
|
PIRect<Type> operator |(const PIRect<Type> & r) {return united(r);}
|
||||||
|
|
||||||
|
//!
|
||||||
PIRect<Type> operator &(const PIRect<Type> & r) {return intersected(r);}
|
PIRect<Type> operator &(const PIRect<Type> & r) {return intersected(r);}
|
||||||
|
|
||||||
|
//!
|
||||||
bool operator ==(const PIRect<Type> & r) const {return (bl == r.bl && tr == r.tr);}
|
bool operator ==(const PIRect<Type> & r) const {return (bl == r.bl && tr == r.tr);}
|
||||||
|
|
||||||
|
//!
|
||||||
bool operator !=(const PIRect<Type> & r) const {return (bl != r.bl || tr != r.tr);}
|
bool operator !=(const PIRect<Type> & r) const {return (bl != r.bl || tr != r.tr);}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -224,6 +345,7 @@ private:
|
|||||||
PIPoint<Type> tr;
|
PIPoint<Type> tr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
PICout operator <<(PICout & s, const PIRect<Type> & v) {
|
PICout operator <<(PICout & s, const PIRect<Type> & v) {
|
||||||
s.setControl(0, true);
|
s.setControl(0, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user