Skip to content

Commit

Permalink
front-chain packer algo change
Browse files Browse the repository at this point in the history
  • Loading branch information
micycle1 committed May 21, 2024
1 parent 1e61ee6 commit 8d850d6
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/main/java/micycle/pgs/PGS_CirclePacking.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Location;
import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.locationtech.jts.operation.distance.IndexedFacetDistance;
import org.locationtech.jts.util.GeometricShapeFactory;
import org.tinfour.common.IIncrementalTin;
import org.tinfour.common.SimpleTriangle;
import org.tinfour.common.Vertex;
Expand Down Expand Up @@ -287,28 +284,21 @@ public static List<PVector> frontChainPack(PShape shape, double radiusMin, doubl
IndexedPointInAreaLocator pointLocator;

final FrontChainPacker packer = new FrontChainPacker((float) e.getWidth(), (float) e.getHeight(), (float) radiusMin,
(float) radiusMax, (float) e.getMinX(), (float) e.getMinY());
(float) radiusMax, (float) e.getMinX(), (float) e.getMinY(), seed);

if (radiusMin == radiusMax) {
// if every circle same radius, use faster contains check
pointLocator = new IndexedPointInAreaLocator(g.buffer(radiusMax));
packer.getCircles().removeIf(p -> pointLocator.locate(PGS.coordFromPVector(p)) == Location.EXTERIOR);
} else {
pointLocator = new IndexedPointInAreaLocator(g);
final PreparedGeometry cache = PreparedGeometryFactory.prepare(g);
final GeometricShapeFactory circleFactory = new GeometricShapeFactory();
circleFactory.setNumPoints(8); // approximate circles using octagon for intersects check
IndexedFacetDistance distance = new IndexedFacetDistance(g);
packer.getCircles().removeIf(p -> {
// first test whether shape contains circle center point (somewhat faster)
if (pointLocator.locate(PGS.coordFromPVector(p)) != Location.EXTERIOR) {
return false;
}

// if center point not in circle, check whether circle overlaps with shape using
// intersects() (somewhat slower)
circleFactory.setCentre(PGS.coordFromPVector(p));
circleFactory.setSize(p.z * 2); // set diameter
return !cache.intersects(circleFactory.createCircle());
return !distance.isWithinDistance(PGS.pointFromPVector(p), p.z * 0.666);
});
}

Expand Down

0 comments on commit 8d850d6

Please sign in to comment.