Skip to content

Commit 8d850d6

Browse files
committed
front-chain packer algo change
1 parent 1e61ee6 commit 8d850d6

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/main/java/micycle/pgs/PGS_CirclePacking.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
import org.locationtech.jts.geom.Envelope;
1616
import org.locationtech.jts.geom.Geometry;
1717
import org.locationtech.jts.geom.Location;
18-
import org.locationtech.jts.geom.prep.PreparedGeometry;
19-
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
2018
import org.locationtech.jts.operation.distance.IndexedFacetDistance;
21-
import org.locationtech.jts.util.GeometricShapeFactory;
2219
import org.tinfour.common.IIncrementalTin;
2320
import org.tinfour.common.SimpleTriangle;
2421
import org.tinfour.common.Vertex;
@@ -287,28 +284,21 @@ public static List<PVector> frontChainPack(PShape shape, double radiusMin, doubl
287284
IndexedPointInAreaLocator pointLocator;
288285

289286
final FrontChainPacker packer = new FrontChainPacker((float) e.getWidth(), (float) e.getHeight(), (float) radiusMin,
290-
(float) radiusMax, (float) e.getMinX(), (float) e.getMinY());
287+
(float) radiusMax, (float) e.getMinX(), (float) e.getMinY(), seed);
291288

292289
if (radiusMin == radiusMax) {
293290
// if every circle same radius, use faster contains check
294291
pointLocator = new IndexedPointInAreaLocator(g.buffer(radiusMax));
295292
packer.getCircles().removeIf(p -> pointLocator.locate(PGS.coordFromPVector(p)) == Location.EXTERIOR);
296293
} else {
297294
pointLocator = new IndexedPointInAreaLocator(g);
298-
final PreparedGeometry cache = PreparedGeometryFactory.prepare(g);
299-
final GeometricShapeFactory circleFactory = new GeometricShapeFactory();
300-
circleFactory.setNumPoints(8); // approximate circles using octagon for intersects check
295+
IndexedFacetDistance distance = new IndexedFacetDistance(g);
301296
packer.getCircles().removeIf(p -> {
302297
// first test whether shape contains circle center point (somewhat faster)
303298
if (pointLocator.locate(PGS.coordFromPVector(p)) != Location.EXTERIOR) {
304299
return false;
305300
}
306-
307-
// if center point not in circle, check whether circle overlaps with shape using
308-
// intersects() (somewhat slower)
309-
circleFactory.setCentre(PGS.coordFromPVector(p));
310-
circleFactory.setSize(p.z * 2); // set diameter
311-
return !cache.intersects(circleFactory.createCircle());
301+
return !distance.isWithinDistance(PGS.pointFromPVector(p), p.z * 0.666);
312302
});
313303
}
314304

0 commit comments

Comments
 (0)