code style
This commit is contained in:
@@ -34,6 +34,14 @@
|
||||
|
||||
#include "pipoint.h"
|
||||
|
||||
|
||||
/*! \brief
|
||||
* \~english Two-dimensional line class
|
||||
* \~russian Класс отрезка двумерной линии
|
||||
* \~\details
|
||||
* \~russian
|
||||
* Этот класс описывает линию на плоскости в прямоугольной системе координат
|
||||
*/
|
||||
template<typename Type>
|
||||
class PIP_EXPORT PILine {
|
||||
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||
@@ -41,82 +49,120 @@ public:
|
||||
PIPoint<Type> p0;
|
||||
PIPoint<Type> p1;
|
||||
|
||||
//!
|
||||
PILine() {}
|
||||
|
||||
//!
|
||||
PILine(const PIPoint<Type> & p0_, const PIPoint<Type> & p1_) {
|
||||
p0 = p0_;
|
||||
p1 = p1_;
|
||||
}
|
||||
|
||||
//!
|
||||
PILine(Type x0, Type y0, Type x1, Type y1) {
|
||||
p0.set(x0, y0);
|
||||
p1.set(x1, y1);
|
||||
}
|
||||
|
||||
//!
|
||||
PILine<Type> & set(const PIPoint<Type> & p0_, const PIPoint<Type> & p1_) {
|
||||
p0 = p0_;
|
||||
p1 = p1_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//!
|
||||
PILine<Type> & set(Type x0, Type y0, Type x1, Type y1) {
|
||||
p0.set(x0, y0);
|
||||
p1.set(x1, y1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//!
|
||||
bool isEmpty() const {
|
||||
return (p0 == p1);
|
||||
}
|
||||
|
||||
//!
|
||||
Type width() const {return piAbs<Type>(p1.x - p0.x);}
|
||||
|
||||
//!
|
||||
Type height() const {return piAbs<Type>(p1.y - p0.y);}
|
||||
|
||||
//!
|
||||
PILine<Type> & translate(Type x, Type y) {
|
||||
p0.translate(x, y);
|
||||
p1.translate(x, y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//!
|
||||
PILine<Type> & translate(const PIPoint<Type> & p) {
|
||||
p0.translate(p);
|
||||
p1.translate(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//!
|
||||
PILine<Type> translated(Type x, Type y) const {
|
||||
PILine<Type> l(*this);
|
||||
l.translate(x, y);
|
||||
return l;
|
||||
}
|
||||
|
||||
//!
|
||||
PILine<Type> translated(const PIPoint<Type> & p) const {
|
||||
PILine<Type> l(*this);
|
||||
l.translate(p);
|
||||
return l;
|
||||
}
|
||||
|
||||
//!
|
||||
PILine<Type> & move(Type x, Type y) {return translate(x, y);}
|
||||
|
||||
//!
|
||||
PILine<Type> & move(const PIPoint<Type> & p) {return translate(p);}
|
||||
|
||||
//!
|
||||
PILine<Type> moved(Type x, Type y) const {
|
||||
PILine<Type> l(*this);
|
||||
l.translate(x, y);
|
||||
return l;
|
||||
}
|
||||
|
||||
//!
|
||||
PILine<Type> moved(const PIPoint<Type> & p) const {
|
||||
PILine<Type> l(*this);
|
||||
l.translate(p);
|
||||
return l;
|
||||
}
|
||||
|
||||
//!
|
||||
void operator +=(Type x) {translate(x, x);}
|
||||
|
||||
//!
|
||||
void operator +=(const PIPoint<Type> & p) {translate(p);}
|
||||
|
||||
//!
|
||||
void operator -=(Type x) {translate(-x, -x);}
|
||||
|
||||
//!
|
||||
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);}
|
||||
|
||||
//!
|
||||
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);}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename Type>
|
||||
PICout operator <<(PICout & s, const PILine<Type> & v) {
|
||||
s.setControl(0, true);
|
||||
|
||||
Reference in New Issue
Block a user