public final class PGS_ShapePredicates extends Object
Modifier and Type | Method and Description |
---|---|
static double |
area(processing.core.PShape shape)
Computes the area of the given shape.
|
static processing.core.PVector |
centroid(processing.core.PShape shape)
Computes the centroid of a shape.
|
static double |
circularity(processing.core.PShape shape)
Calculates the Miller circularity index for a shape.
|
static boolean |
contains(processing.core.PShape outer,
processing.core.PShape inner)
Determines whether the outer shape fully contains the inner shape.
|
static boolean |
containsAllPoints(processing.core.PShape shape,
Collection<processing.core.PVector> points)
Determines whether a shape contains every point from a list of points.
|
static boolean |
containsPoint(processing.core.PShape shape,
processing.core.PVector point)
Determines whether a shape contains a point.
|
static List<Boolean> |
containsPoints(processing.core.PShape shape,
Collection<processing.core.PVector> points)
Measures for each point in the input whether it is contained in the given
shape.
|
static double |
convexity(processing.core.PShape shape)
Computes the convexity of a shape using a simple area-based measure of
convexity.
|
static double |
density(processing.core.PShape shape)
Computes the ratio (density) of the shape's area compared to the area of it's
envelope.
|
static double |
diameter(processing.core.PShape shape)
Returns the diameter of a shape.
|
static double |
distance(processing.core.PShape a,
processing.core.PShape b)
Computes the minimum distance between two shapes.
|
static double |
efdSimilarity(processing.core.PShape a,
processing.core.PShape b)
Quantifies the similarity between two shapes, by using the pairwise euclidean
distance between each shape's Elliptic Fourier Descriptors (EFD).
|
static double |
elongation(processing.core.PShape shape)
Measures the elongation of a shape; the ratio of a shape's bounding box
length to its width.
|
static boolean |
equalsExact(processing.core.PShape a,
processing.core.PShape b)
Tests two shapes for structural equality.
|
static boolean |
equalsNorm(processing.core.PShape a,
processing.core.PShape b)
Tests two shapes for normalised structural equality.
|
static boolean |
equalsTopo(processing.core.PShape a,
processing.core.PShape b)
Tests two shapes for topological equality.
|
static List<processing.core.PVector> |
findContainedPoints(processing.core.PShape shape,
Collection<processing.core.PVector> points)
Tests for each point in the input whether it is contained in/inside the given
shape; if it is, then the point is included in the output list.
|
static processing.core.PShape |
findContainingShape(processing.core.PShape groupShape,
processing.core.PVector point)
Finds the single child shape/cell (if any) that contains the query point from
a GROUP shape input (a shape that has non-overlapping children).
|
static double |
height(processing.core.PShape shape)
Computes the vertical height of a shape (the height of its bounding-box).
|
static int |
holes(processing.core.PShape shape)
Counts the number of holes in a shape.
|
static boolean |
intersect(processing.core.PShape a,
processing.core.PShape b)
Determines whether the shapes intersect/overlap (meaning that have at least
one point in common).
|
static boolean |
isConformingMesh(processing.core.PShape mesh)
Determines whether a GROUP shape forms a conforming mesh / valid polygon
coverage.
|
static boolean |
isConvex(processing.core.PShape shape)
Determines whether a shape is convex.
|
static boolean |
isSimple(processing.core.PShape shape)
Checks whether a shape is simple.
|
static boolean |
isValid(processing.core.PShape shape)
Checks if a PShape is valid, and reports the validation error if it is
invalid.
|
static double |
length(processing.core.PShape shape)
Returns the length of a shape.
|
static double |
maximumInteriorAngle(processing.core.PShape shape)
Computes the maximum/largest interior angle of a polygon.
|
static processing.core.PVector |
median(processing.core.PShape shape)
Computes the geometric median location of a shape's vertices.
|
static double |
overlap(processing.core.PShape a,
processing.core.PShape b)
Measures the degree of mutual overlap between two shapes.
|
static double |
similarity(processing.core.PShape a,
processing.core.PShape b)
Measures the degree of similarity between two shapes using the Hausdorff
distance metric.
|
static double |
sphericity(processing.core.PShape shape)
Measures the sphericity of a shape; the ratio of the maximum inscribed circle
to the minimum bounding circle.
|
static boolean |
touch(processing.core.PShape a,
processing.core.PShape b)
Determines whether the have at least one point in common, but where their
interiors do not intersect.
|
static double |
width(processing.core.PShape shape)
Computes the horizontal width of a shape (the width of its bounding-box).
|
public static boolean contains(processing.core.PShape outer, processing.core.PShape inner)
outer
- inner
- public static boolean containsPoint(processing.core.PShape shape, processing.core.PVector point)
shape
- point
- containsAllPoints(PShape, Collection)
,
containsPoints(PShape, Collection)
public static boolean containsAllPoints(processing.core.PShape shape, Collection<processing.core.PVector> points)
containsPoint()
repeatedly. Any
points that lie on the boundary of the shape are considered to be contained.shape
- points
- list of points to checkpublic static List<Boolean> containsPoints(processing.core.PShape shape, Collection<processing.core.PVector> points)
containsPoint()
repeatedly. Points
that lie on the boundary of the shape are considered to be contained.shape
- points
- list of points to checkpublic static List<processing.core.PVector> findContainedPoints(processing.core.PShape shape, Collection<processing.core.PVector> points)
Using this method is faster than calling
containsPoint()
repeatedly.
shape
- points
- list of points to checkpublic static processing.core.PShape findContainingShape(processing.core.PShape groupShape, processing.core.PVector point)
This method locates the containing shape in log(n) time (after some pre-processing overhead).
groupShape
- a GROUP shapepoint
- the query pointpublic static boolean intersect(processing.core.PShape a, processing.core.PShape b)
Note that the input shapes may be lineal (open path) or polygonal (closed path), and this affects the meaning of the method. The following intersection tests are performed based on the type combinations of the shapes:
a
- b
- public static boolean touch(processing.core.PShape a, processing.core.PShape b)
a
- b
- public static double distance(processing.core.PShape a, processing.core.PShape b)
a
- shape Ab
- shape Bpublic static double area(processing.core.PShape shape)
shape
- public static double density(processing.core.PShape shape)
shape
- public static processing.core.PVector centroid(processing.core.PShape shape)
If the input is a polygon, the centroid will always lie inside it.
shape
- public static processing.core.PVector median(processing.core.PShape shape)
The median point is the point that minimises the sum of distances to the shape vertices. If the input is a concave polygon, the median may not lie inside it.
shape
- public static double width(processing.core.PShape shape)
public static double height(processing.core.PShape shape)
public static double length(processing.core.PShape shape)
public static double diameter(processing.core.PShape shape)
shape
- public static double circularity(processing.core.PShape shape)
shape
- public static double similarity(processing.core.PShape a, processing.core.PShape b)
a
- first shapeb
- second shapepublic static double overlap(processing.core.PShape a, processing.core.PShape b)
This metric aggregates how much each shape is overlapped (fractional), weighted by its respective area.
a
- first shapeb
- second shapepublic static double sphericity(processing.core.PShape shape)
shape
- public static double elongation(processing.core.PShape shape)
shape
- public static double convexity(processing.core.PShape shape)
shape
- public static int holes(processing.core.PShape shape)
If the shape forms a polygon coverage (a mesh), then this method will count holes from gaps within the mesh.
shape
- a polygonal shape (can be a GROUP shape having multiple
polygons)public static double maximumInteriorAngle(processing.core.PShape shape)
shape
- simple polygonal shapepublic static double efdSimilarity(processing.core.PShape a, processing.core.PShape b)
Smaller values indicate greater similarity or equivalence, and the measure is translation and rotation invariant.
This method can be useful in shape recognition tasks where it is necessary to quantify the difference or similarity between two shapes.
a
- polygonal shapeb
- polygonal shapepublic static boolean equalsExact(processing.core.PShape a, processing.core.PShape b)
Note: If two Polygons have matching vertices, but one is arranged clockwise while the other is counter-clockwise, then then this method will return false.
a
- shape ab
- shape bequalsNorm(PShape, PShape)
,
equalsTopo(PShape, PShape)
public static boolean equalsNorm(processing.core.PShape a, processing.core.PShape b)
equalsExact(PShape, PShape)
, vertices do not need
to be in the same order for the shapes to be considered equal.a
- shape ab
- shape bequalsExact(PShape, PShape)
,
equalsTopo(PShape, PShape)
public static boolean equalsTopo(processing.core.PShape a, processing.core.PShape b)
a
- shape ab
- shape bequalsExact(PShape, PShape)
,
equalsTopo(PShape, PShape)
public static boolean isSimple(processing.core.PShape shape)
public static boolean isConvex(processing.core.PShape shape)
public static boolean isConformingMesh(processing.core.PShape mesh)
Conforming meshes comprise faces that do not intersect; any adjacent faces not only share edges, but every pair of shared edges are identical (having the same coordinates) (such as a triangulation).
mesh
- shape to testpublic static boolean isValid(processing.core.PShape shape)
An invalid shape is one that violates the rules of geometric validity. Some common reasons for a shape to be considered invalid include:
shape
- The PShape to validate.true
if the shape is valid, false
otherwise.Copyright © 2023. All rights reserved.