diff --git a/shapes/Shape.cc b/shapes/Shape.cc index e46e478..4ed75c8 100755 --- a/shapes/Shape.cc +++ b/shapes/Shape.cc @@ -2,6 +2,7 @@ #include "Shape.h" #include /* sort() */ #include /* binary_function */ +#include using namespace std; Shape::Shape() @@ -14,6 +15,25 @@ 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) @@ -33,25 +53,7 @@ Shape::IntersectionList::merge(const IntersectionList & other, result.add(other.m_intersections[i]); } - class Comparator : public binary_function - { - 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)); + sort(result.begin(), result.end(), IntersectionComparator(startPoint)); return result; }