public final class PGS_Processing extends Object
Modifier and Type | Method and Description |
---|---|
static processing.core.PShape |
cleanCoverage(processing.core.PShape coverage,
double distanceTolerance,
double angleTolerance)
Removes gaps and overlaps from meshes/polygon collections that are intended
to satisfy the following conditions:
Vector-clean - edges between neighbouring polygons must either be
identical or intersect only at endpoints.
Non-overlapping - No two polygons may overlap.
|
static processing.core.PShape |
convexPartition(processing.core.PShape shape)
Partitions shape(s) into convex (simple) polygons.
|
static processing.core.PShape |
densify(processing.core.PShape shape,
double distanceTolerance)
Densifies a shape by inserting additional vertices along its line segments.
|
static processing.core.PShape |
eliminateSlivers(processing.core.PShape shape,
double threshold)
Removes narrow areas ("slivers") from a shape while preserving the geometry
of the remaining parts.
|
static processing.core.PShape |
equalPartition(processing.core.PShape shape,
int parts)
Randomly partitions a shape into N approximately equal-area polygonal cells.
|
static processing.core.PShape |
equalPartition(processing.core.PShape shape,
int parts,
long seed)
Randomly (with a given seed) partitions a shape into N approximately
equal-area polygonal cells.
|
static processing.core.PShape |
extractHoles(processing.core.PShape shape)
Extracts all the holes from a shape, returning them as if they are polygons.
|
static processing.core.PShape |
extractPerimeter(processing.core.PShape shape,
double from,
double to)
Extracts a portion/subline of the perimeter of a shape between two locations
on the perimeter.
|
static processing.core.PShape |
filterChildren(processing.core.PShape shape,
Predicate<processing.core.PShape> filterFunction)
Filters out the children of a given PShape object based on a given Predicate
function.
|
static List<processing.core.PVector> |
generateRandomGridPoints(processing.core.PShape shape,
int maxPoints,
boolean constrainedToCircle,
double gutterFraction)
Generates up to
maxPoints number of random points that are
contained within the shape region. |
static List<processing.core.PVector> |
generateRandomGridPoints(processing.core.PShape shape,
int maxPoints,
boolean constrainedToCircle,
double gutterFraction,
long randomSeed)
Generates up to
maxPoints number of random points that are
contained within the shape region. |
static List<processing.core.PVector> |
generateRandomPoints(processing.core.PShape shape,
int points)
Generates N random points that lie within the shape region.
|
static List<processing.core.PVector> |
generateRandomPoints(processing.core.PShape shape,
int points,
long seed)
Generates N random points that are contained within the shape region.
|
static List<processing.core.PVector> |
lineSegmentsIntersection(List<processing.core.PVector> lineSegments)
Computes all points of intersection between segments in a set of line
segments.
|
static processing.core.PShape |
nest(processing.core.PShape shape,
int n,
double r)
Creates a nested shape having n levels of inner polygons; each inner polygon
is obtained by joining the points at some fractional distance
r
along each side of the previous polygon. |
static processing.core.PVector |
pointOnExterior(processing.core.PShape shape,
double perimeterPosition,
double offsetDistance)
Extracts a point from the perimeter (exterior) of the given shape at a
specific position along its perimeter.
|
static processing.core.PVector |
pointOnExteriorByDistance(processing.core.PShape shape,
double perimeterDistance,
double offsetDistance)
Extracts a point from the perimeter (exterior) of the given shape at some
distance along its perimeter.
|
static List<processing.core.PVector> |
pointsOnExterior(processing.core.PShape shape,
double interPointDistance,
double offsetDistance)
Generates a list of points that lie on the exterior/perimeter of the given
shape.
|
static List<processing.core.PVector> |
pointsOnExterior(processing.core.PShape shape,
int points,
double offsetDistance)
Efficiently extracts multiple points from the perimeter of a shape, evenly
distributed along its boundary.
|
static processing.core.PShape |
polygonizeLines(List<processing.core.PVector> lineSegmentVertices)
Finds the polygonal faces formed by a set of intersecting line segments.
|
static processing.core.PShape |
removeHiddenLines(processing.core.PShape shape)
Removes overlap between polygons contained in a
GROUP shape,
preserving only visible line segments suitable for pen plotting and similar
applications. |
static processing.core.PShape |
removeSmallHoles(processing.core.PShape shape,
double areaThreshold)
Returns a copy of the shape where holes having an area less than the
specified threshold are removed.
|
static List<processing.core.PVector> |
shapeIntersection(processing.core.PShape a,
processing.core.PShape b)
Computes all points of intersection between the perimeters of
two shapes.
|
static processing.core.PShape |
slice(processing.core.PShape shape,
processing.core.PVector p1,
processing.core.PVector p2)
Slices a shape using a line given by its start and endpoints.
|
static processing.core.PShape |
split(processing.core.PShape shape)
Splits a shape into four equal quadrants (based on the envelope of the
shape).
|
static processing.core.PShape |
split(processing.core.PShape shape,
int splitDepth)
Splits a shape into
4^(1+recursions) rectangular partitions. |
static double |
tangentAngle(processing.core.PShape shape,
double perimeterRatio)
Calculates the angle of the line tangent to the shape at a specific point on
its perimeter.
|
static processing.core.PShape |
trapezoidPartition(processing.core.PShape shape)
Decomposes/partitions a shape into axis-aligned (stip-like) trazepoids.
|
public static processing.core.PShape densify(processing.core.PShape shape, double distanceTolerance)
shape
- The shape to be densified. It should be a lineal or
polygonal shape.distanceTolerance
- The densification tolerance used. All line segments
in the densified geometry will have lengths no
longer than the specified distance tolerance. The
distance tolerance must be a positive value.public static processing.core.PVector pointOnExterior(processing.core.PShape shape, double perimeterPosition, double offsetDistance)
shape
- A lineal or polygonal shape. If the input is a GROUP
shape, a single point will be extracted from its
first child shape.perimeterPosition
- A normalised position along the perimeter of a shape
[0...1]. 0 corresponds to the starting point of the
shape's perimeter, and 1 corresponds to the ending
point of the perimeter; any value between 0 and 1
represents a proportional distance along the shape's
boundary.offsetDistance
- A perpendicular offset distance from the shape's
perimeter. A value of 0 corresponds to exactly on
the shape's exterior/ Positive values offset the
point away from the shape (outwards); negative
values offset the point inwards towards its
interior.pointsOnExterior(PShape, int, double)
public static processing.core.PVector pointOnExteriorByDistance(processing.core.PShape shape, double perimeterDistance, double offsetDistance)
shape
- A lineal or polygonal shape. If the input is a GROUP
shape, a single point will be extracted from its
first child shape.perimeterDistance
- Distance along shape perimeter to extract the point.
0 corresponds to the first vertex of the shape's
perimeter.offsetDistance
- A perpendicular offset distance from the shape's
perimeter. A value of 0 corresponds to exactly on
the shape's exterior/ Positive values offset the
point away from the shape (outwards); negative
values offset the point inwards towards its
interior.public static List<processing.core.PVector> pointsOnExterior(processing.core.PShape shape, int points, double offsetDistance)
This method provides a faster alternative to calling other methods repeatedly when you need to obtain multiple points along the exterior of the shape. The extracted points will be evenly distributed along the shape's perimeter, allowing you to efficiently sample the boundary.
shape
- The shape from which to extract points. It should be a
lineal or polygonal shape. If the input is a GROUP
shape, a single point will be extracted from its first
child.points
- The number of points to return, evenly distributed
around the perimeter of the shape.offsetDistance
- The offset distance along a line perpendicular to the
perimeter. Positive values will offset the points away
from the shape's boundary (outwards), while negative
values will offset the points inwards towards its
interior.pointOnExterior(PShape, double, double)
,
pointsOnExterior(PShape, double, double)
public static List<processing.core.PVector> pointsOnExterior(processing.core.PShape shape, double interPointDistance, double offsetDistance)
This method creates a list of points that are evenly spaced along the shape's exterior. The points are distributed around the shape's boundary with a specified distance between each consecutive point. You can use this method to obtain a set of points that represents an approximation of the shape's outline.
shape
- The shape from which to generate the points. It
should be a lineal or polygonal shape. If the input
is a GROUP shape, a single point will be extracted
from its first child.interPointDistance
- The distance between each exterior point. This
value controls the density of the points and
determines how closely the points will be spaced
along the shape's perimeter.offsetDistance
- The offset distance along a line perpendicular to
the perimeter. Positive values will offset the
points away from the shape's boundary (outwards),
while negative values will offset the points
inwards towards its interior.pointOnExterior(PShape, double, double)
,
densify(PShape, double)
public static processing.core.PShape extractPerimeter(processing.core.PShape shape, double from, double to)
shape
- the shape from which to extract a the perimeterfrom
- the starting location of the perimeter extract, given by a
fraction (0...1) of the total perimeter lengthto
- the end location of the perimeter extract, given by a fraction
(0...1) of the total perimeter lengthpublic static double tangentAngle(processing.core.PShape shape, double perimeterRatio)
shape
- The shape for which to find the tangent angle.perimeterRatio
- A normalised position along the perimeter of a shape
[0...1]. 0 corresponds to the starting point of the
shape's perimeter, and 1 corresponds to the ending
point of the perimeter; any value between 0 and 1
represents a proportional distance along the shape's
boundary.public static List<processing.core.PVector> shapeIntersection(processing.core.PShape a, processing.core.PShape b)
NOTE: This method shouldn't be confused with
PGS_ShapeBoolean.intersect()
, which finds the shape made by the intersecting
shape areas.
a
- one shapeb
- another shapepublic static List<processing.core.PVector> lineSegmentsIntersection(List<processing.core.PVector> lineSegments)
lineSegments
- a list of PVectors where each pair (couplet) of PVectors
represent the start and end point of one line segmentpublic static List<processing.core.PVector> generateRandomPoints(processing.core.PShape shape, int points)
This is a fast method but note that the underlying algorithm makes a minor trade-off for its speed: the resulting point set is slightly more uniformly distributed over the input shape compared to a purely random approach (this arises because the shape is first divided into triangles; each triangle is then sampled a fixed number of times according to its area relative to the whole).
shape
- defines the region in which random points are generatedpoints
- number of points to generate within the shape regiongenerateRandomPoints(PShape, int, long)
,
generateRandomGridPoints(PShape, int, boolean, double)
public static List<processing.core.PVector> generateRandomPoints(processing.core.PShape shape, int points, long seed)
This is a fast method but note that the underlying algorithm makes a minor trade-off for its speed: the resulting point set is slightly more uniformly distributed over the input shape compared to a purely random approach (this arises because the shape is first divided into triangles; each triangle is then sampled a fixed number of times according to its area relative to the whole).
shape
- defines the region in which random points are generatedpoints
- number of points to generate within the shape regionseed
- number used to initialize the underlying pseudorandom number
generatorgenerateRandomPoints(PShape, int)
,
generateRandomGridPoints(PShape, int, boolean, double)
public static List<processing.core.PVector> generateRandomGridPoints(processing.core.PShape shape, int maxPoints, boolean constrainedToCircle, double gutterFraction)
maxPoints
number of random points that are
contained within the shape region. Points are distributed according to a grid
of cells (one point randomly located in each cell), based on the envelope of
the shape.shape
- defines the region in which random points are
generatedmaxPoints
- maximum number of points, if this shape was its
own envelopeconstrainedToCircle
- Sets whether generated points are constrained to
lie within a circle contained within each grid
cell. This provides greater separation between
points in adjacent cells.gutterFraction
- Sets the fraction of the grid cell side which will
be treated as a gutter, in which no points will be
created. The provided value is clamped to the
range [0.0, 1.0]. Higher values increase how
"grid-like" the point distribution is.generateRandomPoints(PShape, int)
,
generateRandomGridPoints(PShape, int, boolean, double, long)
public static List<processing.core.PVector> generateRandomGridPoints(processing.core.PShape shape, int maxPoints, boolean constrainedToCircle, double gutterFraction, long randomSeed)
maxPoints
number of random points that are
contained within the shape region. Points are distributed according to a grid
of cells (one point randomly located in each cell), based on the envelope of
the shape.
This method accepts a seed for the RNG when identical sequences of random points are required.
shape
- defines the region in which random points are
generatedmaxPoints
- maximum number of points, if this shape was its
own envelopeconstrainedToCircle
- Sets whether generated points are constrained to
lie within a circle contained within each grid
cell. This provides greater separation between
points in adjacent cells.gutterFraction
- Sets the fraction of the grid cell side which will
be treated as a gutter, in which no points will be
created. The provided value is clamped to the
range [0.0, 1.0]. Higher values increase how
"grid-like" the point distribution is.randomSeed
- generateRandomGridPoints(PShape, int, boolean, double)
public static processing.core.PShape nest(processing.core.PShape shape, int n, double r)
r
along each side of the previous polygon.
This is also called a "derived polygon".
shape
- a PShape representing the single input polygon for which the
nested shape will be created. Although all polygon types are
compatible, simpler/convex polygons make for a more effective
result.n
- the number of nested levels to be created inside the input
shape.r
- fractional distance between each nested level of polygons, where
0.5
produces maximal nesting.public static processing.core.PShape removeHiddenLines(processing.core.PShape shape)
GROUP
shape,
preserving only visible line segments suitable for pen plotting and similar
applications.
This method processes a GROUP
shape consisting of lineal or
polygonal child shapes, aiming to create linework that represents only the
segments visible to a human, rather than a computer. The resulting linework
is useful for pen plotters or other applications where only the visible paths
are desired.
During the operation, any overlapping lines are also removed to ensure a clean and clear representation of the shapes. It's important to note that the order of shape layers in the input GROUP shape is significant. The method considers the last child shape of the input to be "on top" of all other shapes, as is the case visually.
shape
- A GROUP shape containing lineal or polygonal child shapes.public static processing.core.PShape removeSmallHoles(processing.core.PShape shape, double areaThreshold)
shape
- a single polygonal shape or GROUP polygonal shapeareaThreshold
- removes any holes with an area smaller than this valuepublic static processing.core.PShape extractHoles(processing.core.PShape shape)
shape
- the PShape to extract holes frompublic static processing.core.PShape polygonizeLines(List<processing.core.PVector> lineSegmentVertices)
lineSegmentVertices
- a list of PVectors where each pair (couplet) of
PVectors represent the start and end point of one
line segmentpublic static processing.core.PShape split(processing.core.PShape shape)
shape
- The shape to be split into quadrants.split(PShape, int)
public static processing.core.PShape split(processing.core.PShape shape, int splitDepth)
4^(1+recursions)
rectangular partitions.
This method performs a recursive split operation on the given shape, dividing it into a finer grid of rectangular partitions. Each recursion further divides the envelopes of the parent shapes into four quadrants, resulting in a more refined partitioning of the original shape.
It's important to note that this operation differs from merely overlaying a regular square grid on the shape and then splitting it. The recursive process ensures that each subdivision is based on the envelope of the parent shape, which may be rectangular.
shape
- The shape to be split into rectangular partitions.splitDepth
- The number of split recursions to perform, determining the
level of partitioning and grid refinement.split(PShape)
public static processing.core.PShape convexPartition(processing.core.PShape shape)
shape
- the shape to partition. can be a single polygon or a GROUP of
polygonspublic static processing.core.PShape equalPartition(processing.core.PShape shape, int parts)
shape
- a polygonal (non-group, no holes) shape to partitionparts
- number of roughly equal area partitons to createpublic static processing.core.PShape equalPartition(processing.core.PShape shape, int parts, long seed)
shape
- a polygonal (non-group, no holes) shape to partitionparts
- number of roughly equal area partitons to createseed
- number used to initialize the underlying pseudorandom number
generatorpublic static processing.core.PShape trapezoidPartition(processing.core.PShape shape)
The output can contain some "degenerate" trapezoids that do indeed have 4 vertices but look like triangles.
shape
- a polygonal or a GROUP shapepublic static processing.core.PShape slice(processing.core.PShape shape, processing.core.PVector p1, processing.core.PVector p2)
shape
- PShape to slice into two shapesp1
- must be outside shapep2
- must be outside shapepublic static processing.core.PShape eliminateSlivers(processing.core.PShape shape, double threshold)
This operation is similar to
erosionDilation()
, but
better preserves the original geometry of remaining parts.
If the input is a single polygon and if when removing slivers, a multipolygon is produced, further processing occurs within the method to repair it back into a single polygon.
shape
- polygonal shapethreshold
- width threshold (probably no more than 10); parts narrower
than this are eliminatedpublic static processing.core.PShape cleanCoverage(processing.core.PShape coverage, double distanceTolerance, double angleTolerance)
It may not always be possible to perfectly clean the input.
While this method is intended to be used to fix malformed coverages, it can be used to snap collections of disparate polygons together.
coverage
- a GROUP shape, consisting of the polygonal faces to
cleandistanceTolerance
- the distance below which segments and vertices are
considered to matchangleTolerance
- the maximum angle difference between matching
segments, in degreespublic static processing.core.PShape filterChildren(processing.core.PShape shape, Predicate<processing.core.PShape> filterFunction)
Example Lambda Code:
PGS_Processing.filterChildren(myShape, child -> PGS_ShapePredicates.area(child) < 50); // discard small child shapes
shape
- The PShape whose children will be filtered.filterFunction
- A Predicate function that takes a PShape object as its
argument and returns true
if the child
shape should be filtered out/removed from the
shape. To retain child shapes, the Predicate function
should return false
. You can use a lambda
expression or a method reference to implement the
Predicate function.==false
).Copyright © 2023. All rights reserved.