#ifndef SDLPP_HPP_LINE #define SDLPP_HPP_LINE #include "sdlpp_common.hpp" #include "sdlpp_vector.hpp" #include namespace SDLPP { template class SDLPPSCOPE Line { public: Line() = delete; ~Line() = default; Line( const Vec2D &start, const Vec2D &end ) : _start( start ), _end( end ) { updateMost(); } Line( T x_1, T y_1, T x_2, T y_2 ) : Line( { x_1, y_1 }, { x_2, y_2 } ) {} Line( const Vec2D &start, const Vec2D &end, bool infinite ) : Line( start, end ), _infinite( infinite ) {} Line( T x_1, T y_1, T x_2, T y_2, bool infinite ) : Line( { x_1, y_1 }, { x_2, y_2 }, infinite ) {} Line(const Line &input) : Line(input.getStart(), input.getEnd()) {} Line &operator=(const Line &input) { _start = input.getStart(); _end = input.getEnd(); updateMost(); return *this; } void updateMost() { if(_start.getY() < _end.getY()) { top = &_start; bottom = &_end; } else { top = &_end; bottom = &_start; } if(_start.getX() < _end.getX()) { left = &_start; right = &_end; } else { left = &_end; right = &_start; } } const Vec2D &getStart() const { return _start; } const Vec2D &getEnd() const { return _end; } double length() const { return vecDistance( _start, _end ); } double lengthSquared() const { return vecDistanceSquared( _start, _end ); } void setInfinite( bool infinite ) { _infinite = infinite; } bool isInfinite() { return _infinite; } void add(const Vec2D &vec) { _start += vec; _end += vec; } const Vec2D &topmost() const { return *top; } const Vec2D &bottomost() const { return *bottom; } const Vec2D &leftmost() const { return *left; } const Vec2D &rightmost() const { return *right; } private: Vec2D _start; Vec2D _end; Vec2D *top = nullptr; Vec2D *bottom = nullptr; Vec2D *left = nullptr; Vec2D *right = nullptr; bool _infinite = false; }; } // namespace SDLPP #endif