darkma773r commented on code in PR #225: URL: https://github.com/apache/commons-geometry/pull/225#discussion_r1398625096
########## commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/hull/ConvexHull3D.java: ########## @@ -0,0 +1,697 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.geometry.euclidean.threed.hull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.commons.geometry.core.ConvexHull; +import org.apache.commons.geometry.core.collection.PointSet; +import org.apache.commons.geometry.euclidean.EuclideanCollections; +import org.apache.commons.geometry.euclidean.threed.ConvexPolygon3D; +import org.apache.commons.geometry.euclidean.threed.ConvexVolume; +import org.apache.commons.geometry.euclidean.threed.Plane; +import org.apache.commons.geometry.euclidean.threed.Planes; +import org.apache.commons.geometry.euclidean.threed.Vector3D; +import org.apache.commons.geometry.euclidean.threed.line.Line3D; +import org.apache.commons.geometry.euclidean.threed.line.Lines3D; +import org.apache.commons.numbers.core.Precision.DoubleEquivalence; + +/** + * This class represents a convex hull in three-dimensional Euclidean space. + */ +public class ConvexHull3D implements ConvexHull<Vector3D> { + + /** The vertices of the convex hull. */ + private final List<Vector3D> vertices; + + /** The region defined by the hull. */ + private final ConvexVolume region; + + /** A collection of all facets that form the convex volume of the hull. */ + private final Collection<ConvexPolygon3D> facets; + + /** Flag for when the hull is degenerate. */ + private final boolean isDegenerate; + + /** + * Simple constructor no validation performed. This constructor is called if the + * hull is well-formed and non-degenerative. + * + * @param facets the facets of the hull. + */ + ConvexHull3D(Collection<? extends ConvexPolygon3D> facets) { + vertices = Collections + .unmodifiableList(facets.stream().flatMap(f -> f.getVertices().stream()).collect(Collectors.toList())); + region = ConvexVolume.fromBounds(() -> facets.stream().map(ConvexPolygon3D::getPlane).iterator()); + this.facets = Collections.unmodifiableSet(new HashSet<>(facets)); + this.isDegenerate = false; + } + + /** + * Simple constructor no validation performed. No Region is formed as it is + * assumed that the hull is degenerate. + * + * @param points the given vertices of the hull. + * @param isDegenerate boolean flag + */ + ConvexHull3D(Collection<Vector3D> points, boolean isDegenerate) { + vertices = Collections.unmodifiableList(new ArrayList<>(points)); + region = null; + this.facets = Collections.emptySet(); + this.isDegenerate = isDegenerate; + } + + /** {@inheritDoc} */ + @Override + public List<Vector3D> getVertices() { + return vertices; + } + + /** {@inheritDoc} */ + @Override + public ConvexVolume getRegion() { + return region; + } + + /** + * Return a collection of all two-dimensional faces (called facets) of the + * convex hull. + * + * @return a collection of all two-dimensional faces. + */ + public Collection<? extends ConvexPolygon3D> getFacets() { + return Collections.unmodifiableCollection(facets); Review Comment: There are already a number of exclusions for this bug in `src/main/resources/spotbugs/spotbugs-exclude-filter.xml`. The bug does not apply in this case so we can add an exception. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
