66 lines
1.7 KiB
C++
Executable File
66 lines
1.7 KiB
C++
Executable File
|
|
#include "Shape.h"
|
|
#include <algorithm> /* sort() */
|
|
#include <functional> /* binary_function */
|
|
#include <utility>
|
|
using namespace std;
|
|
|
|
static refptr<Material> default_material;
|
|
static bool default_material_initialized = false;
|
|
|
|
Shape::Shape()
|
|
{
|
|
if (default_material_initialized == false)
|
|
{
|
|
default_material = new Material();
|
|
default_material_initialized = true;
|
|
}
|
|
m_material = default_material;
|
|
}
|
|
|
|
Shape::~Shape()
|
|
{
|
|
}
|
|
|
|
class BoolIntersectionComparator
|
|
: public std::binary_function<Shape::BoolIntersection,
|
|
Shape::BoolIntersection,
|
|
bool>
|
|
{
|
|
public:
|
|
BoolIntersectionComparator(const Vector & refPoint)
|
|
{
|
|
m_refPoint = refPoint;
|
|
}
|
|
bool operator()(const Shape::BoolIntersection & i1,
|
|
const Shape::BoolIntersection & i2) const
|
|
{
|
|
return (m_refPoint.dist_to(i1.intersection.vector)
|
|
< m_refPoint.dist_to(i2.intersection.vector));
|
|
}
|
|
protected:
|
|
Vector m_refPoint;
|
|
};
|
|
|
|
Shape::BoolIntersectionList::BoolIntersectionList(const IntersectionList & l1,
|
|
const IntersectionList & l2,
|
|
const Vector & startPoint)
|
|
{
|
|
for (size_t i = 0, sz = l1.size();
|
|
i < sz;
|
|
i++)
|
|
{
|
|
m_intersections.push_back( BoolIntersection(l1[i], true) );
|
|
}
|
|
for (size_t i = 0, sz = l2.size();
|
|
i < sz;
|
|
i++)
|
|
{
|
|
m_intersections.push_back( BoolIntersection(l2[i], false) );
|
|
}
|
|
|
|
sort(m_intersections.begin(),
|
|
m_intersections.end(),
|
|
BoolIntersectionComparator(startPoint));
|
|
}
|