#include "Shape.h" #include /* sort() */ #include /* binary_function */ #include using namespace std; Shape::Shape() { m_transparency = 0.0; m_material = new Material(Material::white); } Shape::~Shape() { } class IntersectionComparator : public std::binary_function { public: IntersectionComparator(const Vector & refPoint) { m_refPoint = refPoint; } bool operator()(const Shape::Intersection & i1, const Shape::Intersection & i2) const { return (m_refPoint.dist_to(i1.second) < m_refPoint.dist_to(i2.second)); } protected: Vector m_refPoint; }; Shape::IntersectionList Shape::IntersectionList::merge(const IntersectionList & other, const Vector & startPoint) { Shape::IntersectionList result; for (size_t i = 0, sz = m_intersections.size(); i < sz; i++) { result.add(m_intersections[i]); } for (size_t i = 0, sz = other.m_intersections.size(); i < sz; i++) { result.add(other.m_intersections[i]); } sort(result.begin(), result.end(), IntersectionComparator(startPoint)); return result; }