Monday, December 30, 2024

SWMM5 Delphi GUI Uvertex.pas Summary

 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:

  1. TVertex record

    • Holds (X, Y) coordinates of a point.
    • Includes a Next pointer to the subsequent vertex, implementing a forward-linked list structure.
  2. TVertexList class

    • A linked list of these TVertex nodes, 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.

2. Major Components and Methods

2.1 Vertex Management

  1. Vfirst, Vcurrent

    • Vfirst: pointer to the first vertex in the list.
    • Vcurrent: pointer to the current vertex in the list, used for insertion or traversal.
  2. Add(X, Y: Extended): PVertex

    • Allocates a new vertex, sets its (X, Y) coordinates, then inserts it after Vcurrent.
    • Updates Vcurrent to the new vertex.
  3. Delete(aVertex: PVertex): PVertex

    • Removes aVertex from the linked list.
    • Frees the memory allocated for that vertex.
    • Updates Vcurrent to the previous vertex or the new list head.
  4. Clear

    • Traverses and deletes all vertices in the list, releasing their memory.

2.2 Traversal and Positioning

  1. First / Next

    • First sets Vcurrent to the first vertex and returns it.
    • Next advances Vcurrent to the next vertex in the list and returns it.
  2. Find(X1, X2, Y1, Y2: Extended): PVertex

    • Locates the first vertex whose (X, Y) is within the rectangle [X1..X2] x [Y1..Y2].
    • Sets Vcurrent to that vertex if found.
  3. Count

    • Returns the total number of vertices in the list.
  4. Move(DX, DY: Extended)

    • Adds (DX, DY) to every vertex coordinate in the list, effectively translating the entire shape.
  5. Assign(aVlist: TVertexList)

    • Copies all vertices from another TVertexList.

2.3 Specialized Polygon Operations

While TVertexList can store polylines, it also supports polygon operations:

  1. AddPolygonVertex

    • Inserts a new vertex midway between Vcurrent and Vcurrent^.Next.
    • Assumes a closed polygon where the last vertex’s Next might circle back to Vfirst.
  2. ClearPolygon

    • Removes all vertices except for one, which is set to the shape’s centroid.
  3. 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.
  4. 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

  1. Reverse

    • Reverses the order of vertices in the list (end becomes start, etc.).
  2. Update(X, Y: Extended)

    • Updates the coordinates of Vcurrent without creating a new vertex.

3. Typical Usage

  1. Initializing a shape or link:

    var
      Vlist: TVertexList;
    begin
      Vlist := TVertexList.Create;
      Vlist.Add(100, 200);
      Vlist.Add(150, 250);
      // ...
    end;
    
  2. Finding polygons area and centroid, used for subcatchment geometry:

    var
      area, cx, cy: Extended;
    begin
      area := Vlist.PolygonArea;
      Vlist.PolygonCentroid(cx, cy);
    end;
    
  3. 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).

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:

A comprehensive explanation of how minimum travel distance relates to link length in InfoSewer

In hydraulic modeling of sewer networks, the minimum travel distance is a fundamental parameter that affects how accurately the model can si...