Skip to content

Commit

Permalink
small improvements / javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
micycle1 committed Feb 18, 2024
1 parent 6bd8904 commit ef23b3b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 45 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ Docs are hosted via *GitHub Pages* [here](https://micycle1.github.io/PGS/).
Library functionality is split over the following classes:

* `PGS_CirclePacking`
* Circle packings of shapes, subject to varying constraints and patterns of tangencies
* Circle packings of shapes, subject to varying constraints and patterns of tangencies.
* `PGS_Coloring`
* Minimal colorings of meshes (or mesh-like shapes)
* Minimal colorings of meshes (or mesh-like shapes).
* `PGS_Construction`
* Construct uncommon/interesting 2D primitives
* Construct uncommon/interesting 2D primitives.
* `PGS_Contour`
* Methods that produce various contours from shapes: medial axes, straight skeletons, offset curves, etc.
* `PGS_Conversion`
* Conversion between *Processing* PShapes and *JTS* Geometries (amongst other formats)
* `PGS_Hull`
* Convex and concave hulls of polygons and point sets
* Convex and concave hulls of polygons and point sets.
* `PGS_Meshing`
* Mesh generation (excluding triangulation) and processing
* Mesh generation (excluding triangulation) and processing.
* `PGS_Morphology`
* Methods that affect the geometry or topology of shapes (buffering, simplification, smoothing, etc.)
* Methods that affect the geometry or topology of shapes (buffering, simplification, smoothing, etc.).
* `PGS_Optimisation`
* Solve geometric optimisation problems, such as finding the maximum inscribed circle, or the closest vertex to a coordinate
* Solve geometric optimisation problems, such as finding the maximum inscribed circle, or the closest vertex to a coordinate.
* `PGS_PointSet`
* Generates sets of 2D points having a variety of different distributions and constraints
* Generates sets of 2D points having a variety of different distributions and constraints.
* `PGS_Processing`
* Methods that process a shape in some way: compute hulls, partition, slice, etc.
* Methods that process a shape in some way: partition, slice, clean, etc.
* `PGS_SegmentSet`
* Generates sets of random non-intersecting line segments
* Generates sets of random non-intersecting line segments.
* `PGS_ShapeBoolean`
* Boolean set-operations for 2D shapes
* Boolean set-operations for 2D shapes.
* `PGS_ShapePredicates`
* Various shape metrics (area, circularity, etc.) and predicates (*"do these shapes intersect?"*)
* Various shape metrics (area, circularity, etc.) and predicates (*"do these shapes intersect?"*).
* `PGS_Tiling`
* Tiling, tessellation and subdivision of the plane using periodic or non-periodic geometric shapes.
* `PGS_Transformation`
* Various geometric and affine transformations that affect vertex coordinates
* Various geometric and affine transformations that affect vertex coordinates.
* `PGS_Triangulation`
* Delaunay triangulation (constrained and refined) and earcut triangulation of shapes and point sets
* Delaunay triangulation (constrained and refined) and earcut triangulation of shapes and point sets.
* `PGS_Voronoi`
* Voronoi Diagrams of shapes and point sets
* Voronoi Diagrams of shapes and point sets.

## **Installation**

Expand Down
32 changes: 16 additions & 16 deletions src/main/java/micycle/pgs/PGS.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,6 @@ static final boolean isClockwise(List<PVector> points) {
return (area < 0);
}

/**
* Polygonizes a set of edges.
*
* @param edges a collection of NODED (i.e. non intersecting / must only meet at
* their endpoints) edges. The collection can contain duplicates.
* @return a GROUP PShape, where each child shape represents a polygon face
* formed by the given edges
*/
static final PShape polygonizeEdges(Collection<PEdge> edges) {
return polygonizeEdgesRobust(edges);
}

/**
* Nodes (optional) then polygonizes a set of line segments.
*
Expand All @@ -257,6 +245,18 @@ static final PShape polygonizeSegments(Collection<SegmentString> segments, boole
return polygonizeEdges(meshEdges);
}

/**
* Polygonizes a set of edges.
*
* @param edges a collection of NODED (i.e. non intersecting / must only meet at
* their endpoints) edges. The collection can contain duplicates.
* @return a GROUP PShape, where each child shape represents a polygon face
* formed by the given edges
*/
static final PShape polygonizeEdges(Collection<PEdge> edges) {
return polygonizeEdgesRobust(edges);
}

/**
* Polygonizes a set of edges using JTS Polygonizer (occasionally
* FastPolygonizer is not robust enough).
Expand All @@ -273,10 +273,10 @@ private static final PShape polygonizeEdgesRobust(Collection<PEdge> edges) {
polygonizer.setCheckRingsValid(false);
edgeSet.forEach(ss -> {
/*
* If the same LineString is added more than once to the polygonizer, the string
* is "collapsed" and not counted as an edge. Therefore a set is used to ensure
* strings are added once only to the polygonizer. A PEdge is used to determine
* this (since LineString hashcode doesn't work).
* NOTE: If the same LineString is added more than once to the polygonizer, the
* string is "collapsed" and not counted as an edge. Therefore a set is used to
* ensure strings are added once only to the polygonizer. A PEdge is used to
* determine this (since LineString hashcode doesn't work).
*/
final LineString l = createLineString(ss.a, ss.b);
polygonizer.add(l);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/micycle/pgs/PGS_Meshing.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static PShape spannerFaces(final IIncrementalTin triangulation, int k, fi
.map(PGS_Triangulation::toPEdge).collect(Collectors.toList()));
}
}

