got Shape::IntersectionList::merge() to sort the result with IntersectionComparator successfully
git-svn-id: svn://anubis/fart/trunk@150 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
25d6432dbd
commit
7d64dd745d
@ -2,6 +2,7 @@
|
|||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
#include <algorithm> /* sort() */
|
#include <algorithm> /* sort() */
|
||||||
#include <functional> /* binary_function */
|
#include <functional> /* binary_function */
|
||||||
|
#include <utility>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Shape::Shape()
|
Shape::Shape()
|
||||||
@ -14,6 +15,25 @@ Shape::~Shape()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class IntersectionComparator : public std::binary_function<Shape::Intersection,
|
||||||
|
Shape::Intersection,
|
||||||
|
bool>
|
||||||
|
{
|
||||||
|
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
|
||||||
Shape::IntersectionList::merge(const IntersectionList & other,
|
Shape::IntersectionList::merge(const IntersectionList & other,
|
||||||
const Vector & startPoint)
|
const Vector & startPoint)
|
||||||
@ -33,25 +53,7 @@ Shape::IntersectionList::merge(const IntersectionList & other,
|
|||||||
result.add(other.m_intersections[i]);
|
result.add(other.m_intersections[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Comparator : public binary_function<Intersection,
|
sort(result.begin(), result.end(), IntersectionComparator(startPoint));
|
||||||
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user