Loading...
Searching...
No Matches
EditGeometry Namespace Reference

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.
 

Detailed Description

Pure geometry helpers for map editing: ring validation, interior points and related checks, with no GUI, OGR or engine dependency.

Enumeration Type Documentation

◆ RingValidity

enum class EditGeometry::RingValidity
strong

Validity classes for a RingPolygon (in-house checks, no GEOS).

Enumerator
Ok 

Every check passed.

TooFewVertices 

Exterior or a hole has < 3 vertices.

SelfIntersecting 

Exterior or a hole crosses itself.

HoleOutsideExterior 

A hole escapes / crosses the exterior.

HolesOverlap 

Two holes overlap or nest.

Function Documentation

◆ cleanPolygonRing()

QVector< QPointF > EditGeometry::cleanPolygonRing ( const QVector< QPointF > & v,
double tol = kCoincidenceTol )
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).

Parameters
vOrdered polygon vertices (open or explicitly closed).
tolCoincidence tolerance in the input coordinate units.
Returns
Cleaned open ring. May contain fewer than three distinct points when the input is degenerate — the caller decides how to handle it.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanPolyline()

QVector< QPointF > EditGeometry::cleanPolyline ( const QVector< QPointF > & v,
double tol = kCoincidenceTol )
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.

Parameters
vOrdered polyline vertices.
tolCoincidence tolerance in the input coordinate units. Two points are coincident when their squared distance is <= tol*tol.
Returns
Cleaned polyline. May contain fewer than two distinct points when the whole input collapses — the caller decides how to handle that.
Here is the caller graph for this function:

◆ containsPoint()

bool EditGeometry::containsPoint ( const RingPolygon & p,
const QPointF & pt )
nodiscard

True when pt is inside the exterior and outside every hole.

Parameters
[in]pPolygon in the query frame.
[in]ptPoint tested against the exterior and each interior ring.
Returns
True for exterior membership excluding all holes; boundary behavior follows pointInRing().
Here is the call graph for this function:

◆ distanceToPolyline()

double EditGeometry::distanceToPolyline ( const QVector< QPointF > & vertices,
const QPointF & point,
int * segmentIndex = nullptr,
QPointF * closestPoint = nullptr )
nodiscard

Distance from a point to the nearest point on a polyline segment.

Parameters
[out]segmentIndexWhen non-null, receives the index of the closest segment (0 = first segment between vertices[0] and vertices[1]).
[out]closestPointWhen non-null, receives the closest point on the polyline.
Returns
Distance in the same units as the input coordinates. Returns std::numeric_limits<double>::infinity() for fewer than two vertices.
Parameters
[in]verticesOrdered polyline vertices, in a common Euclidean coordinate frame.
[in]pointQuery 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.

◆ insertedAt()

QVector< QPointF > EditGeometry::insertedAt ( const QVector< QPointF > & vertices,
int index,
const QPointF & newPt )
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.

Parameters
[in]verticesSource polyline, unchanged by this operation.
[in]indexInsertion position clamped to [0, vertices.size()].
[in]newPtCoordinate in the same frame as the source.
Returns
Copy with one inserted point; no geometry validity check is performed.

◆ interiorPoint()

QPointF EditGeometry::interiorPoint ( const QVector< QPointF > & ring)
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.

Parameters
[in]ringSimple ring, open or explicitly closed, in a Euclidean frame.
Returns
Interior scanline seed for usable rings; a default point for empty input or vertex centroid for degenerate geometry. Degenerate fallback is not guaranteed interior.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netArea()

double EditGeometry::netArea ( const RingPolygon & p)
nodiscard

Net area = |exterior| − Σ|holes|, clamped to >= 0.

Parameters
[in]pPolygon with rings expressed in one Euclidean frame.
Returns
Nonnegative exterior-minus-hole area in squared coordinate units; does not validate ring containment.
Here is the call graph for this function:

◆ normalizeRingPolygon()

