/*! \file pirect.h * \ingroup Math * \brief * \~english Two-dimensional line class * \~russian Класс отрезка двумерной линии */ /* PIP - Platform Independent Primitives Two-dimensional line class Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef PILINE_H #define PILINE_H #include "pipoint.h" /*! \brief * \~english Two-dimensional line class * \~russian Класс отрезка двумерной линии * \~\details * \~russian * Этот класс описывает линию на плоскости в прямоугольной системе координат */ template class PIP_EXPORT PILine { static_assert(std::is_arithmetic::value, "Type must be arithmetic"); public: PIPoint p0; PIPoint p1; //! PILine() {} //! PILine(const PIPoint & p0_, const PIPoint & p1_) { p0 = p0_; p1 = p1_; } //! PILine(Type x0, Type y0, Type x1, Type y1) { p0.set(x0, y0); p1.set(x1, y1); } //! PILine & set(const PIPoint & p0_, const PIPoint & p1_) { p0 = p0_; p1 = p1_; return *this; } //! PILine & 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(p1.x - p0.x);} //! Type height() const {return piAbs(p1.y - p0.y);} //! PILine & translate(Type x, Type y) { p0.translate(x, y); p1.translate(x, y); return *this; } //! PILine & translate(const PIPoint & p) { p0.translate(p); p1.translate(p); return *this; } //! PILine translated(Type x, Type y) const { PILine l(*this); l.translate(x, y); return l; } //! PILine translated(const PIPoint & p) const { PILine l(*this); l.translate(p); return l; } //! PILine & move(Type x, Type y) {return translate(x, y);} //! PILine & move(const PIPoint & p) {return translate(p);} //! PILine moved(Type x, Type y) const { PILine l(*this); l.translate(x, y); return l; } //! PILine moved(const PIPoint & p) const { PILine l(*this); l.translate(p); return l; } //! void operator +=(Type x) {translate(x, x);} //! void operator +=(const PIPoint & p) {translate(p);} //! void operator -=(Type x) {translate(-x, -x);} //! void operator -=(const PIPoint & p) {translate(-p);} //! PILine operator +(const PIPoint & p) {return translated(p);} //! PILine operator -(const PIPoint & p) {return translated(-p);} //! bool operator ==(const PILine & r) const {return (p0 == r.p0 && p1 == r.p1);} //! bool operator !=(const PILine & r) const {return (p1 != r.p1 || p1 != r.p1);} }; template PICout operator <<(PICout & s, const PILine & v) { s.setControl(0, true); s << "Line{" << v.p0 << ", " << v.p1 << "}"; s.restoreControl(); return s; } typedef PILine PILinei; typedef PILine PILineu; typedef PILine PILinef; typedef PILine PILined; #endif // PILINE_H