From 7d64dd745d979de76645a7b7cbce672b7e8075d9 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 24 Feb 2009 00:38:09 +0000 Subject: [PATCH] got Shape::IntersectionList::merge() to sort the result with IntersectionComparator successfully git-svn-id: svn://anubis/fart/trunk@150 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- shapes/Shape.cc | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) 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; }