Add a constructor to make a Line from x1,y1-x2,y2 coordinates.

Also allow to retrieve the internal points using the [] operator.
This commit is contained in:
King_DuckZ 2014-08-22 10:50:50 +02:00
parent 78734f6ad3
commit c4fbdd8e16
2 changed files with 16 additions and 0 deletions

View file

@ -22,6 +22,8 @@
#include "vector.hpp"
#include "vectormath.hpp"
#include <ciso646>
#include <cstdint>
namespace cloonel {
template <typename T, uint32_t S>
@ -35,6 +37,7 @@ namespace cloonel {
Line ( const Line& parOther );
Line ( const Point& parStart, const Point& parEnd );
Line ( const Point& parStart, const Point& parDirection, Scalar parLength ) : Line(parStart, parStart + parDirection * parLength) { }
Line ( Scalar parX1, Scalar parY1, Scalar parX2, Scalar parY2 );
~Line ( void ) noexcept = default;
Point& Start ( void ) { return m_points.x(); }
@ -42,6 +45,11 @@ namespace cloonel {
const Point& Start ( void ) const { return m_points.x(); }
const Point& End ( void ) const { return m_points.y(); }
Point& operator[] ( int parIndex ) { assert(parIndex >= 0); return m_points[static_cast<uint32_t>(parIndex)]; }
const Point& operator[] ( int parIndex ) const { assert(parIndex >= 0); return m_points[static_cast<uint32_t>(parIndex)]; }
Point& operator[] ( uint32_t parIndex ) { return m_points[parIndex]; }
const Point& operator[] ( uint32_t parIndex ) const { return m_points[parIndex]; }
Line& operator+= ( const Point& parRhs ) __attribute__((flatten));
Line& operator-= ( const Point& parRhs ) __attribute__((flatten));
template <typename U>

View file

@ -23,6 +23,14 @@ namespace cloonel {
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, uint32_t S>
Line<T, S>::Line (Scalar parX1, Scalar parY1, Scalar parX2, Scalar parY2) :
m_points(Point(parX1, parY1), Point(parX2, parY2))
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
template <typename T, uint32_t S>