code style

This commit is contained in:
Andrey
2022-03-21 12:20:11 +03:00
parent 415160387b
commit 4bae04feec
3 changed files with 262 additions and 51 deletions

View File

@@ -1,16 +1,15 @@
/*! \file pipoint.h
* \ingroup Math
* \brief
* \~english Two-dimensional point class
* \~russian Класс двумерной точки
* \~\authors
* \~english
* Ivan Pelipenko peri4ko@yandex.ru;
* Andrey Bychkov work.a.b@yandex.ru;
* \~russian
* Иван Пелипенко peri4ko@yandex.ru;
* Андрей Бычков work.a.b@yandex.ru;
*/
//! \file pipoint.h
//! \ingroup Math
//! \brief
//! \~english Two-dimensional point class
//! \~russian Класс двумерной точки
//! \~\authors
//! \~english
//! Ivan Pelipenko peri4ko@yandex.ru;
//! Andrey Bychkov work.a.b@yandex.ru;
//! \~russian
//! Иван Пелипенко peri4ko@yandex.ru;
//! Андрей Бычков work.a.b@yandex.ru;
/*
PIP - Platform Independent Primitives
Two-dimensional point class
@@ -31,10 +30,10 @@
#include "pimathbase.h"
/*! \brief
* \~english Two-dimensional point class
* \~russian Класс двумерной точки
*/
//! \brief
//! \~english Two-dimensional point class
//! \~russian Класс двумерной точки
template<typename Type>
class PIP_EXPORT PIPoint {
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
@@ -42,65 +41,109 @@ public:
Type x;
Type y;
//!
PIPoint() {x = y = Type();}
//!
PIPoint(Type x_, Type y_) {set(x_, y_);}
//!
PIPoint<Type> & set(Type x_, Type y_) {
x = x_;
y = y_;
return *this;
}
//!
PIPoint<Type> & set(const PIPoint<Type> & p) {
x = p.x;
y = p.y;
return *this;
}
//!
PIPoint<Type> & translate(Type x_, Type y_) {
x += x_;
y += y_;
return *this;
}
//!
PIPoint<Type> & translate(const PIPoint<Type> & p) {
x += p.x;
y += p.y;
return *this;
}
//!
PIPoint<Type> translated(Type x_, Type y_) const {
PIPoint<Type> rp(*this);
rp.translate(x_, y_);
return rp;
}
//!
PIPoint<Type> translated(const PIPoint<Type> & p) const {
PIPoint<Type> rp(*this);
rp.translate(p);
return rp;
}
//!
PIPoint<Type> & move(Type x_, Type y_) {return translate(x_, y_);}
//!
PIPoint<Type> & move(const PIPoint<Type> & p) {return translate(p);}
//!
PIPoint<Type> moved(Type x_, Type y_) const {
PIPoint<Type> rp(*this);
rp.translate(x_, y_);
return rp;
}
//!
PIPoint<Type> moved(const PIPoint<Type> & p) const {
PIPoint<Type> rp(*this);
rp.translate(p);
return rp;
}
//!
double angleRad() const {return 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());}
//!
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);}
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);}
};