Just now quickly I made a LineVolume class that's for an assignment at school but with some modifications(like making the line calculation internal) it would be possible to use it like I intended and place it at the wiki.
#ifndef VOLUME_HEADER_
#define VOLUME_HEADER_
#include <vector>
// LineVolume inherits from this class. I made it like this as in the
// assignment we also had to create a PlaneVolume with the same
// functionallity but using planes as the primitive instead.
template<class Primitive, class VectorType>
class Volume
{
public:
Volume()
{
}
Volume(const std::vector<Primitive> &aList)
{
myList = aList;
}
~Volume()
{
}
void Add(const Primitive &aPrimitive)
{
myList.push_back(aPrimitive);
}
void Remove(const Primitive &aPrimitive)
{
for(std::vector<Primitive>::iterator it = myList.begin(), end = myList.end(); it != end; it++)
{
if(*it == aPrimitive)
{
myList.erase(it);
break;
}
}
}
bool Inside(const VectorType &aPoint) const
{
for(std::vector<Primitive>::const_iterator it = myList.begin(), end = myList.end(); it != end; it++)
{
if(it->Inside(aPoint) == false)
{
return false;
}
}
return true;
}
private:
std::vector<Primitive> myList;
};
#endif VOLUME_HEADER_
#ifndef LINE_HEADER_
#define LINE_HEADER_
#include "Vector2.h"
template<class Type>
class Line
{
public:
Line() {}
Line(const Vector2<Type> &aPoint, const Vector2<Type> &aSecondPoint)
{
InitWith2Points(aPoint, aSecondPoint);
}
void InitWith2Points(const Vector2<Type> &aPoint, const Vector2<Type> &aSecondPoint)
{
myPoint = aPoint;
myDirection = aSecondPoint - aPoint;
myDirection /= myDirection.Length();
}
void InitWithPointAndDirection(const Vector2<Type> &aPoint, const Vector2<Type> &aDirection)
{
myPoint = aPoint;
myDirection = aDirection;
}
bool Inside(const Vector2<Type> &aPoint) const
{
Vector2<Type> normal;
normal.x = -myDirection.y;
normal.y = myDirection.x;
Vector2<Type> testPosition = aPoint - myPoint;
testPosition /= testPosition.Length();
return normal.Dot(testPosition) > 0;
}
bool operator==(const Line<Type> aLine)
{
return myPoint == aLine.myPoint && myDirection == aLine.myDirection;
}
private:
Vector2<Type> myPoint;
Vector2<Type> myDirection;
};
#endif LINE_HEADER_