39#ifndef BOOSTINTERFACE_H_
40 #define BOOSTINTERFACE_H_
46 #include <boost/geometry.hpp>
47 #include <boost/geometry/geometries/segment.hpp>
48 #include <boost/geometry/geometries/linestring.hpp>
49 #include <boost/geometry/geometries/point_xy.hpp>
50 #include <boost/geometry/geometries/polygon.hpp>
51 #include <boost/geometry/multi/geometries/multi_point.hpp>
52 #include <boost/geometry/multi/geometries/multi_polygon.hpp>
54 #include <boost/foreach.hpp>
56 #include <boost/numeric/ublas/matrix.hpp>
62typedef boost :: geometry :: model :: d2 :: point_xy< double >bPoint2;
65typedef boost :: geometry :: model :: segment< bPoint2 >bSeg2;
68typedef boost :: geometry :: model :: linestring< bPoint2 >bLine2;
71typedef boost :: numeric :: ublas :: matrix< double >bMatrix;
77inline double bDist(
const bPoint2 &iP1,
const bPoint2 &iP2) {
return boost :: geometry :: distance(iP1, iP2); }
80inline double bDist(
const bPoint2 &iP,
const bLine2 &iL) {
return boost :: geometry :: distance(iP, iL); }
83inline double bDist(
const bPoint2 &iP,
const bSeg2 &iL) {
return boost :: geometry :: distance(iP, iL); }
86inline double bDist(
const bSeg2 &iLS1,
const bSeg2 &iLS2, bPoint2 *oIntersectionPoint = NULL);
92inline bool bOverlap(
const bPoint2 &iLC1,
const bPoint2 &iUC1,
const bPoint2 &iLC2,
const bPoint2 &iUC2);
97inline double bDot(
const bPoint2 &iP1,
const bPoint2 &iP2) {
return boost :: geometry :: dot_product(iP1, iP2); }
99inline double bNorm(
const bPoint2 &iP1) {
return sqrt( iP1.x() * iP1.x() + iP1.y() * iP1.y() ); }
100inline void bNormalized(bPoint2 &ioP);
103inline bool bSolve2by2(
const bMatrix &iA,
const bPoint2 &ib, bPoint2 &ox);
131inline double bDist(
const bSeg2 &iLS1,
const bSeg2 &iLS2, bPoint2 *oIntersectionPoint)
133 bPoint2 pSpE( iLS1.second.x() - iLS1.first.x(), iLS1.second.y() - iLS1.first.y() );
134 double l1 = bNorm(pSpE);
135 bPoint2 n1(pSpE.x() / l1, pSpE.y() / l1);
137 bPoint2 qSqE( iLS2.second.x() - iLS2.first.x(), iLS2.second.y() - iLS2.first.y() );
138 double l2 = bNorm(qSqE);
139 bPoint2 n2(qSqE.x() / l2, qSqE.y() / l2);
142 bPoint2 psqs( iLS2.first.x() - iLS1.first.x(), iLS2.first.y() - iLS1.first.y() );
143 bPoint2 b( 2.0 * l1 * bDot(psqs, n1), -2.0 * l2 * bDot(psqs, n2) );
147 A(0, 0) = 2.0 * l1 * l1;
148 A(0, 1) = -2.0 *l1 *l2 *bDot(n1, n2);
150 A(1, 1) = 2.0 * l2 * l2;
157 if ( bSolve2by2(A, b, x) ) {
175 bPoint2 p( ( 1.0 - x.x() ) * iLS1.first.x() + x.x() * iLS1.second.x(), ( 1.0 - x.x() ) * iLS1.first.y() + x.x() * iLS1.second.y() );
176 bPoint2 q( ( 1.0 - x.y() ) * iLS2.first.x() + x.y() * iLS2.second.x(), ( 1.0 - x.y() ) * iLS2.first.y() + x.y() * iLS2.second.y() );
178 if ( oIntersectionPoint != NULL ) {
179 oIntersectionPoint->x( 0.5 * ( p.x() + q.x() ) );
180 oIntersectionPoint->y( 0.5 * ( p.y() + q.y() ) );
192 bPoint2 p( iLS1.first.x(), iLS1.first.y() );
193 return bDist(p, iLS2);
197inline bool bOverlap(
const bPoint2 &iLC1,
const bPoint2 &iUC1,
const bPoint2 &iLC2,
const bPoint2 &iUC2)
199 if ( iUC1.x() > iLC2.x() && iUC1.y() > iLC2.y() ) {
200 if ( iLC1.x() < iUC2.x() && iLC1.y() < iUC2.y() ) {
208inline void bNormalized(bPoint2 &ioP)
210 double l = bNorm(ioP);
216inline bool bSolve2by2(
const bMatrix &iA,
const bPoint2 &ib, bPoint2 &ox)
218 double tol = 1.0e-12;
219 double det = iA(0, 0) * iA(1, 1) - iA(0, 1) * iA(1, 0);
221 if ( fabs(det) > tol ) {
222 ox.x( ( iA(1, 1) * ib.x() - iA(0, 1) * ib.y() ) / det );
223 ox.y( ( -iA(1, 0) * ib.x() + iA(0, 0) * ib.y() ) / det );
double det(const FloatMatrixF< 2, 2 > &mat)
Computes the determinant.