Sometimes it may be desirable to get stats for a Polyline - either the entire length, or for a custom set of contiguous vertices or segments. Stats may include things such as length, max/min or average values, or even statistics based on properties associated with vertices and segments.

The polyline data structure allows this to be done with a separate stats object that traverses the polyline & applies different property class objects to aggregate the data needed for the stats desired. This object can then serialize the results into a JSON object. The way the class objects are set up allows for easy additions & customization of stats collection on extended classes of the base stats object or polyline object.

The following diagram shows the most fundamental stats that can be collected for a polyline. Other libraries can extend from or aggregate these in order to generate more meaningful stats for a particular use case.

Screen Shot 2024-08-20 at 4.17.46 PM.png

Constrained stats is an abstract class that allows a user to turn the stats on/off, which can allow for real-time optimization of gathering desired stats for an object by use of some isConsidered delegate that is passed in.

Basic stats inherit from this and have more complex behaviors, such as optionally adding/removing segments, specifying start/end locations, updating stats, etc.

Screen Shot 2024-08-20 at 4.22.20 PM.png

In interfaces, the Node of Interest is used in order to save the node at the max/min/median/etc. location in case other data from this node or neighboring segments is desired. Basic stats, such as MaxMin just return a max or min, and other basic stats. Stats with the naming convention {name}Stats tend to contain references to these but reveals them in a more meaningful way, such as a range for Max/Min.

The basic pattern for stats is to have an interface to implement that specifies the public properties. The classes themselves then have their own methods for adding/removing/calculating/etc. for the stat, as well as uniformly a serialize method that produces a JSON object of the basic end results of any stats calculations.