53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
#ifndef SDLPP_HPP_LINE
|
|
#define SDLPP_HPP_LINE
|
|
|
|
#include "sdlpp_common.hpp"
|
|
#include "sdlpp_vector.hpp"
|
|
|
|
namespace SDLPP {
|
|
template<typename T>
|
|
class SDLPPSCOPE Line {
|
|
public:
|
|
Line() = delete;
|
|
~Line() = default;
|
|
Line( const Vec2D<T> &start, const Vec2D<T> &end )
|
|
: _start( start ), _end( end ) {}
|
|
Line( T x_1, T y_1, T x_2, T y_2 )
|
|
: _start( { x_1, y_1 } ), _end( { x_2, y_2 } ) {}
|
|
Line( const Vec2D<T> &start, const Vec2D<T> &end, bool infinite )
|
|
: _start( start ), _end( end ), _infinite( infinite ) {}
|
|
Line( T x_1, T y_1, T x_2, T y_2, bool infinite )
|
|
: _start( { x_1, y_1 } ), _end( { x_2, y_2 } ),
|
|
_infinite( infinite ) {}
|
|
const Vec2D<T> &getStart() const {
|
|
return _start;
|
|
}
|
|
const Vec2D<T> &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<T> &vec) {
|
|
_start += vec;
|
|
_end += vec;
|
|
}
|
|
|
|
private:
|
|
Vec2D<T> _start;
|
|
Vec2D<T> _end;
|
|
bool _infinite = false;
|
|
};
|
|
} // namespace SDLPP
|
|
|
|
#endif
|