Skip to content

Commit

Permalink
GEOMETRY-110
Browse files Browse the repository at this point in the history
Create simplex while appending and cache it for later.
  • Loading branch information
Andreas Goss committed Oct 30, 2023
1 parent 82dc2eb commit d952130
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public static class Builder {
/** Precision context used to compare floating point numbers. */
private final DoubleEquivalence precision;

/** Simplex for testing new points and starting the algorithm. */
private Simplex simplex;

/**
* A map which contains all the vertices of the current hull as keys and the
* associated facets as values.
Expand Down Expand Up @@ -186,7 +189,11 @@ public Builder append(Vector3D point) {
* @return this instance.
*/
public Builder append(Collection<Vector3D> points) {
points.forEach(this::append);
simplex = createSimplex(points);
candidates.addAll(points);
if (!simplex.isDegenerate()) {
distributePoints(simplex);
}
return this;
}

Expand All @@ -196,13 +203,10 @@ public Builder append(Collection<Vector3D> points) {
* @return a convex hull containing all appended points.
*/
public ConvexHull3D build() {
if (candidates.size() < 4) {
if (simplex == null) {
return new ConvexHull3D(candidates, true);
}

// Construct an initial simplex with extreme properties.
Simplex simplex = createSimplex(candidates);

// The simplex is degenerate.
if (simplex.isDegenerate()) {
return new ConvexHull3D(candidates, true);
Expand Down

0 comments on commit d952130

Please sign in to comment.