16 #ifndef QGSGEOMETRYUTILS_H 17 #define QGSGEOMETRYUTILS_H 78 static double sqrDistToLine(
double ptX,
double ptY,
double x1,
double y1,
double x2,
double y2,
double& minDistX,
double& minDistY,
double epsilon );
112 double nx = s2.
y() - s1.
y();
113 double ny = -( s2.
x() - s1.
x() );
114 double t = ( p.
x() * ny - p.
y() * nx - s1.
x() * ny + s1.
y() * nx ) / (( s2.
x() - s1.
x() ) * ny - ( s2.
y() - s1.
y() ) * nx );
115 return t < 0. ? s1 : t > 1. ? s2 :
QgsPointV2( s1.
x() + ( s2.
x() - s1.
x() ) * t, s1.
y() + ( s2.
y() - s1.
y() ) * t );
137 static double leftOfLine(
double x,
double y,
double x1,
double y1,
double x2,
double y2 );
144 static double ccwAngle(
double dy,
double dx );
148 double& centerX,
double& centerY );
151 static bool circleClockwise(
double angle1,
double angle2,
double angle3 );
154 static bool circleAngleBetween(
double angle,
double angle1,
double angle2,
bool clockwise );
159 static bool angleOnCircle(
double angle,
double angle1,
double angle2,
double angle3 );
162 static double circleLength(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
165 static double sweepAngle(
double centerX,
double centerY,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
191 static double normalizedAngle(
double angle );
200 static double lineAngle(
double x1,
double y1,
double x2,
double y2 );
210 static double linePerpendicularAngle(
double x1,
double y1,
double x2,
double y2 );
213 static double averageAngle(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
220 static double averageAngle(
double a1,
double a2 );
243 double minDistSegmentX = 0.0, minDistSegmentY = 0.0;
245 bool minDistLeftOf =
false;
246 double sqrDist = 0.0;
247 int vertexOffset = 0;
251 for (
int i = 0; i < container.size(); ++i )
253 sqrDist = container.at( i )->closestSegment( pt, segmentPt, vertexAfter, leftOf, epsilon );
254 if ( sqrDist >= 0 && sqrDist < minDist )
257 minDistSegmentX = segmentPt.
x();
258 minDistSegmentY = segmentPt.
y();
259 minDistVertexAfter = vertexAfter;
260 minDistVertexAfter.
vertex = vertexAfter.
vertex + vertexOffset;
261 minDistVertexAfter.
part = vertexAfter.
part + partOffset;
262 minDistVertexAfter.
ring = vertexAfter.
ring + ringOffset;
269 if ( ctype == VERTEX )
272 vertexOffset += container.at( i )->nCoordinates() - 1;
274 else if ( ctype == RING )
278 else if ( ctype == PART )
287 segmentPt.
setX( minDistSegmentX );
288 segmentPt.
setY( minDistSegmentY );
289 vertexAfter = minDistVertexAfter;
292 *leftOf = minDistLeftOf;
298 #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'.