78 static void trimFeature( std::vector<double>& x,
79 std::vector<double>& y,
82 static void trimPolygon( QPolygonF& pts,
const QgsRectangle& clipRect );
88 static unsigned char* clippedLineWKB(
unsigned char* wkb,
const QgsRectangle& clipExtent, QPolygonF& line );
97 static void trimFeatureToBoundary(
const std::vector<double>& inX,
98 const std::vector<double>& inY,
99 std::vector<double>& outX,
100 std::vector<double>& outY,
104 static void trimPolygonToBoundary(
const QPolygonF& inPts, QPolygonF& outPts,
const QgsRectangle& rect,
Boundary b,
double boundaryValue );
107 static bool inside(
const double x,
const double y,
Boundary b );
109 static bool inside(
const QPointF& pt,
Boundary b,
double val );
113 static QgsPoint intersect(
const double x1,
const double y1,
114 const double x2,
const double y2,
117 static QPointF intersectRect(
const QPointF& pt1,
122 static bool clipLineSegment(
double xLeft,
double xRight,
double yBottom,
double yTop,
double& x0,
double& y0,
double& x1,
double& y1 );
132 static void connectSeparatedLines(
double x0,
double y0,
double x1,
double y1,
136 static void clipStartTop(
double& x0,
double& y0,
const double& x1,
const double& y1,
double yMax );
137 static void clipStartBottom(
double& x0,
double& y0,
const double& x1,
const double& y1,
double yMin );
138 static void clipStartRight(
double& x0,
double& y0,
const double& x1,
const double& y1,
double xMax );
139 static void clipStartLeft(
double& x0,
double& y0,
const double& x1,
const double& y1,
double xMin );
140 static void clipEndTop(
const double& x0,
const double& y0,
double& x1,
double& y1,
double yMax );
141 static void clipEndBottom(
const double& x0,
const double& y0,
double& x1,
double& y1,
double yMin );
142 static void clipEndRight(
const double& x0,
const double& y0,
double& x1,
double& y1,
double xMax );
143 static void clipEndLeft(
const double& x0,
const double& y0,
double& x1,
double& y1,
double xMin );
159 std::vector<double>& y,
162 std::vector<double> tmpX;
163 std::vector<double> tmpY;
182 tmpPts.reserve( pts.size() );
199 const std::vector<double>& inX,
200 const std::vector<double>& inY,
201 std::vector<double>& outX,
202 std::vector<double>& outY,
209 unsigned int i1 = inX.size() - 1;
212 for (
unsigned int i2 = 0; i2 < inX.size() ; ++i2 )
217 if ( qIsNaN( inX[i2] ) || qIsNaN( inY[i2] ) || qIsInf( inX[i2] ) || qIsInf( inY[i2] )
218 || qIsNaN( inX[i1] ) || qIsNaN( inY[i1] ) || qIsInf( inX[i1] ) || qIsInf( inY[i1] ) )
225 if (
inside( inX[i2], inY[i2], b ) )
227 if (
inside( inX[i1], inY[i1], b ) )
229 outX.push_back( inX[i2] );
230 outY.push_back( inY[i2] );
236 if ( !( i2 == 0 && shapeOpen ) )
239 outX.push_back( p.
x() );
240 outY.push_back( p.
y() );
243 outX.push_back( inX[i2] );
244 outY.push_back( inY[i2] );
250 if (
inside( inX[i1], inY[i1], b ) )
252 if ( !( i2 == 0 && shapeOpen ) )
255 outX.push_back( p.
x() );
256 outY.push_back( p.
y() );
266 unsigned int i1 = inPts.size() - 1;
269 for (
int i2 = 0; i2 < inPts.size() ; ++i2 )
271 if (
inside( inPts[i2], b, boundaryValue ) )
273 if (
inside( inPts[i1], b, boundaryValue ) )
275 outPts.append( inPts[i2] );
281 outPts.append(
intersectRect( inPts[i1], inPts[i2], b, rect ) );
282 outPts.append( inPts[i2] );
288 if (
inside( inPts[i1], b, boundaryValue ) )
290 outPts.append(
intersectRect( inPts[i1], inPts[i2], b, rect ) );
329 return ( pt.x() < val );
331 return ( pt.x() > val );
333 return ( pt.y() < val );
335 return ( pt.y() > val );
346 const double x2,
const double y2,
379 double r = r_n / r_d;
380 p.
set( x1 + r*( x2 - x1 ), y1 + r*( y2 - y1 ) );
401 const double x1 = pt1.x(), x2 = pt2.x();
402 const double y1 = pt1.y(), y2 = pt2.y();
429 return QPointF( x1 + r*( x2 - x1 ), y1 + r*( y2 - y1 ) );
434 x0 += ( x1 - x0 ) * ( yMax - y0 ) / ( y1 - y0 );
440 x0 += ( x1 - x0 ) * ( yMin - y0 ) / ( y1 - y0 );
446 y0 += ( y1 - y0 ) * ( xMax - x0 ) / ( x1 - x0 );
452 y0 += ( y1 - y0 ) * ( xMin - x0 ) / ( x1 - x0 );
458 x1 += ( x1 - x0 ) * ( yMax - y1 ) / ( y1 - y0 );
464 x1 += ( x1 - x0 ) * ( yMin - y1 ) / ( y1 - y0 );
470 y1 += ( y1 - y0 ) * ( xMax - x1 ) / ( x1 - x0 );
476 y1 += ( y1 - y0 ) * ( xMin - x1 ) / ( x1 - x0 );
481 inline bool QgsClipper::clipLineSegment(
double xLeft,
double xRight,
double yBottom,
double yTop,
double& x0,
double& y0,
double& x1,
double& y1 )
487 else if ( y1 > yTop )
492 else if ( x1 < xLeft )
497 else if ( y0 > yTop )
502 else if ( x0 < xLeft )