Below is a high-level overview of Uvertex.pas, a Delphi unit that manages a linked list of 2D vertex coordinates forming polylines or polygons in EPA SWMM.
1. Purpose and Structure
The Uvertex.pas unit defines:
-
TVertexrecord- Holds (X, Y) coordinates of a point.
- Includes a
Nextpointer to the subsequent vertex, implementing a forward-linked list structure.
-
TVertexListclass- A linked list of these
TVertexnodes, storing vertex coordinates that represent either:- A polyline, such as the geometry for a link or conduit, or
- A polygon, such as the boundary for a subcatchment or storage shape.
- A linked list of these
2. Major Components and Methods
2.1 Vertex Management
-
Vfirst,VcurrentVfirst: pointer to the first vertex in the list.Vcurrent: pointer to the current vertex in the list, used for insertion or traversal.
-
Add(X, Y: Extended): PVertex- Allocates a new vertex, sets its
(X, Y)coordinates, then inserts it afterVcurrent. - Updates
Vcurrentto the new vertex.
- Allocates a new vertex, sets its
-
Delete(aVertex: PVertex): PVertex- Removes
aVertexfrom the linked list. - Frees the memory allocated for that vertex.
- Updates
Vcurrentto the previous vertex or the new list head.
- Removes
-
Clear- Traverses and deletes all vertices in the list, releasing their memory.
2.2 Traversal and Positioning
-
First/NextFirstsetsVcurrentto the first vertex and returns it.NextadvancesVcurrentto the next vertex in the list and returns it.
-
Find(X1, X2, Y1, Y2: Extended): PVertex- Locates the first vertex whose
(X, Y)is within the rectangle[X1..X2] x [Y1..Y2]. - Sets
Vcurrentto that vertex if found.
- Locates the first vertex whose
-
Count- Returns the total number of vertices in the list.
-
Move(DX, DY: Extended)- Adds
(DX, DY)to every vertex coordinate in the list, effectively translating the entire shape.
- Adds
-
Assign(aVlist: TVertexList)- Copies all vertices from another
TVertexList.
- Copies all vertices from another
2.3 Specialized Polygon Operations
While TVertexList can store polylines, it also supports polygon operations:
-
AddPolygonVertex- Inserts a new vertex midway between
VcurrentandVcurrent^.Next. - Assumes a closed polygon where the last vertex’s
Nextmight circle back toVfirst.
- Inserts a new vertex midway between
-
ClearPolygon- Removes all vertices except for one, which is set to the shape’s centroid.
-
PolygonCentroid(var X, Y: Extended): Boolean- Uses a formula (from Graphics Gems IV) to find the centroid of the polygon.
- Returns it in
(X, Y). - Handles edge cases with fewer vertices gracefully.
-
PolygonArea: Extended- Computes the signed area of the polygon using a typical cross-product method (again from Graphics Gems IV).
- Returns the area in positive units (absolute value).
2.4 Additional Utility Methods
-
Reverse- Reverses the order of vertices in the list (end becomes start, etc.).
-
Update(X, Y: Extended)- Updates the coordinates of
Vcurrentwithout creating a new vertex.
- Updates the coordinates of
3. Typical Usage
-
Initializing a shape or link:
var Vlist: TVertexList; begin Vlist := TVertexList.Create; Vlist.Add(100, 200); Vlist.Add(150, 250); // ... end; -
Finding polygons area and centroid, used for subcatchment geometry:
var area, cx, cy: Extended; begin area := Vlist.PolygonArea; Vlist.PolygonCentroid(cx, cy); end; -
Editing a shape’s geometry in SWMM’s map via:
- Inserting or deleting vertices (
Add,Delete), - Translating the entire shape (
Move), - Reversing the polyline flow direction (
Reverse).
- Inserting or deleting vertices (
4. Summary
Uvertex.pas is a lightweight but crucial part of SWMM’s internal geometry handling:
- Implements a singly linked list of
(X, Y)vertices, - Handles geometry-related actions (insert, delete, move),
- Provides basic polygon computations (centroid and area),
- Powers link or subcatchment shapes in the SWMM GUI.
This allows the rest of SWMM (particularly the map form and property editor) to efficiently manage polylines (links) and polygons (subcatchments/storage) with flexible insertion, deletion, and transformations of vertices.
No comments:
Post a Comment