RingPolygon EditGeometry::normalizeRingPolygon ( RingPolygon p,
double tol = kCoincidenceTol )
nodiscard

Clean every ring (dedupe + de-close), drop degenerate interior rings, and orient exterior CCW / interiors CW.

Parameters
[in]pPolygon copied by value; input storage held by the caller is unchanged.
[in]tolCoincidence tolerance in input coordinate units, as for cleanPolyline().
Returns
Open, oriented exterior and surviving nondegenerate holes; this does not repair self-intersections or misplaced holes.
Here is the call graph for this function:

◆ orientInteriorToEndpoints()

QVector< QPointF > EditGeometry::orientInteriorToEndpoints ( QVector< QPointF > interior,
const QPointF & from,
const QPointF & to )
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).

Parameters
interiorInterior bend points only (no node endpoints).
fromFrom-node coordinate (polyline start).
toTo-node coordinate (polyline end).
Returns
interior, reversed iff it was stored to→from.

◆ pointInRing()

bool EditGeometry::pointInRing ( const QVector< QPointF > & ring,
const QPointF & pt )
nodiscard

Even-odd point-in-ring test (boundary result is unspecified but stable).

Returns false for rings with fewer than 3 vertices.

Parameters
[in]ringOrdered ring in the same coordinate frame as the query.
[in]ptPoint to classify; no tolerance is applied.
Returns
Result of the even-odd ray test; degenerate rings return false.
Here is the caller graph for this function:

◆ polygonArea()

double EditGeometry::polygonArea ( const QVector< QPointF > & polygon)
nodiscard

Compute the area of a polygon using the shoelace formula.

Parameters
polygonOrdered polygon vertices (open or closed; if the last vertex equals the first, the closing edge is not doubled).
Returns
Absolute area in the squared units of the input coordinates. Returns 0 for fewer than 3 vertices.

◆ polylineLength()

double EditGeometry::polylineLength ( const QVector< QPointF > & vertices)
nodiscard

Compute the total length of a polyline.

Parameters
verticesOrdered 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).
Returns
Sum of Euclidean segment lengths, or 0 for <2 vertices.

◆ removedAt()

QVector< QPointF > EditGeometry::removedAt ( const QVector< QPointF > & vertices,
int index )
nodiscard

Remove the vertex at index, producing a new polyline of size-1.

Returns
A copy of 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.
Parameters
[in]verticesSource polyline, unchanged by this operation.
[in]indexZero-based vertex to erase; invalid indexes are ignored.

◆ replacedAt()

QVector< QPointF > EditGeometry::replacedAt ( const QVector< QPointF > & vertices,
int index,
const QPointF & newPt )
nodiscard

Replace one endpoint of a polyline, producing a new vector.

Parameters
verticesOriginal polyline (read-only).
indexEndpoint to replace (0 = first, vertices.size()-1 = last).
newPtReplacement point.
Returns
New polyline, or a copy of vertices if index is out of range.

◆ signedRingArea()

double EditGeometry::signedRingArea ( const QVector< QPointF > & ring)
nodiscard

Signed area of a ring via the shoelace formula.

Returns
Positive for counter-clockwise winding, negative for clockwise, 0 for fewer than 3 vertices. Handles open or explicitly-closed rings.
Parameters
[in]ringOrdered open or explicitly closed ring in a Euclidean frame.
Returns
Signed area in squared coordinate units, preserving ring orientation.
Here is the caller graph for this function:

◆ validateRingPolygon()

RingValidity EditGeometry::validateRingPolygon ( const RingPolygon & p)
nodiscard

Validate a RingPolygon with in-house geometry checks (O(n^2) edge tests; intended for hand-digitized / GIS-sourced rings).

Parameters
[in]pExterior and holes to inspect without modifying storage.
Returns
First detected validity class: insufficient vertices, self-intersection, escaping hole or overlapping/nested holes; Ok when these checks pass.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kCoincidenceTol

double EditGeometry::kCoincidenceTol = 1e-6
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.