Class PGS_SegmentSet
Methods in this class output segments as collections of
PEdges
; such collections can be converted
into LINES PShapes with toPShape(edges)
.
- Since:
- 1.3.0
- Author:
- Michael Carleton
-
Method Summary
Modifier and TypeMethodDescriptionstatic processing.core.PShape
dissolve
(Collection<micycle.pgs.commons.PEdge> segments) Dissolves the edges from a collection ofPEdges
into a set of maximal-length LineStrings in which each unique segment appears only once.static List<micycle.pgs.commons.PEdge>
filterAxisAligned
(List<micycle.pgs.commons.PEdge> segments, double angleDelta) Removes axis-aligned (horizontal and vertical) segments (within a given angle tolerance) from a collection of segments.static List<micycle.pgs.commons.PEdge>
filterByAverageLength
(List<micycle.pgs.commons.PEdge> segments, double fraction) Removes segments having a length either less than some fraction or more than1/fraction
of the mean segment length from a collection of segments.static List<micycle.pgs.commons.PEdge>
filterByMinLength
(List<micycle.pgs.commons.PEdge> segments, double minLength) Removes segments having a length less than the given length from a collection of segmensts.static List<micycle.pgs.commons.PEdge>
filterNear
(List<micycle.pgs.commons.PEdge> segments, double distance) Removes segments that are near others.static List<micycle.pgs.commons.PEdge>
fromPShape
(processing.core.PShape shape) Extracts a list of unique PEdge segments representing the given shape.static List<micycle.pgs.commons.PEdge>
getPolygonInteriorSegments
(List<micycle.pgs.commons.PEdge> segments, processing.core.PShape shape) Retains line segments from a set of line segments that are wholly contained within a given shape.static List<micycle.pgs.commons.PEdge>
graphMatchedSegments
(double width, double height, int n, long seed) Generates N non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with random points.static List<micycle.pgs.commons.PEdge>
graphMatchedSegments
(List<processing.core.PVector> points) Generates non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with the given points.static List<micycle.pgs.commons.PEdge>
graphMatchedSegments
(org.tinfour.common.IIncrementalTin triangulation) Generates non-intersecting segments via a Perfect matching algorithm applied to the given triangulation.static List<processing.core.PVector>
intersections
(Collection<micycle.pgs.commons.PEdge> edgesA, Collection<micycle.pgs.commons.PEdge> edgesB) Computes all intersection points between two collections of line segments.static List<micycle.pgs.commons.PEdge>
nodedSegments
(double width, double height, int n, long seed) Generates N non-intersecting segments via intersection and noding.static List<micycle.pgs.commons.PEdge>
parallelSegments
(double centerX, double centerY, double length, double spacing, double angle, int n) Generates a set of N straight parallel segments, centered on a given point.static List<micycle.pgs.commons.PEdge>
stochasticSegments
(double width, double height, int n) Generates a set of N random non-intersecting line segments via brute-forcing.static List<micycle.pgs.commons.PEdge>
stochasticSegments
(double width, double height, int n, double length) Generates a set of N random non-intersecting line segments of the given length via brute-forcing.static List<micycle.pgs.commons.PEdge>
stochasticSegments
(double width, double height, int n, double minLength, double maxLength, long seed) Generates a set of N random non-intersecting line segments via brute-forcing.static List<micycle.pgs.commons.PEdge>
Stretches each PEdge segment in the provided list by a specified factor.static processing.core.PShape
toPShape
(Collection<micycle.pgs.commons.PEdge> segments) Converts a collection ofPEdges
into aLINES
shape.static processing.core.PShape
toPShape
(Collection<micycle.pgs.commons.PEdge> segments, Integer strokeColor, Integer strokeCap, Integer strokeWeight) Converts a collection ofPEdges
into aLINES
shape, having the (optional) styling provided.
-
Method Details
-
nodedSegments
public static List<micycle.pgs.commons.PEdge> nodedSegments(double width, double height, int n, long seed) Generates N non-intersecting segments via intersection and noding.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
Algorithm:
- Generate a set of N random segments (will have many intersections)
- Node the random segment set and split segments at intersections
- Shrink split segments by ~30% (to increase distance between each other)
- The split segments will be very numerous; sort by length and return the longest N segments
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generateseed
- number used to initialize the underlying pseudorandom number generator- Returns:
- set of N random non-intersecting line segments
-
graphMatchedSegments
public static List<micycle.pgs.commons.PEdge> graphMatchedSegments(double width, double height, int n, long seed) Generates N non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with random points.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
The
graphMatchedSegments
methods are arguably the best approaches for random segment set generation.- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generateseed
- number used to initialize the underlying pseudorandom number generator- Returns:
- set of N random non-intersecting line segments
-
graphMatchedSegments
public static List<micycle.pgs.commons.PEdge> graphMatchedSegments(List<processing.core.PVector> points) Generates non-intersecting segments via a Perfect matching algorithm applied to a triangulation populated with the given points.Generates N/2 segments, where N is the number of points in the input. If the number of points is odd, the last point is discarded.
The
graphMatchedSegments
methods are arguably the best approaches for random segment set generation.- Parameters:
points
- point set from which to compute segments- Returns:
- set of non-intersecting line segments
-
graphMatchedSegments
public static List<micycle.pgs.commons.PEdge> graphMatchedSegments(org.tinfour.common.IIncrementalTin triangulation) Generates non-intersecting segments via a Perfect matching algorithm applied to the given triangulation.Generates N/2 segments, where N is the number of vertices in the triangulation. If the number of points is odd, the last point is discarded.
The
graphMatchedSegments
methods are arguably the best approaches for random segment set generation.- Parameters:
triangulation
- triangulation object to use for vertices and graph connectivity- Returns:
- set of non-intersecting line segments
-
stochasticSegments
public static List<micycle.pgs.commons.PEdge> stochasticSegments(double width, double height, int n) Generates a set of N random non-intersecting line segments via brute-forcing. Plentifully fast enough for many applications.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generate- Returns:
- set of N random non-intersecting line segments
- See Also:
-
stochasticSegments
public static List<micycle.pgs.commons.PEdge> stochasticSegments(double width, double height, int n, double length) Generates a set of N random non-intersecting line segments of the given length via brute-forcing. Plentifully fast enough for many applications.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generatelength
- segment length (for all segments)- Returns:
- set of N random non-intersecting line segments
- See Also:
-
stochasticSegments
public static List<micycle.pgs.commons.PEdge> stochasticSegments(double width, double height, int n, double minLength, double maxLength, long seed) Generates a set of N random non-intersecting line segments via brute-forcing. Plentifully fast enough for many applications.The segments are generated within a bounding box anchored at (0, 0) having the width and height specified.
- Parameters:
width
- width of the bounds in which to generate segments; segment x coordinates will not be greater than this valueheight
- height of the bounds in which to generate segments; segment y coordinates will not be greater than this valuen
- number of segments to generateminLength
- minimum segment length (inclusive)maxLength
- maximum segment length (exclusive)seed
- number used to initialize the underlying pseudorandom number generator- Returns:
- set of N random non-intersecting line segments
-
parallelSegments
public static List<micycle.pgs.commons.PEdge> parallelSegments(double centerX, double centerY, double length, double spacing, double angle, int n) Generates a set of N straight parallel segments, centered on a given point.- Parameters:
centerX
- the x coordinate of the center of the segments arrangmentcenterY
- the y coordinate of the center of the segments arrangmentlength
- length of each segmentspacing
- distance between successive segmentsangle
- line angle in radians, where 0 is parallel to x-axis (horizontal)n
- number of segments to generate. if odd then the middle segment lies on the center point; if even, then the first two segments are spaced evenly from the center point- Returns:
- set of N parallel line segments
-
toPShape
Converts a collection ofPEdges
into aLINES
shape.- Parameters:
segments
- collection of segments- Returns:
LINES
shape representing segments
-
toPShape
public static processing.core.PShape toPShape(Collection<micycle.pgs.commons.PEdge> segments, @Nullable Integer strokeColor, @Nullable Integer strokeCap, @Nullable Integer strokeWeight) Converts a collection ofPEdges
into aLINES
shape, having the (optional) styling provided.- Parameters:
segments
- collection of PEdge segmentsstrokeColor
- nullable/optional (default =Colors.PINK
)strokeCap
- nullable/optional (default =ROUND
)strokeWeight
- nullable/optional (default =2
)- Returns:
- shape representing segments
-
toBag
-
dissolve
Dissolves the edges from a collection ofPEdges
into a set of maximal-length LineStrings in which each unique segment appears only once. This method works by fusing segments that share endpoints into longer linear strings.This method may be preferred to
toPShape()
when the input segments form a linear string(s).- Parameters:
segments
- Collection of PEdge objects to dissolve into maximal-length LineStrings- Returns:
- A PShape object representing the dissolved LineStrings
- Since:
- 1.4.0
-
intersections
public static List<processing.core.PVector> intersections(Collection<micycle.pgs.commons.PEdge> edgesA, Collection<micycle.pgs.commons.PEdge> edgesB) Computes all intersection points between two collections of line segments.Given two collections of edges, this method finds and returns all points where a segment from the first collection intersects with a segment from the second collection, including intersection endpoints if applicable.
- Parameters:
edgesA
- the first collection of line segments to compareedgesB
- the second collection of line segments to compare- Returns:
- a list of
PVector
representing all intersection points found between the two collections of segments - Since:
- 2.1
-
fromPShape
Extracts a list of unique PEdge segments representing the given shape.This method iterates through all the child shapes of the input shape, creating PEdge segments for each pair of consecutive vertices.
- Parameters:
shape
- The shape from which to extract the edges. Supports holes and GROUP shapes.- Returns:
- A list of unique PEdge segments representing the edges of the input shape and its child shapes.
- Since:
- 1.4.0
-
stretch
public static List<micycle.pgs.commons.PEdge> stretch(List<micycle.pgs.commons.PEdge> segments, double factor) Stretches each PEdge segment in the provided list by a specified factor. The stretch is applied by scaling the distance between the edge's vertices, while keeping the midpoint of the edge constant.- Parameters:
segments
- The list of PEdges to be stretched.factor
- The factor by which to stretch each PEdge. A value greater than 1 will stretch the edges, while a value between 0 and 1 will shrink them.- Returns:
- A new List of PEdges representing the stretched edges.
- Since:
- 1.4.0
-
filterByMinLength
public static List<micycle.pgs.commons.PEdge> filterByMinLength(List<micycle.pgs.commons.PEdge> segments, double minLength) Removes segments having a length less than the given length from a collection of segmensts.- Parameters:
segments
- list of segments to filterminLength
- the minimum segment length to keep- Returns:
- a filtered copy of input collection
-
filterByAverageLength
public static List<micycle.pgs.commons.PEdge> filterByAverageLength(List<micycle.pgs.commons.PEdge> segments, double fraction) Removes segments having a length either less than some fraction or more than1/fraction
of the mean segment length from a collection of segments.This method can be used to homogenise a segment set.
- Parameters:
segments
- list of segments to filterfraction
- fraction of mean length to keep segments- Returns:
- a filtered copy of input collection
-
filterAxisAligned
public static List<micycle.pgs.commons.PEdge> filterAxisAligned(List<micycle.pgs.commons.PEdge> segments, double angleDelta) Removes axis-aligned (horizontal and vertical) segments (within a given angle tolerance) from a collection of segments.- Parameters:
segments
- list of segments to filterangleDelta
- angle tolerance, in radians- Returns:
- a filtered copy of the input where axis-aligned segments have been removed
-
filterNear
public static List<micycle.pgs.commons.PEdge> filterNear(List<micycle.pgs.commons.PEdge> segments, double distance) Removes segments that are near others. More specifically, removes any segment that lies closer than a given threshold to a previously retained segment.This method uses a simple greedy, O(n²) algorithm: it iterates through the input
segments
in order, keeps the first segment unconditionally, and for each subsequent segment rejects it if its distance to any segment already in the output list is less thandistance
.- Parameters:
segments
- the list of segments to filter.distance
- the minimum allowed distance between any two segments in the returned list; must be non-negative.- Returns:
- a new
List
containing those segments from the input (in original order) such that each pair of segments in the returned list is at leastdistance
apart. - Since:
- 2.1
-
getPolygonInteriorSegments
public static List<micycle.pgs.commons.PEdge> getPolygonInteriorSegments(List<micycle.pgs.commons.PEdge> segments, processing.core.PShape shape) Retains line segments from a set of line segments that are wholly contained within a given shape.- Parameters:
segments
- a list of line segments to check for containment within the shapeshape
- the polygonal shape to check for interior segments- Returns:
- a list of interior segments contained within the shape
- Since:
- 1.4.0
-