Pure geometry helpers for map editing: ring validation, interior points and related checks, with no GUI, OGR or engine dependency. More...
Classes | |
| struct | RingPolygon |
| A polygon: exactly one exterior ring + zero-or-more interior rings. More... | |
Enumerations | |
| enum class | RingValidity { Ok , TooFewVertices , SelfIntersecting , HoleOutsideExterior , HolesOverlap } |
| Validity classes for a RingPolygon (in-house checks, no GEOS). More... | |
Functions | |
| QVector< QPointF > | cleanPolyline (const QVector< QPointF > &v, double tol=kCoincidenceTol) |
| Drop consecutive coincident points from a polyline. | |
| QVector< QPointF > | cleanPolygonRing (const QVector< QPointF > &v, double tol=kCoincidenceTol) |
| Normalize a polygon ring: collapse coincident points and drop a redundant explicit closing vertex. | |
| QVector< QPointF > | orientInteriorToEndpoints (QVector< QPointF > interior, const QPointF &from, const QPointF &to) |
Orient a link's interior bend points to run from from toward to. | |
| double | polylineLength (const QVector< QPointF > &vertices) |
| Compute the total length of a polyline. | |
| QVector< QPointF > | replacedAt (const QVector< QPointF > &vertices, int index, const QPointF &newPt) |
| Replace one endpoint of a polyline, producing a new vector. | |
| QVector< QPointF > | insertedAt (const QVector< QPointF > &vertices, int index, const QPointF &newPt) |
Insert a vertex at index, producing a new polyline of size+1. | |
| QVector< QPointF > | removedAt (const QVector< QPointF > &vertices, int index) |
Remove the vertex at index, producing a new polyline of size-1. | |
| double | distanceToPolyline (const QVector< QPointF > &vertices, const QPointF &point, int *segmentIndex=nullptr, QPointF *closestPoint=nullptr) |
| Distance from a point to the nearest point on a polyline segment. | |
| double | polygonArea (const QVector< QPointF > &polygon) |
| Compute the area of a polygon using the shoelace formula. | |
| double | signedRingArea (const QVector< QPointF > &ring) |
| Signed area of a ring via the shoelace formula. | |
| bool | pointInRing (const QVector< QPointF > &ring, const QPointF &pt) |
| Even-odd point-in-ring test (boundary result is unspecified but stable). | |
| RingPolygon | normalizeRingPolygon (RingPolygon p, double tol=kCoincidenceTol) |
| Clean every ring (dedupe + de-close), drop degenerate interior rings, and orient exterior CCW / interiors CW. | |
| double | netArea (const RingPolygon &p) |
| Net area = |exterior| − Σ|holes|, clamped to >= 0. | |
| bool | containsPoint (const RingPolygon &p, const QPointF &pt) |
True when pt is inside the exterior and outside every hole. | |
| QPointF | interiorPoint (const QVector< QPointF > &ring) |
| A point guaranteed strictly interior to a simple ring — robust for non-convex rings — suitable as a triangulation hole/region seed. | |
| RingValidity | validateRingPolygon (const RingPolygon &p) |
| Validate a RingPolygon with in-house geometry checks (O(n^2) edge tests; intended for hand-digitized / GIS-sourced rings). | |
Variables | |
| constexpr double | kCoincidenceTol = 1e-6 |
| Default coincidence tolerance, in layer-CRS units. | |
Pure geometry helpers for map editing: ring validation, interior points and related checks, with no GUI, OGR or engine dependency.
|
strong |
Validity classes for a RingPolygon (in-house checks, no GEOS).
|
nodiscard |
Normalize a polygon ring: collapse coincident points and drop a redundant explicit closing vertex.
Runs the same consecutive-duplicate collapse as cleanPolyline(), then strips a trailing point that coincides with the first vertex so the result is an OPEN ring (matching the SWMM [POLYGONS] storage convention, where the closing edge is implicit).
| v | Ordered polygon vertices (open or explicitly closed). |
| tol | Coincidence tolerance in the input coordinate units. |
|
nodiscard |
Drop consecutive coincident points from a polyline.
Each point within tol of the previous kept point is removed, so a run of three or more duplicates collapses to one. The first point is always kept; order and shape are otherwise preserved. Inputs with fewer than two points are returned unchanged.
| v | Ordered polyline vertices. |
| tol | Coincidence tolerance in the input coordinate units. Two points are coincident when their squared distance is <= tol*tol. |
|
nodiscard |
True when pt is inside the exterior and outside every hole.
| [in] | p | Polygon in the query frame. |
| [in] | pt | Point tested against the exterior and each interior ring. |
|
nodiscard |
Distance from a point to the nearest point on a polyline segment.
| [out] | segmentIndex | When non-null, receives the index of the closest segment (0 = first segment between vertices[0] and vertices[1]). |
| [out] | closestPoint | When non-null, receives the closest point on the polyline. |
| [in] | vertices | Ordered polyline vertices, in a common Euclidean coordinate frame. |
| [in] | point | Query coordinate in the same frame. |
On fewer than two vertices, optional outputs are initialized to -1 and a default QPointF. Equal-distance ties retain the first segment.
|
nodiscard |
Insert a vertex at index, producing a new polyline of size+1.
Pass index = vertices.size() to append, 0 to prepend. Out-of-range indices are clamped.
| [in] | vertices | Source polyline, unchanged by this operation. |
| [in] | index | Insertion position clamped to [0, vertices.size()]. |
| [in] | newPt | Coordinate in the same frame as the source. |
|
nodiscard |
A point guaranteed strictly interior to a simple ring — robust for non-convex rings — suitable as a triangulation hole/region seed.
Scans a horizontal line through the ring's vertical midpoint and returns the midpoint of the widest interior span (even-odd rule). Falls back to the vertex centroid only for degenerate input. This replaces the naive vertex-centroid seed, which can fall outside a non-convex ring.
| [in] | ring | Simple ring, open or explicitly closed, in a Euclidean frame. |
|
nodiscard |
Net area = |exterior| − Σ|holes|, clamped to >= 0.
| [in] | p | Polygon with rings expressed in one Euclidean frame. |
|
nodiscard |
Clean every ring (dedupe + de-close), drop degenerate interior rings, and orient exterior CCW / interiors CW.
| [in] | p | Polygon copied by value; input storage held by the caller is unchanged. |
| [in] | tol | Coincidence tolerance in input coordinate units, as for cleanPolyline(). |
|
nodiscard |
Orient a link's interior bend points to run from from toward to.
GIS-imported SWMM models frequently digitize a link in the opposite sense to its from/to-node assignment, so the [VERTICES] are stored running to→from. The assembled polyline [from, interior…, to] then doubles back on itself and renders as self-crossing "loop" artifacts. This reverses interior when its endpoints sit closer to the opposite nodes (i.e. the first bend is nearer to and the last bend nearer from). Correctly-ordered interiors are returned unchanged, as are inputs with fewer than two points (no ordering ambiguity).
| interior | Interior bend points only (no node endpoints). |
| from | From-node coordinate (polyline start). |
| to | To-node coordinate (polyline end). |
interior, reversed iff it was stored to→from.
|
nodiscard |
Even-odd point-in-ring test (boundary result is unspecified but stable).
Returns false for rings with fewer than 3 vertices.
| [in] | ring | Ordered ring in the same coordinate frame as the query. |
| [in] | pt | Point to classify; no tolerance is applied. |
|
nodiscard |
Compute the area of a polygon using the shoelace formula.
| polygon | Ordered polygon vertices (open or closed; if the last vertex equals the first, the closing edge is not doubled). |
|
nodiscard |
Compute the total length of a polyline.
| vertices | Ordered polyline vertices (any coordinate frame — the caller is responsible for passing points in the frame whose Euclidean distance matches the desired length unit; for SWMM auto-length this is the layer CRS). |
|
nodiscard |
Remove the vertex at index, producing a new polyline of size-1.
vertices when index is out of range. Callers that need a minimum vertex count (subcatchment polygons) enforce it themselves; a link's interior list may legitimately become empty. | [in] | vertices | Source polyline, unchanged by this operation. |
| [in] | index | Zero-based vertex to erase; invalid indexes are ignored. |
|
nodiscard |
Replace one endpoint of a polyline, producing a new vector.
| vertices | Original polyline (read-only). |
| index | Endpoint to replace (0 = first, vertices.size()-1 = last). |
| newPt | Replacement point. |
vertices if index is out of range.
|
nodiscard |
Signed area of a ring via the shoelace formula.
| [in] | ring | Ordered open or explicitly closed ring in a Euclidean frame. |
|
nodiscard |
Validate a RingPolygon with in-house geometry checks (O(n^2) edge tests; intended for hand-digitized / GIS-sourced rings).
| [in] | p | Exterior and holes to inspect without modifying storage. |
|
constexpr |
Default coincidence tolerance, in layer-CRS units.
Targets true / near-exact coincidence and floating-point round-trip noise (e.g. duplicate map clicks, a polygon closing point that repeats the first vertex), NOT visual simplification. Collinear / shape-preserving vertices are intentionally left untouched.