26template <
class Po
intType>
double theta(
const PointType& p1,
const PointType& p2 )
28 typename PointType::value_type dx, dy, ax, ay;
31 dx = p2.x - p1.x; ax =
absval( dx );
32 dy = p2.y - p1.y; ay =
absval( dy );
33 t = (ax+ay == 0) ? 0 : (
double) dy/(ax+ay);
50 bool operator() (
const PointType& p1,
const PointType& p2 )
66template <
class Po
intType,
class CmpFunctor>
typename PointType::value_type
ccw(
const PointType& p0,
const PointType& p1,
const PointType& p2, CmpFunctor& thetaCmp )
68 typename PointType::value_type dx1, dx2, dy1, dy2;
69 typename PointType::value_type theta0( thetaCmp(p0) );
70 typename PointType::value_type theta1( thetaCmp(p1) );
71 typename PointType::value_type theta2( thetaCmp(p2) );
74 if( theta0 == theta1 ||
84 dx1 = p1.x - p0.x; dy1 = p1.y - p0.y;
85 dx2 = p2.x - p0.x; dy2 = p2.y - p0.y;
87 if( dx1*dy2 > dy1*dx2 )
90 if( dx1*dy2 < dy1*dx2 )
93 if( (dx1*dx2 < 0) || (dy1*dy2 < 0) )
96 if( (dx1*dx1 + dy1*dy1) < (dx2*dx2 + dy2*dy2) )
152 const Polygon2D::size_type
N( rPoly.size() );
154 std::copy(rPoly.begin(), rPoly.end(),
result.begin()+1 );
155 Polygon2D::size_type
min,
i;
165 for(
i=1;
i<=
N; ++
i )
186 Polygon2D::size_type
M;
187 for(
M=3,
i=4;
i<=
N; ++
i )
std::vector< Point2D > Polygon2D
NumType absval(NumType x)
ThetaCompare(const PointType &rRefPoint)
bool operator()(const PointType &p1, const PointType &p2)
Polygon2D convexHull(const Polygon2D &rPoly)
double theta(const PointType &p1, const PointType &p2)
PointType::value_type ccw(const PointType &p0, const PointType &p1, const PointType &p2, CmpFunctor &thetaCmp)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)