Class PGS_Conversion
PShapes
and
JTS's Geometries
, along with various other formats. It also
offers additional utility methods to assist with handling PShapes
.
Though certain conversion methods are utilised internally by the library, they have been kept public to cater to more complex user requirements.
Note: JTS Geometries
do not provide support for bezier curves. As
such, bezier curves are linearised/divided into straight line segments during
the conversion process from PShape
to JTS Geometry
.
Furthermore, any consecutive duplicate vertices are not preserved.
Two configurable boolean flags influence the conversion process:
PRESERVE_STYLE
(set to true by default), and
HANDLE_MULTICONTOUR
(set to false by default). Users are encouraged
to review these flags as part of more complicated workflows with this class.
- Author:
- Michael Carleton
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A utility class for storing and manipulating the visual properties of PShapes from the Processing library. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic boolean
A boolean flag that, when true, enables a specialised subroutine during thefromPShape()
conversion to correctly convert single PShapes comprised of multiple contours, each representing a separate shape.static boolean
A boolean flag that affects whether a PShape's style (fillColor, strokeColor, strokeWidth) is preserved duringPShape->Geometry->PShape
conversion (i.e. whentoPShape(fromPShape(myPShape))
is called). -
Method Summary
Modifier and TypeMethodDescriptionstatic processing.core.PShape
copy
(processing.core.PShape shape) Produces a deep copy / clone of the input shape.static processing.core.PShape
disableAllFill
(processing.core.PShape shape) Calls setFill(false) on a PShape and all its children.static processing.core.PShape
disableAllStroke
(processing.core.PShape shape) Calls setStroke(false) on a PShape and all its children.static processing.core.PShape
flatten
(Collection<processing.core.PShape> shapes) Flattens a collection of PShapes into a single GROUP PShape which has the input shapes as its children.static processing.core.PShape
flatten
(processing.core.PShape... shapes) Flattens a collection of PShapes into a single GROUP PShape which has the input shapes as its children.static processing.core.PShape
fromArray
(double[][] shape, boolean close) Creates a PShape from an array of doubles representing coordinates.static processing.core.PShape
fromChildren
(Collection<processing.core.PShape> children) Creates a single GROUP shape whose children shapes are the list given.static processing.core.PShape
fromContours
(List<processing.core.PVector> shell, List<List<processing.core.PVector>> holes) Generates a polygonal shape from lists of vertices representing its shell and holes.static processing.core.PShape
fromCubicBezier
(processing.core.PVector start, processing.core.PVector controlPoint1, processing.core.PVector controlPoint2, processing.core.PVector end) Creates a PATH PShape representing a cubic bezier curve, given by its parameters.static processing.core.PShape
fromEncodedPolyline
(String encodedPolyline) Converts a geometry in Encoded Polyline format into a PShape.static processing.core.PShape
fromGeoJSON
(String json) Converts a GeoJSON representation of a shape into its PShape counterpart.static processing.core.PShape
Converts a given SimpleGraph consisting of PVectors and PEdges into a PShape by polygonizing its edges.static <V,
E> processing.core.PShape fromGraph
(org.jgrapht.graph.SimpleGraph<V, E> graph, double normalizationFactor, double boundsX, double boundsY) Takes as input a graph and computes a layout for the graph vertices using a Force-Directed placement algorithm (not vertex coordinates, if any exist).static processing.core.PShape
fromHexWKB
(String shapeWKB) Converts a geometry in Well-Known Binary hex format into a PShape.static processing.core.PShape
fromJava2D
(Shape shape) Converts a Java2D/java.awt Shape to a Processing PShape.static org.locationtech.jts.geom.Geometry
fromPShape
(processing.core.PShape shape) Transforms a PShape into a corresponding JTS Geometry.static processing.core.PShape
fromPVector
(Collection<processing.core.PVector> vertices) Generates a shape from a list of vertices.static processing.core.PShape
fromPVector
(processing.core.PVector... vertices) Generates a shape from a list of vertices.static processing.core.PShape
fromQuadraticBezier
(processing.core.PVector start, processing.core.PVector controlPoint, processing.core.PVector end) Creates a PATH PShape representing a quadratic bezier curve, given by its parameters.static processing.core.PShape
fromWKB
(byte[] shapeWKB) Converts a geometry in Well-Known Binary format into a PShape.static processing.core.PShape
Reads a shape from a (binary) file containing the Well-Known Binary representation of it.static processing.core.PShape
Converts a geometry in Well-Known Text format into a PShape.static List<processing.core.PShape>
getChildren
(processing.core.PShape shape) Recurses a GROUP PShape, finding all of its non-GROUP child PShapes.static int
getFillColor
(processing.core.PShape shape) Retrieves the fill color of a PShape.static PGS_Conversion.PShapeData
getShapeStylingData
(processing.core.PShape shape) Retrieves the styling data associated with the specified PShape object.static processing.core.PShape
reorderChildren
(processing.core.PShape shape, Comparator<processing.core.PShape> comparator) Reorders the child shapes of a given shape.static processing.core.PShape
roundVertexCoords
(processing.core.PShape shape) Rounds the x and y coordinates (to the closest int) of all vertices belonging to the shape, mutating the shape.static processing.core.PShape
setAllFillColor
(processing.core.PShape shape, int color) Sets the fill color for the PShape and all of its children recursively (and disables stroke).static processing.core.PShape
setAllStrokeColor
(processing.core.PShape shape, int color, double strokeWeight) Sets the stroke color for the PShape and all of its children recursively.static processing.core.PShape
setAllStrokeToFillColor
(processing.core.PShape shape) Sets the stroke color equal to the fill color for the PShape and all of its descendent shapes individually (that is, each child shape belonging to the shape (if any) will have its stroke color set to its own fill color, and not the parent-most shape's fill color).static processing.core.PShape
setAllStrokeToFillColor
(processing.core.PShape shape, double strokeWeight) Sets the stroke color equal to the fill color, and the strokeWeight to the specified value, for the PShape and all of its descendent shapes individually (that is, each child shape belonging to the shape (if any) will have its stroke color set to its own fill color, and not the parent-most shape's fill color).static double[][]
toArray
(processing.core.PShape shape, boolean keepClosed) Converts a simple PShape into an array of its coordinates.static org.jgrapht.graph.SimpleGraph<processing.core.PVector,
PEdge> toCentroidDualGraph
(processing.core.PShape mesh) Converts a mesh-like PShape into its centroid-based undirected dual-graph.static final processing.core.PShape
toCircles
(Collection<processing.core.PVector> circles) Creates a PShape having circle geometries representing a collection of circles.toContours
(processing.core.PShape shape) Extracts the contours from aPOLYGON
orPATH
PShape, represented as lists of PVector points.static org.jgrapht.graph.SimpleGraph<processing.core.PShape,
org.jgrapht.graph.DefaultEdge> toDualGraph
(processing.core.PShape mesh) Converts a mesh-like PShape into its undirected, unweighted dual-graph.static String
toEncodedPolyline
(processing.core.PShape shape) Writes a single holeless shape into the string representation of its Google Encoded Polyline format.static String
toGeoJSON
(processing.core.PShape shape) Writes a shape into the string representation of its GeoJSON format.static org.jgrapht.graph.SimpleGraph<processing.core.PVector,
PEdge> toGraph
(processing.core.PShape shape) Transforms a given PShape into a simple graph representation.static String
toHexWKB
(processing.core.PShape shape) Writes a shape into the hexadecimal string representation of its Well-Known Binary format.static Shape
toJava2D
(processing.core.PShape shape) Creates a Java2D/java.awt Shape representing a PShape.static final processing.core.PShape
toPointsPShape
(Collection<processing.core.PVector> points) Transforms a list of points into a POINTS PShape.static final processing.core.PShape
toPointsPShape
(processing.core.PVector... vertices) Transforms a variable arg list of points into a POINTS PShape.static processing.core.PShape
toPShape
(Collection<? extends org.locationtech.jts.geom.Geometry> geometries) Converts a collection of JTS Geometries into a corresponding GROUP PShape.static processing.core.PShape
toPShape
(org.locationtech.jts.geom.Geometry g) Converts a JTS Geometry into a corresponding PShape.static List<processing.core.PVector>
toPVector
(processing.core.PShape shape) Extracts the vertices of a PShape into a list of PVectors.static byte[]
toWKB
(processing.core.PShape shape) Writes a shape into Well-Known Binary format.static void
Converts a shape into Well-Known Binary format and writes the bytes to a file.static String
toWKT
(processing.core.PShape shape) Writes the Well-Known Text representation of a shape.
-
Field Details
-
PRESERVE_STYLE
public static boolean PRESERVE_STYLEA boolean flag that affects whether a PShape's style (fillColor, strokeColor, strokeWidth) is preserved duringPShape->Geometry->PShape
conversion (i.e. whentoPShape(fromPShape(myPShape))
is called). Default =true
. -
HANDLE_MULTICONTOUR
public static boolean HANDLE_MULTICONTOURA boolean flag that, when true, enables a specialised subroutine during thefromPShape()
conversion to correctly convert single PShapes comprised of multiple contours, each representing a separate shape. If set tofalse
, thefromPShape()
method assumes that in multi-contour shapes, every contour beyond the first represents a hole, which is generally an adequate assumption.This feature is disabled by default because it necessitates additional computation, such as determining polygon ring orientations, and is seldom required (unless one is dealing with fonts, I have observed). Default =
false
.For more information, refer to the discussion on this topic at GitHub.
-
-
Method Details
-
toPShape
public static processing.core.PShape toPShape(org.locationtech.jts.geom.Geometry g) Converts a JTS Geometry into a corresponding PShape. In the case of MultiGeometries (which include collections of geometries), the result is a GROUP PShape containing the appropriate child PShapes.The conversion process follows the geometry types supported by JTS, namely:
GEOMETRYCOLLECTION
: Converted to a GROUP PShape if it contains multiple geometries. For single geometry collections, it extracts and converts the single geometry.MULTIPOLYGON
: Similar to GeometryCollection, MultiPolygons are converted to a GROUP PShape, with each polygon converted to a child PShape.MULTILINESTRING
: MultiLineStrings are handled in the same way as GeometryCollections and MultiPolygons, converted to a GROUP PShape containing child PShapes.LINEARRING
andLINESTRING
: These are converted to a PATH PShape, preserving the closed or open nature of the original LineString.POLYGON
: Converted to a PATH PShape, with each contour of the polygon represented as a series of vertices in the PShape. Inner contours, or 'holes' in the polygon, are handled separately.POINT
andMULTIPOINT
: These are converted to a GEOMETRY PShape with each point represented as a vertex.
Please note that any unsupported geometry types will result in an error message.
If
PRESERVE_STYLE
is enabled and the geometry includes user data in the form of PShapeData, the style from the data is applied to the resulting PShape.- Parameters:
g
- The JTS geometry to convert.- Returns:
- A PShape that represents the input geometry, or a new, empty PShape if the input is null.
-
toPShape
public static processing.core.PShape toPShape(Collection<? extends org.locationtech.jts.geom.Geometry> geometries) Converts a collection of JTS Geometries into a corresponding GROUP PShape. This method loops through the provided geometries, converting each individual geometry into a PShape, and then adds it as a child to the GROUP PShape.In case the collection only contains a single geometry, this method will instead return a PShape that directly corresponds to that single geometry. It will not be wrapped in a GROUP shape in this case.
- Parameters:
geometries
- A collection of JTS Geometries to convert into a PShape.- Returns:
- A PShape that represents the collection of input geometries. If the collection contains only a single geometry, the return is a PShape directly equivalent to that geometry. Otherwise, the return is a GROUP PShape containing child PShapes for each geometry in the collection.
-
fromPShape
public static org.locationtech.jts.geom.Geometry fromPShape(processing.core.PShape shape) Transforms a PShape into a corresponding JTS Geometry.During this transformation, any bezier curve elements within the input PShape are linearised, meaning they are sampled at regular, equidistant intervals. This process results in the created geometry having a greater number of vertices than the original PShape.
Additionally, please be aware that the method does not preserve multi-level child shape hierarchies present in the input PShape. All child shapes are flattened to the same level in the output geometry.
The conversion process depends on the PShape's type and can be broadly categorized as follows:
PConstants.GROUP
: The method recursively converts each child of the PShape into a corresponding Geometry and groups these into a GeometryCollection.PShape.GEOMETRY
andPShape.PATH
: Here, the method further distinguishes between the kinds of the shape. For POLYGON, PATH and unspecified kinds, it creates a Geometry from the vertices of the PShape. For special paths (e.g., POINTS, LINES), it uses a separate conversion routine.PShape.PRIMITIVE
: It converts the PShape using a separate routine dedicated to primitive shapes.
If
PRESERVE_STYLE
is enabled, the method preserves the style of the PShape in the output Geometry as user data.Lastly, any affine transformations applied to the PShape (which do not directly affect its vertices) are also applied to the resulting Geometry (baked into its coordinates).
- Parameters:
shape
- The PShape to convert into a JTS Geometry.- Returns:
- A JTS Geometry that corresponds to the input PShape, or an empty 2D Geometry if the PShape is null or the type of the PShape is unsupported.
-
toContours
Extracts the contours from aPOLYGON
orPATH
PShape, represented as lists of PVector points. It extracts both the exterior contour (perimeter) and interior contours (holes). For such PShape types, all contours after the first are guaranteed to be holes.Background: The PShape data structure stores all vertices in a single array, with contour breaks designated in a separate array of vertex codes. This design makes it challenging to directly access holes and their vertices. This method overcomes that limitation by analyzing the vertex codes to identify and extract both the exterior contour and interior contours (holes).
- Parameters:
shape
- The PShape object (of kind POLYGON or PATH) from which to extract contours.- Returns:
- A List of Lists of PVector coordinates, where each inner List represents a contour. The first contour is always the exterior, while all subsequent contours represent holes.
- Since:
- 2.0
-
toPointsPShape
public static final processing.core.PShape toPointsPShape(processing.core.PVector... vertices) Transforms a variable arg list of points into a POINTS PShape.- Parameters:
vertices
-- Returns:
- a POINTS PShape
- Since:
- 1.4.0
-
toPointsPShape
public static final processing.core.PShape toPointsPShape(Collection<processing.core.PVector> points) Transforms a list of points into a POINTS PShape.- Since:
- 1.2.0
-
toCircles
Creates a PShape having circle geometries representing a collection of circles.- Parameters:
circles
- The collection of PVector objects representing the circles. The x and y components represent the center of the circle, and the z component represents the radius.- Returns:
- The GROUP PShape object representing the collection of circles.
- Since:
- 1.4.0
-
toPVector
Extracts the vertices of a PShape into a list of PVectors.The function navigates through all children of the given shape if it is of the GROUP type, recursively flattening their vertices and adding them to the list. In the case of PShape primitives, where the
getVertex()
method fails, the shape is converted to its equivalent path representation before vertex extraction.If the input shape represents a closed polygon, the method returns an "unclosed" version of the shape. This means that the duplicate vertex that closes the shape (which is identical to the first vertex) is omitted from the output.
The resulting list contains all vertices from the input PShape in the order they appear in the shape.
- Parameters:
shape
- the PShape from which vertices are to be extracted- Returns:
- a list of PVector objects representing the vertices of the input shape
-
toGraph
public static org.jgrapht.graph.SimpleGraph<processing.core.PVector,PEdge> toGraph(processing.core.PShape shape) Transforms a given PShape into a simple graph representation. In this representation, the vertices of the graph correspond to the vertices of the shape, and the edges of the graph correspond to the edges of the shape. This transformation is specifically applicable to polygonal shapes where edges are formed by adjacent vertices.The edge weights in the graph are set to the length of the corresponding edge in the shape.
- Parameters:
shape
- the PShape to convert into a graph- Returns:
- A SimpleGraph object that represents the structure of the input shape
- Since:
- 1.3.0
- See Also:
-
fromGraph
public static processing.core.PShape fromGraph(org.jgrapht.graph.SimpleGraph<processing.core.PVector, PEdge> graph) Converts a given SimpleGraph consisting of PVectors and PEdges into a PShape by polygonizing its edges. If the graph represented a shape with holes, these will not be preserved during the conversion.- Parameters:
graph
- the graph to be converted into a PShape.- Returns:
- a PShape representing the polygonized edges of the graph.
- Since:
- 1.4.0
-
fromGraph
public static <V,E> processing.core.PShape fromGraph(org.jgrapht.graph.SimpleGraph<V, E> graph, double normalizationFactor, double boundsX, double boundsY) Takes as input a graph and computes a layout for the graph vertices using a Force-Directed placement algorithm (not vertex coordinates, if any exist). Vertices are joined by their edges.The output is a rather abstract representation of the input graph, and not a geometric equivalent (unlike most other conversion methods in the class).
- Type Parameters:
V
- any vertex typeE
- any edge type- Parameters:
graph
- the graph whose edges and vertices to lay outnormalizationFactor
- normalization factor for the optimal distance, between 0 and 1.boundsX
- horizontal vertex boundsboundsY
- vertical vertex bounds- Returns:
- a GROUP PShape consisting of 2 children; child 0 is the linework (LINES) depicting edges and child 1 is the points (POINTS) depicting vertices. The bounds of the layout are anchored at (0, 0);
- Since:
- 1.3.0
-
toDualGraph
public static org.jgrapht.graph.SimpleGraph<processing.core.PShape,org.jgrapht.graph.DefaultEdge> toDualGraph(processing.core.PShape mesh) Converts a mesh-like PShape into its undirected, unweighted dual-graph.The output is a dual graph of the input; it has a vertex for each face (PShape) of the input, and an edge for each pair of faces that are adjacent.
- Parameters:
mesh
- a GROUP PShape, whose children constitute the polygonal faces of a conforming mesh. A conforming mesh consists of adjacent cells that not only share edges, but every pair of shared edges are identical (having the same coordinates) (such as a triangulation).- Returns:
- the dual graph of the input mesh; an undirected graph containing no graph loops or multiple edges.
- Since:
- 1.3.0
- See Also:
-
toCentroidDualGraph
public static org.jgrapht.graph.SimpleGraph<processing.core.PVector,PEdge> toCentroidDualGraph(processing.core.PShape mesh) Converts a mesh-like PShape into its centroid-based undirected dual-graph.The output is a dual graph of the input; it has a vertex for each centroid of the face of the input, and an edge (connecting the centroids) for each pair of faces that are adjacent. Each vertex represents the geometric center or centroid of the respective face in the mesh.
- Parameters:
mesh
- a GROUP PShape, whose children constitute the polygonal faces of a conforming mesh. A conforming mesh consists of adjacent cells that not only share edges, but every pair of shared edges are identical (having the same coordinates) (such as a triangulation).- Returns:
- the centroid-based dual graph of the input mesh; an undirected graph containing no graph loops or multiple edges. Each vertex in the graph represents the centroid of a face in the input mesh, and each edge represents adjacency between two faces.
- Since:
- 1.4.0
- See Also:
-
toWKT
Writes the Well-Known Text representation of a shape. The Well-Known Text format is defined in the OGC Simple Features Specification for SQL.- Parameters:
shape
- shape to process- Returns:
- a Geometry Tagged Text string
- Since:
- 1.3.0
- See Also:
-
fromWKT
Converts a geometry in Well-Known Text format into a PShape.- Parameters:
textRepresentation
- one or more Geometry Tagged Text strings, separated by whitespace- Returns:
- a PShape specified by the text
- Since:
- 1.3.0
- See Also:
-
toWKB
public static byte[] toWKB(processing.core.PShape shape) Writes a shape into Well-Known Binary format. The WKB format is specified in the OGC Simple Features for SQL specification.- Parameters:
shape
- shape to process- Returns:
- WKB byte representation of shape
- Since:
- 1.3.0
- See Also:
-
toWKB
Converts a shape into Well-Known Binary format and writes the bytes to a file.- Parameters:
shape
- shape to processfilename
- Absolute file path (with filename and extension). Prefix with "./" for a relative path.- Since:
- 1.4.0
-
fromWKB
public static processing.core.PShape fromWKB(byte[] shapeWKB) Converts a geometry in Well-Known Binary format into a PShape.- Parameters:
shapeWKB
- byte representation of shape to process- Returns:
- a PShape specified by the WKB
- Since:
- 1.3.0
- See Also:
-
fromWKB
Reads a shape from a (binary) file containing the Well-Known Binary representation of it.- Parameters:
filename
- Absolute file path (with filename and extension). Prefix with "./" for a relative path.- Returns:
- a PShape specified by the WKB in the file
-
toHexWKB
Writes a shape into the hexadecimal string representation of its Well-Known Binary format.- Parameters:
shape
- shape to process- Returns:
- hexadecimal string representation of shape WKB
- Since:
- 1.3.0
- See Also:
-
fromHexWKB
Converts a geometry in Well-Known Binary hex format into a PShape.- Parameters:
shapeWKB
- hex string WKB representation of shape to process- Returns:
- a PShape specified by the WKB
- Since:
- 1.3.0
- See Also:
-
toEncodedPolyline
Writes a single holeless shape into the string representation of its Google Encoded Polyline format.- Parameters:
shape
- single (holeless) polygon or line- Returns:
- Since:
- 1.3.0
-
fromEncodedPolyline
Converts a geometry in Encoded Polyline format into a PShape.- Parameters:
encodedPolyline
- an encoded polyline string representing a shape- Returns:
- a PShape represented by the encoded polyline string
- Since:
- 1.3.0
-
toGeoJSON
Writes a shape into the string representation of its GeoJSON format.- Parameters:
shape
-- Returns:
- json JSON string
- Since:
- 1.3.0
-
fromGeoJSON
Converts a GeoJSON representation of a shape into its PShape counterpart.- Parameters:
json
- GeoJSON string- Returns:
- PShape represented by the GeoJSON
- Since:
- 1.3.0
-
toJava2D
Creates a Java2D/java.awt Shape representing a PShape.- Parameters:
shape
- the PShape to convert- Returns:
- a Java2D shape representing the PShape
- Since:
- 1.3.0
-
fromJava2D
Converts a Java2D/java.awt Shape to a Processing PShape.If the shape contains bezier components (such as
CubicCurve2D
, these are decomposed into straight-line segments in the output.- Parameters:
shape
- the Java2D shape to convert- Returns:
- a PShape representing the Java2D shape
- Since:
- 1.3.0
-
fromPVector
Generates a shape from a list of vertices. If the list of vertices is closed (first and last vertices are the same), the vertices are interpreted as a closed polygon (having no holes); if the list is unclosed, they are treated as a linestring.- Parameters:
vertices
- list of (un)closed shape vertices- Returns:
- a PATH PShape (either open linestring or closed polygon)
- See Also:
-
fromPVector
public static processing.core.PShape fromPVector(processing.core.PVector... vertices) Generates a shape from a list of vertices. If the list of vertices is closed (first and last vertices are the same), the vertices are interpreted as a closed polygon (having no holes); if the list is unclosed, they are treated as a linestring.- Parameters:
vertices
- list of (un)closed shape vertices- Returns:
- a PATH PShape (either open linestring or closed polygon)
- See Also:
-
fromContours
public static processing.core.PShape fromContours(List<processing.core.PVector> shell, @Nullable List<List<processing.core.PVector>> holes) Generates a polygonal shape from lists of vertices representing its shell and holes.According to Processing shape definitions, the shell should be orientated CW and the holes CCW, but this method will detect orientation and handle it accordingly, so the orientation of input does not matter.
- Parameters:
shell
- vertices of the shell of the polygonholes
- (optional) list of holes- Returns:
- Since:
- 1.4.0
-
toArray
public static double[][] toArray(processing.core.PShape shape, boolean keepClosed) Converts a simple PShape into an array of its coordinates.- Parameters:
shape
- a simple shape (closed polygon or open line) represented by a coordinate array [[x1, y1], [x2, y2]...]keepClosed
- flag to determine whether to keep the (last) closing vertex in the output if the input forms a closed polygon- Returns:
- coordinate array in the form [[x1, y1], [x2, y2]]
- Since:
- 1.4.0 an array of coordinates representing the PShape
- See Also:
-
fromArray
public static processing.core.PShape fromArray(double[][] shape, boolean close) Creates a PShape from an array of doubles representing coordinates.- Parameters:
shape
- coordinate array representing a simple shape (closed polygon or open line) [[x1, y1], [x2, y2]...]close
- close the coordinates (if unclosed)- Returns:
- a PShape represented by the coordinates
- Since:
- 1.4.0
- See Also:
-
flatten
Flattens a collection of PShapes into a single GROUP PShape which has the input shapes as its children.- Since:
- 1.2.0
- See Also:
-
flatten
public static processing.core.PShape flatten(processing.core.PShape... shapes) Flattens a collection of PShapes into a single GROUP PShape which has the input shapes as its children.- Since:
- 1.3.0
- See Also:
-
getChildren
Recurses a GROUP PShape, finding all of its non-GROUP child PShapes. If the shape type is not GROUP, only it is returned.Note: this method differs from
PShape.getChildren()
. That method will return GROUP child shapes, whereas this method will recurse such shapes, returing their non-group children (in other words, this method explores the whole tree of shapes, returning non-group shapes only).- Parameters:
shape
-- Returns:
- a list of non-GROUP PShapes
- Since:
- 1.2.0
-
fromChildren
Creates a single GROUP shape whose children shapes are the list given.- Parameters:
children
-- Returns:
- a GROUP PShape consisting of the given children
-
getFillColor
public static int getFillColor(processing.core.PShape shape) Retrieves the fill color of a PShape.- Parameters:
shape
- The PShape object for which to retrieve the fill color.- Returns:
- The integer representation of the fill color in ARGB format (32-bit).
- Since:
- 1.4.0
-
setAllFillColor
public static processing.core.PShape setAllFillColor(processing.core.PShape shape, int color) Sets the fill color for the PShape and all of its children recursively (and disables stroke).- Parameters:
shape
-- Returns:
- the input object (having now been mutated)
- See Also:
-
setAllStrokeColor
public static processing.core.PShape setAllStrokeColor(processing.core.PShape shape, int color, double strokeWeight) Sets the stroke color for the PShape and all of its children recursively.- Parameters:
shape
-- Returns:
- the input object (having now been mutated)
- See Also:
-
setAllStrokeToFillColor
public static processing.core.PShape setAllStrokeToFillColor(processing.core.PShape shape) Sets the stroke color equal to the fill color for the PShape and all of its descendent shapes individually (that is, each child shape belonging to the shape (if any) will have its stroke color set to its own fill color, and not the parent-most shape's fill color).- Parameters:
shape
-- Returns:
- the input object (having now been mutated)
- Since:
- 1.2.0
-
setAllStrokeToFillColor
public static processing.core.PShape setAllStrokeToFillColor(processing.core.PShape shape, double strokeWeight) Sets the stroke color equal to the fill color, and the strokeWeight to the specified value, for the PShape and all of its descendent shapes individually (that is, each child shape belonging to the shape (if any) will have its stroke color set to its own fill color, and not the parent-most shape's fill color).- Parameters:
shape
-- Returns:
- the input object (having now been mutated)
- Since:
- 1.3.0
-
getShapeStylingData
Retrieves the styling data associated with the specified PShape object. The method creates an instance of PShapeData containing the fill, stroke, fill color, stroke color, and stroke weight extracted from the PShape.- Parameters:
shape
- the PShape instance from which to extract styling information.- Returns:
- a PShapeData object with the extracted styling properties of the shape.
- Since:
- 2.0
-
reorderChildren
public static processing.core.PShape reorderChildren(processing.core.PShape shape, Comparator<processing.core.PShape> comparator) Reorders the child shapes of a given shape.Creates a new GROUP shape, having the same children as the input, but in a different order; child shapes of the new shape are ordered according to the given comparator.
- Parameters:
shape
- a GROUP shapecomparator
- PShape comparison function- Returns:
- a new GROUP PShape object having its children in a different order. Child shapes reference the same objects as the input.
- Since:
- 1.4.0
-
disableAllFill
public static processing.core.PShape disableAllFill(processing.core.PShape shape) Calls setFill(false) on a PShape and all its children. This method mutates the input shape.- Parameters:
shape
-- Returns:
- the input object (having now been mutated)
-
disableAllStroke
public static processing.core.PShape disableAllStroke(processing.core.PShape shape) Calls setStroke(false) on a PShape and all its children. This method mutates the input shape.- Parameters:
shape
-- Returns:
- the input object (having now been mutated)
-
roundVertexCoords
public static processing.core.PShape roundVertexCoords(processing.core.PShape shape) Rounds the x and y coordinates (to the closest int) of all vertices belonging to the shape, mutating the shape. This can sometimes fix a visual problem in Processing where narrow gaps can appear between otherwise flush shapes.- Returns:
- the input object (having now been mutated)
- Since:
- 1.1.3
-
copy
public static processing.core.PShape copy(processing.core.PShape shape) Produces a deep copy / clone of the input shape. Handles GROUP, PRIMITIVE, GEOMETRY and PATH PShapes. Clones both geometry and styling.- Parameters:
shape
- the PShape to copy- Returns:
- a deep copy of the given shape
- Since:
- 1.2.0
-
fromQuadraticBezier
public static processing.core.PShape fromQuadraticBezier(processing.core.PVector start, processing.core.PVector controlPoint, processing.core.PVector end) Creates a PATH PShape representing a quadratic bezier curve, given by its parameters.- Parameters:
start
-controlPoint
-end
-- Returns:
- Since:
- 1.4.0
-
fromCubicBezier
public static processing.core.PShape fromCubicBezier(processing.core.PVector start, processing.core.PVector controlPoint1, processing.core.PVector controlPoint2, processing.core.PVector end) Creates a PATH PShape representing a cubic bezier curve, given by its parameters.- Parameters:
start
-controlPoint1
-controlPoint2
-end
-- Returns:
- Since:
- 1.4.0
-