58 lines
1.4 KiB
C++
Executable File
58 lines
1.4 KiB
C++
Executable File
|
|
#include "Shape.h"
|
|
#include <algorithm> /* sort() */
|
|
#include <functional> /* binary_function */
|
|
using namespace std;
|
|
|
|
Shape::Shape()
|
|
{
|
|
m_transparency = 0.0;
|
|
m_material = new Material(Material::white);
|
|
}
|
|
|
|
Shape::~Shape()
|
|
{
|
|
}
|
|
|
|
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]);
|
|
}
|
|
|
|
class Comparator : public binary_function<Intersection,
|
|
Intersection,
|
|
bool>
|
|
{
|
|
public:
|
|
Comparator(const Vector & refPoint)
|
|
{
|
|
m_refPoint = refPoint;
|
|
}
|
|
bool operator()(Intersection const & i1, Intersection const & i2) const
|
|
{
|
|
return (m_refPoint.dist_to(i1.second)
|
|
< m_refPoint.dist_to(i2.second));
|
|
}
|
|
protected:
|
|
Vector m_refPoint;
|
|
};
|
|
|
|
sort(result.m_intersections.begin(), result.m_intersections.end(), Comparator(startPoint));
|
|
|
|
return result;
|
|
}
|