PShape mesh = PGS.polygonizeEdges(spannerEdges);

return removeHoles(mesh, triangulation);
Expand Down Expand Up @@ -588,6 +588,7 @@ public static PShape nodeNonMesh(PShape shape) {
}
}
return PGS.polygonizeSegments(segmentStrings, true);
// return PGS.polygonizeSegments(SegmentStringUtil.extractSegmentStrings(fromPShape(shape)), true);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/micycle/pgs/PGS_PointSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -911,11 +911,13 @@ public static PShape minimumSpanningTree(List<PVector> points) {
* provided. Utilises a heuristic based TSP solver, starting with the farthest
* insertion method followed by 2-opt heuristic improvements for tour
* optimization.
*
* <p>
* Note: The algorithm's runtime grows rapidly as the number of points
* increases. Large datasets (>1000) may result in long computation times and
* should be used with caution.
* <p>
* Note {@link PGS_Hull#concaveHullBFS(List, double) concaveHullBFS()} produces
* a similar result (somewhat longer tours) but is <b>much</b> more performant.
*
* @param points the list of points for which to compute the approximate
* shortest tour
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/micycle/pgs/PGS_ShapeBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static micycle.pgs.PGS_Conversion.fromPShape;
import static micycle.pgs.PGS_Conversion.toPShape;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -14,6 +13,7 @@
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.locationtech.jts.geom.util.GeometryFixer;
import org.locationtech.jts.operation.overlayng.CoverageUnion;
import org.locationtech.jts.operation.overlayng.OverlayNG;
import org.locationtech.jts.operation.union.UnaryUnionOp;
Expand Down Expand Up @@ -136,9 +136,11 @@ public static PShape union(final PShape a, final PShape b) {
* @see #union(PShape...) For union operations on a variable number of shapes.
*/
public static PShape union(final Collection<PShape> shapes) {
Collection<Geometry> polygons = new ArrayList<>();
shapes.forEach(s -> polygons.add(fromPShape(s)));
return toPShape(UnaryUnionOp.union(polygons));
try {
return toPShape(UnaryUnionOp.union(shapes.stream().map(s -> fromPShape(s)).toList()));
} catch (Exception e) {
return toPShape(UnaryUnionOp.union(shapes.stream().map(s -> GeometryFixer.fix(fromPShape(s))).toList()));
}
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/micycle/pgs/PGS_Transformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static PShape scale(PShape shape, double scaleX, double scaleY) {
AffineTransformation t = AffineTransformation.scaleInstance(scaleX, scaleY, c.getX(), c.getY());
return toPShape(t.transform(g));
}

/**
* Scale a shape around a point.
*
Expand Down Expand Up @@ -452,8 +452,8 @@ public static PShape homotheticTransformation(PShape shape, PVector center, doub
* sourceShape.
* @since 1.4.0
*/
public static PShape align(PShape sourceShape, PShape transformShape) {
return align(sourceShape, transformShape, 1);
public static PShape align(PShape alignShape, PShape baseShape) {
return align(alignShape, baseShape, 1);
}

/**
Expand All @@ -472,7 +472,7 @@ public static PShape align(PShape sourceShape, PShape transformShape) {
* position. 0 means no transformation, 1 means maximum
* alignment.
* @return a new PShape that is the transformed and aligned version of
* sourceShape.
* alignShape.
* @since 1.4.0
*/
public static PShape align(PShape alignShape, PShape baseShape, double alignmentRatio) {
Expand All @@ -490,10 +490,10 @@ public static PShape align(PShape alignShape, PShape baseShape, double alignment
PShape sourceShapeT = alignShape;
PShape transformShapeT = baseShape;
if (alignShape.getVertexCount() > vertices) {
sourceShapeT = PGS_Morphology.simplifyDCE(alignShape, vertices);
sourceShapeT = PGS_Morphology.simplifyDCE(alignShape, (v, r, verticesRemaining) -> verticesRemaining <= vertices);
}
if (baseShape.getVertexCount() > vertices) {
transformShapeT = PGS_Morphology.simplifyDCE(baseShape, vertices);
transformShapeT = PGS_Morphology.simplifyDCE(baseShape, (v, r, verticesRemaining) -> verticesRemaining <= vertices);
}

double[] m = ProcrustesAlignment.transform((Polygon) fromPShape(sourceShapeT), (Polygon) fromPShape(transformShapeT));
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/micycle/pgs/commons/DiscreteCurveEvolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public interface DCETerminationCallback {
* @param relevance The relevance score of the current kink. A value of
* 30 or lower is generally imperceptible.
* @param verticesRemaining The number of vertices remaining in the simplified
* geometry. Note: this does not count the closing
* vertex of closed geometries.
* geometry (including the current candidate vertex).
* Note: this does not count the closing vertex of
* closed geometries.
* @return {@code true} if the DCE process should terminate; {@code false}
* otherwise.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/micycle/pgs/commons/RectangularSubdivision.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.SplittableRandom;

import micycle.pgs.color.Colors;
import processing.core.PConstants;
import processing.core.PShape;

Expand Down Expand Up @@ -130,6 +131,7 @@ private void rect(double x1, double y1, double x2, double y2, double x3, double
// rect(x1, y1, x3 - x1, y3 - y1);
final PShape rect = new PShape(PShape.PATH);
rect.setFill(true);
rect.setFill(Colors.PINK);
rect.setStroke(true);
rect.setStroke(255);
rect.beginShape();
Expand Down

0 comments on commit ef23b3b

Please sign in to comment.