16 #ifndef QGSGEOMETRYUTILS_H 17 #define QGSGEOMETRYUTILS_H 55 static double sqrDistToLine(
double ptX,
double ptY,
double x1,
double y1,
double x2,
double y2,
double& minDistX,
double& minDistY,
double epsilon );
89 double nx = s2.
y() - s1.
y();
90 double ny = -( s2.
x() - s1.
x() );
91 double t = ( p.
x() * ny - p.
y() * nx - s1.
x() * ny + s1.
y() * nx ) / (( s2.
x() - s1.
x() ) * ny - ( s2.
y() - s1.
y() ) * nx );
92 return t < 0. ? s1 : t > 1. ? s2 :
QgsPointV2( s1.
x() + ( s2.
x() - s1.
x() ) * t, s1.
y() + ( s2.
y() - s1.
y() ) * t );
114 static double leftOfLine(
double x,
double y,
double x1,
double y1,
double x2,
double y2 );
121 static double ccwAngle(
double dy,
double dx );
125 double& centerX,
double& centerY );
128 static bool circleClockwise(
double angle1,
double angle2,
double angle3 );
131 static bool circleAngleBetween(
double angle,
double angle1,
double angle2,
bool clockwise );
136 static bool angleOnCircle(
double angle,
double angle1,
double angle2,
double angle3 );
139 static double circleLength(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
142 static double sweepAngle(
double centerX,
double centerY,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
168 static double normalizedAngle(
double angle );
177 static double lineAngle(
double x1,
double y1,
double x2,
double y2 );
187 static double linePerpendicularAngle(
double x1,
double y1,
double x2,
double y2 );
190 static double averageAngle(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
197 static double averageAngle(
double a1,
double a2 );
220 double minDistSegmentX = 0.0, minDistSegmentY = 0.0;
222 bool minDistLeftOf =
false;
223 double sqrDist = 0.0;
224 int vertexOffset = 0;
228 for (
int i = 0; i < container.size(); ++i )
230 sqrDist = container.at( i )->closestSegment( pt, segmentPt, vertexAfter, leftOf, epsilon );
231 if ( sqrDist >= 0 && sqrDist < minDist )
234 minDistSegmentX = segmentPt.
x();
235 minDistSegmentY = segmentPt.
y();
236 minDistVertexAfter = vertexAfter;
237 minDistVertexAfter.
vertex = vertexAfter.
vertex + vertexOffset;
238 minDistVertexAfter.
part = vertexAfter.
part + partOffset;
239 minDistVertexAfter.
ring = vertexAfter.
ring + ringOffset;
246 if ( ctype == VERTEX )
249 vertexOffset += container.at( i )->nCoordinates() - 1;
251 else if ( ctype == RING )
255 else if ( ctype == PART )
264 segmentPt.
setX( minDistSegmentX );
265 segmentPt.
setY( minDistSegmentY );
266 vertexAfter = minDistVertexAfter;
269 *leftOf = minDistLeftOf;
275 #endif // QGSGEOMETRYUTILS_H
Abstract base class for all geometries.
void setX(double x)
Sets the point's x-coordinate.
static double closestSegmentFromComponents(T &container, componentType ctype, const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon)
static QgsPointV2 projPointOnSegment(const QgsPointV2 &p, const QgsPointV2 &s1, const QgsPointV2 &s2)
Project the point on a segment.
double y() const
Returns the point's y-coordinate.
void setY(double y)
Sets the point's y-coordinate.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Contains various geometry utility functions.
Utility class for identifying a unique vertex within a geometry.
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
double x() const
Returns the point's x-coordinate.
bool ANALYSIS_EXPORT lineIntersection(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Returns true, if line1 (p1 to p2) and line2 (p3 to p4) intersect.
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
A class to represent a vector.
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'.