You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2021/08/16 16:38:01 UTC
[commons-geometry] branch master updated: implementing changes from
rc3 feedback
This is an automated email from the ASF dual-hosted git repository.
mattjuntunen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git
The following commit(s) were added to refs/heads/master by this push:
new 5efb17c implementing changes from rc3 feedback
5efb17c is described below
commit 5efb17c639ac55cb90e3c99b7fcb99809522e3c6
Author: Matt Juntunen <ma...@apache.org>
AuthorDate: Mon Aug 16 09:58:47 2021 -0400
implementing changes from rc3 feedback
---
.../core/partitioning/bsp/AbstractRegionBSPTree.java | 2 +-
.../core/partitioning/bsp/BSPTreeVisitor.java | 4 ++--
.../core/partitioning/bsp/AbstractBSPTreeTest.java | 20 ++++++++++++++++++++
.../geometry/euclidean/internal/EuclideanUtils.java | 11 +++++++----
.../geometry/euclidean/oned/RegionBSPTree1D.java | 2 +-
.../commons/geometry/euclidean/oned/Vector1D.java | 2 --
.../euclidean/threed/AbstractConvexPolygon3D.java | 2 +-
.../commons/geometry/euclidean/threed/Planes.java | 18 +++++++++---------
.../commons/geometry/euclidean/threed/Vector3D.java | 2 --
.../euclidean/threed/VertexListConvexPolygon3D.java | 6 ++++--
.../euclidean/threed/mesh/SimpleTriangleMesh.java | 6 ++++--
.../threed/rotation/QuaternionRotation.java | 2 +-
.../geometry/euclidean/twod/RegionBSPTree2D.java | 4 ++--
.../commons/geometry/euclidean/twod/Vector2D.java | 2 --
.../commons/geometry/io/core/BoundaryIOManager.java | 3 ++-
.../geometry/io/core/internal/CharReadBuffer.java | 2 +-
.../geometry/io/core/internal/SimpleTextParser.java | 3 +--
.../io/euclidean/threed/SimpleFacetDefinition.java | 7 ++++---
.../threed/obj/AbstractObjPolygonReader.java | 6 +++---
.../geometry/io/euclidean/threed/obj/ObjWriter.java | 6 ++++--
.../io/euclidean/threed/obj/PolygonObjParser.java | 8 +++++---
.../threed/txt/TextFacetDefinitionWriter.java | 8 +++++---
.../threed/obj/ObjFacetDefinitionReaderTest.java | 2 +-
.../threed/obj/ObjTriangleMeshReaderTest.java | 2 +-
.../euclidean/threed/obj/PolygonObjParserTest.java | 2 +-
.../commons/geometry/spherical/oned/Point1S.java | 2 --
.../geometry/spherical/twod/GreatCircles.java | 2 +-
.../commons/geometry/spherical/twod/Point2S.java | 2 --
pom.xml | 8 ++++++++
.../resources/checkstyle/checkstyle-suppressions.xml | 1 +
src/main/resources/checkstyle/checkstyle.xml | 8 ++++----
src/main/resources/pmd/pmd-ruleset.xml | 4 +++-
src/site/xdoc/userguide/index.xml | 4 ++--
33 files changed, 99 insertions(+), 64 deletions(-)
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractRegionBSPTree.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractRegionBSPTree.java
index a39ae2c..93a0800 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractRegionBSPTree.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractRegionBSPTree.java
@@ -128,7 +128,7 @@ public abstract class AbstractRegionBSPTree<
/** {@inheritDoc} */
@Override
public double getBoundarySize() {
- if (boundarySize < 0.0) {
+ if (boundarySize < 0) {
double sum = 0.0;
RegionCutBoundary<P> boundary;
diff --git a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/BSPTreeVisitor.java b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/BSPTreeVisitor.java
index 7df94e3..d7e46b7 100644
--- a/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/BSPTreeVisitor.java
+++ b/commons-geometry-core/src/main/java/org/apache/commons/geometry/core/partitioning/bsp/BSPTreeVisitor.java
@@ -142,7 +142,7 @@ public interface BSPTreeVisitor<P extends Point<P>, N extends BSPTree.Node<P, N>
/** {@inheritDoc} */
@Override
public Order visitOrder(final N node) {
- if (node.getCutHyperplane().offset(getTarget()) > 0.0) {
+ if (node.getCutHyperplane().offset(getTarget()) > 0) {
return Order.PLUS_NODE_MINUS;
}
return Order.MINUS_NODE_PLUS;
@@ -169,7 +169,7 @@ public interface BSPTreeVisitor<P extends Point<P>, N extends BSPTree.Node<P, N>
/** {@inheritDoc} */
@Override
public Order visitOrder(final N node) {
- if (node.getCutHyperplane().offset(getTarget()) < 0.0) {
+ if (node.getCutHyperplane().offset(getTarget()) < 0) {
return Order.PLUS_NODE_MINUS;
}
return Order.MINUS_NODE_PLUS;
diff --git a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractBSPTreeTest.java b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractBSPTreeTest.java
index 827709b..830645f 100644
--- a/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractBSPTreeTest.java
+++ b/commons-geometry-core/src/test/java/org/apache/commons/geometry/core/partitioning/bsp/AbstractBSPTreeTest.java
@@ -856,6 +856,26 @@ class AbstractBSPTreeTest {
}
@Test
+ void testDepth_detachedNodes() {
+ // arrange
+ final TestBSPTree tree = new TestBSPTree();
+
+ final TestNode detached = new TestNode(tree);
+ detached.cut(TestLine.X_AXIS)
+ .getMinus()
+ .cut(TestLine.Y_AXIS);
+
+ // act/assert
+ Assertions.assertEquals(-1, detached.depth());
+
+ Assertions.assertEquals(-1, detached.getPlus().depth());
+
+ Assertions.assertEquals(-1, detached.getMinus().depth());
+ Assertions.assertEquals(-1, detached.getMinus().getPlus().depth());
+ Assertions.assertEquals(-1, detached.getMinus().getMinus().depth());
+ }
+
+ @Test
void testVisit_defaultOrder() {
// arrange
final TestBSPTree tree = new TestBSPTree();
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/EuclideanUtils.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/EuclideanUtils.java
index a692b69..2f7cf8a 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/EuclideanUtils.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/internal/EuclideanUtils.java
@@ -30,6 +30,9 @@ import org.apache.commons.geometry.euclidean.threed.Vector3D;
*/
public final class EuclideanUtils {
+ /** Number of vertices in a triangle, i.e. {@code 3}. */
+ public static final int TRIANGLE_VERTEX_COUNT = 3;
+
/** Utility class; no instantiation. */
private EuclideanUtils() { }
@@ -49,10 +52,10 @@ public final class EuclideanUtils {
public static <T> List<T> convexPolygonToTriangleFan(final List<Vector3D> vertices,
final Function<List<Vector3D>, T> fn) {
final int size = vertices.size();
- if (size < 3) {
- throw new IllegalArgumentException("Cannot create triangle fan: 3 or more vertices are required " +
- "but found only " + vertices.size());
- } else if (size == 3) {
+ if (size < TRIANGLE_VERTEX_COUNT) {
+ throw new IllegalArgumentException("Cannot create triangle fan: " + TRIANGLE_VERTEX_COUNT +
+ " or more vertices are required but found only " + vertices.size());
+ } else if (size == TRIANGLE_VERTEX_COUNT) {
return Collections.singletonList(fn.apply(vertices));
}
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/RegionBSPTree1D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/RegionBSPTree1D.java
index cb94de7..d6fe32e 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/RegionBSPTree1D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/RegionBSPTree1D.java
@@ -538,7 +538,7 @@ public final class RegionBSPTree1D extends AbstractRegionBSPTree<Vector1D, Regio
Vector1D centroid = null;
if (count > 0 && Double.isFinite(size)) {
- if (size > 0.0) {
+ if (size > 0) {
// use the scaled sum if we have a non-zero size
centroid = Vector1D.of(scaledCentroidSum / size);
} else {
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java
index 56cec14..6453f13 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/oned/Vector1D.java
@@ -33,10 +33,8 @@ public class Vector1D extends EuclideanVector<Vector1D> {
/** Zero vector (coordinates: 0). */
public static final Vector1D ZERO = new Vector1D(0.0);
- // CHECKSTYLE: stop ConstantName
/** A vector with all coordinates set to NaN. */
public static final Vector1D NaN = new Vector1D(Double.NaN);
- // CHECKSTYLE: resume ConstantName
/** A vector with all coordinates set to positive infinity. */
public static final Vector1D POSITIVE_INFINITY =
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/AbstractConvexPolygon3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/AbstractConvexPolygon3D.java
index b1c6c5a..cb5575d 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/AbstractConvexPolygon3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/AbstractConvexPolygon3D.java
@@ -132,7 +132,7 @@ abstract class AbstractConvexPolygon3D extends AbstractPlaneSubset implements Co
prevVec = curVec;
}
- if (areaSum > 0.0) {
+ if (areaSum > 0) {
final double scale = 1 / areaSum;
return Vector3D.of(
scale * scaledCentroidSumX,
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Planes.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Planes.java
index d6db5ef..fd69aa0 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Planes.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Planes.java
@@ -162,7 +162,7 @@ public final class Planes {
vertices.remove(vertices.size() - 1);
}
- if (vertices.size() == 3) {
+ if (vertices.size() == EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
return new SimpleTriangle3D(plane, vertices.get(0), vertices.get(1), vertices.get(2));
}
return new VertexListConvexPolygon3D(plane, vertices);
@@ -243,10 +243,10 @@ public final class Planes {
int[] face;
for (int i = 0; i < numFaces; ++i) {
face = faceIndices[i];
- if (face.length != 3) {
+ if (face.length != EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
throw new IllegalArgumentException(MessageFormat.format(
- "Invalid number of vertex indices for face at index {0}: expected 3 but found {1}",
- i, face.length));
+ "Invalid number of vertex indices for face at index {0}: expected {1} but found {2}",
+ i, EuclideanUtils.TRIANGLE_VERTEX_COUNT, face.length));
}
triangles.add(triangleFromVertices(
@@ -322,10 +322,10 @@ public final class Planes {
int[] face;
for (int i = 0; i < numFaces; ++i) {
face = faceIndices[i];
- if (face.length < 3) {
+ if (face.length < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
throw new IllegalArgumentException(MessageFormat.format(
- "Invalid number of vertex indices for face at index {0}: required at least 3 but found {1}",
- i, face.length));
+ "Invalid number of vertex indices for face at index {0}: required at least {1} but found {2}",
+ i, EuclideanUtils.TRIANGLE_VERTEX_COUNT, face.length));
}
for (final int vertexIndex : face) {
@@ -514,7 +514,7 @@ public final class Planes {
static ConvexPolygon3D fromConvexPlanarVertices(final Plane plane, final List<Vector3D> vertices) {
final int size = vertices.size();
- if (size == 3) {
+ if (size == EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
return new SimpleTriangle3D(plane, vertices.get(0), vertices.get(1), vertices.get(2));
}
@@ -585,7 +585,7 @@ public final class Planes {
* @throws IllegalArgumentException if the points do not define a plane
*/
Plane build() {
- if (pts.size() < 3) {
+ if (pts.size() < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
throw nonPlanar();
}
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
index ed389f0..0ac52da 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java
@@ -36,10 +36,8 @@ public class Vector3D extends MultiDimensionalEuclideanVector<Vector3D> {
/** Zero (null) vector (coordinates: 0, 0, 0). */
public static final Vector3D ZERO = new Vector3D(0, 0, 0);
- // CHECKSTYLE: stop ConstantName
/** A vector with all coordinates set to NaN. */
public static final Vector3D NaN = new Vector3D(Double.NaN, Double.NaN, Double.NaN);
- // CHECKSTYLE: resume ConstantName
/** A vector with all coordinates set to positive infinity. */
public static final Vector3D POSITIVE_INFINITY =
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/VertexListConvexPolygon3D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/VertexListConvexPolygon3D.java
index f309cf0..0e8d5f8 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/VertexListConvexPolygon3D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/VertexListConvexPolygon3D.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.geometry.core.Transform;
+import org.apache.commons.geometry.euclidean.internal.EuclideanUtils;
/** Internal {@link ConvexPolygon3D} implementation class that uses a list of vertices
* to represent the plane subset.
@@ -42,8 +43,9 @@ final class VertexListConvexPolygon3D extends AbstractConvexPolygon3D {
super(plane);
// sanity check
- if (vertices.size() < 3) {
- throw new IllegalArgumentException("Convex polygon requires at least 3 points; found " + vertices.size());
+ if (vertices.size() < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
+ throw new IllegalArgumentException("Convex polygon requires at least " +
+ EuclideanUtils.TRIANGLE_VERTEX_COUNT + " points; found " + vertices.size());
}
this.vertices = Collections.unmodifiableList(vertices);
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/mesh/SimpleTriangleMesh.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/mesh/SimpleTriangleMesh.java
index 60783d6..409e8ad 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/mesh/SimpleTriangleMesh.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/mesh/SimpleTriangleMesh.java
@@ -32,6 +32,7 @@ import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apache.commons.geometry.core.Transform;
+import org.apache.commons.geometry.euclidean.internal.EuclideanUtils;
import org.apache.commons.geometry.euclidean.threed.BoundarySource3D;
import org.apache.commons.geometry.euclidean.threed.Bounds3D;
import org.apache.commons.geometry.euclidean.threed.PlaneConvexSubset;
@@ -563,8 +564,9 @@ public final class SimpleTriangleMesh implements TriangleMesh {
* or if any of the vertex indices is not a valid index into the current vertex list
*/
public Builder addFace(final int[] face) {
- if (face.length != 3) {
- throw new IllegalArgumentException("Face must contain 3 vertex indices; found " + face.length);
+ if (face.length != EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
+ throw new IllegalArgumentException("Face must contain " + EuclideanUtils.TRIANGLE_VERTEX_COUNT +
+ " vertex indices; found " + face.length);
}
addFace(face[0], face[1], face[2]);
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java
index 4317bd8..5f80016 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/rotation/QuaternionRotation.java
@@ -778,7 +778,7 @@ public final class QuaternionRotation implements Rotation3D {
final double y;
final double z;
- if (trace > 0.0) {
+ if (trace > 0) {
// let s = 4*w
final double s = 2.0 * Math.sqrt(1.0 + trace);
final double sinv = 1.0 / s;
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/RegionBSPTree2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/RegionBSPTree2D.java
index bd3edd6..62eac07 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/RegionBSPTree2D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/RegionBSPTree2D.java
@@ -246,10 +246,10 @@ public final class RegionBSPTree2D extends AbstractRegionBSPTree<Vector2D, Regio
// The area is finite only if the computed quadrilateral area is finite and non-negative.
// Negative areas indicate that the region is inside-out, with a finite outside surrounded
// by an infinite inside.
- if (quadrilateralAreaSum >= 0.0 && Double.isFinite(quadrilateralAreaSum)) {
+ if (quadrilateralAreaSum >= 0 && Double.isFinite(quadrilateralAreaSum)) {
size = 0.5 * quadrilateralAreaSum;
- if (quadrilateralAreaSum > 0.0) {
+ if (quadrilateralAreaSum > 0) {
centroid = Vector2D.of(scaledSumX, scaledSumY).multiply(1.0 / (3.0 * quadrilateralAreaSum));
}
}
diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
index 10b0ff8..738bbf7 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java
@@ -36,10 +36,8 @@ public class Vector2D extends MultiDimensionalEuclideanVector<Vector2D> {
/** Zero vector (coordinates: 0, 0). */
public static final Vector2D ZERO = new Vector2D(0, 0);
- // CHECKSTYLE: stop ConstantName
/** A vector with all coordinates set to NaN. */
public static final Vector2D NaN = new Vector2D(Double.NaN, Double.NaN);
- // CHECKSTYLE: resume ConstantName
/** A vector with all coordinates set to positive infinity. */
public static final Vector2D POSITIVE_INFINITY =
diff --git a/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/BoundaryIOManager.java b/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/BoundaryIOManager.java
index 3cba98b..19c8435 100644
--- a/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/BoundaryIOManager.java
+++ b/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/BoundaryIOManager.java
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -481,7 +482,7 @@ public class BoundaryIOManager<
* @return normalized string
*/
private static String normalizeString(final String str) {
- return str.toLowerCase();
+ return str.toLowerCase(Locale.ROOT);
}
}
}
diff --git a/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/CharReadBuffer.java b/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/CharReadBuffer.java
index 72318e4..9f4b2af 100644
--- a/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/CharReadBuffer.java
+++ b/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/CharReadBuffer.java
@@ -240,7 +240,7 @@ public class CharReadBuffer {
final int remaining = n - skipped;
if (remaining > 0) {
try {
- skipped += reader.skip(remaining);
+ skipped += (int) reader.skip(remaining);
} catch (IOException exc) {
throw GeometryIOUtils.createUnchecked(exc);
}
diff --git a/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/SimpleTextParser.java b/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/SimpleTextParser.java
index dc60ff5..0d1c243 100644
--- a/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/SimpleTextParser.java
+++ b/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/internal/SimpleTextParser.java
@@ -979,9 +979,8 @@ public class SimpleTextParser {
} else if (currentToken != null) {
if (!hasMoreCharactersOnLine()) {
return "end of line";
- } else if (currentToken != null) {
- return "empty token followed by [" + peek(1) + "]";
}
+ return "empty token followed by [" + peek(1) + "]";
}
} catch (IllegalStateException exc) {
// ignore
diff --git a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/SimpleFacetDefinition.java b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/SimpleFacetDefinition.java
index 2ddb13c..ca2acfc 100644
--- a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/SimpleFacetDefinition.java
+++ b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/SimpleFacetDefinition.java
@@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import org.apache.commons.geometry.euclidean.internal.EuclideanUtils;
import org.apache.commons.geometry.euclidean.threed.Vector3D;
/** Simple {@link FacetDefinition} implementation that stores a list of vertices and
@@ -48,9 +49,9 @@ public class SimpleFacetDefinition implements FacetDefinition {
*/
public SimpleFacetDefinition(final List<Vector3D> vertices, final Vector3D normal) {
Objects.requireNonNull(vertices, "Facet vertex list cannot be null");
- if (vertices.size() < 3) {
- throw new IllegalArgumentException("Facet vertex list must contain at least 3 points; found " +
- vertices.size());
+ if (vertices.size() < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
+ throw new IllegalArgumentException("Facet vertex list must contain at least " +
+ EuclideanUtils.TRIANGLE_VERTEX_COUNT + " points; found " + vertices.size());
}
this.vertices = Collections.unmodifiableList(vertices);
diff --git a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/AbstractObjPolygonReader.java b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/AbstractObjPolygonReader.java
index 55612c0..9e0ffc5 100644
--- a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/AbstractObjPolygonReader.java
+++ b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/AbstractObjPolygonReader.java
@@ -46,10 +46,10 @@ public abstract class AbstractObjPolygonReader implements Closeable {
* (ex: {@code curv}). If false, non-polygon data is ignored.
* @return flag indicating whether or not an {@link IllegalStateException} will be thrown
* if non-polygon content is encountered
- * @see PolygonObjParser#getFailOnNonPolygonKeywords()
+ * @see PolygonObjParser#isFailOnNonPolygonKeywords()
*/
- public boolean getFailOnNonPolygonKeywords() {
- return parser.getFailOnNonPolygonKeywords();
+ public boolean isFailOnNonPolygonKeywords() {
+ return parser.isFailOnNonPolygonKeywords();
}
/** Set the flag indicating whether or not an {@link IllegalStateException} will be thrown
diff --git a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjWriter.java b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjWriter.java
index d7472e9..b7ae13a 100644
--- a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjWriter.java
+++ b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjWriter.java
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.function.DoubleFunction;
import java.util.stream.Stream;
+import org.apache.commons.geometry.euclidean.internal.EuclideanUtils;
import org.apache.commons.geometry.euclidean.threed.BoundarySource3D;
import org.apache.commons.geometry.euclidean.threed.PlaneConvexSubset;
import org.apache.commons.geometry.euclidean.threed.Vector3D;
@@ -251,8 +252,9 @@ public final class ObjWriter extends AbstractTextFormatWriter {
*/
private void writeFaceWithOffsets(final int vertexOffset, final int[] vertexIndices,
final int normalOffset, final int[] normalIndices) {
- if (vertexIndices.length < 3) {
- throw new IllegalArgumentException("Face must have more than 3 vertices; found " + vertexIndices.length);
+ if (vertexIndices.length < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
+ throw new IllegalArgumentException("Face must have more than " + EuclideanUtils.TRIANGLE_VERTEX_COUNT +
+ " vertices; found " + vertexIndices.length);
} else if (normalIndices != null && normalIndices.length != vertexIndices.length) {
throw new IllegalArgumentException("Face normal index count must equal vertex index count; expected " +
vertexIndices.length + " but was " + normalIndices.length);
diff --git a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParser.java b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParser.java
index 4eff147..360e3f8 100644
--- a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParser.java
+++ b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParser.java
@@ -27,6 +27,7 @@ import java.util.function.IntFunction;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;
+import org.apache.commons.geometry.euclidean.internal.EuclideanUtils;
import org.apache.commons.geometry.euclidean.threed.Vector3D;
import org.apache.commons.geometry.io.core.internal.SimpleTextParser;
@@ -121,7 +122,7 @@ public class PolygonObjParser extends AbstractObjParser {
* </ul>
* @return true if the instance is configured to fail when a non-polygon keyword is encountered
*/
- public boolean getFailOnNonPolygonKeywords() {
+ public boolean isFailOnNonPolygonKeywords() {
return failOnNonPolygonKeywords;
}
@@ -186,9 +187,10 @@ public class PolygonObjParser extends AbstractObjParser {
vertices.add(readFaceVertex());
}
- if (vertices.size() < 3) {
+ if (vertices.size() < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
throw getTextParser().parseError(
- "face must contain at least 3 vertices but found only " + vertices.size());
+ "face must contain at least " + EuclideanUtils.TRIANGLE_VERTEX_COUNT +
+ " vertices but found only " + vertices.size());
}
discardDataLine();
diff --git a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionWriter.java b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionWriter.java
index c23c47b..4f67dde 100644
--- a/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionWriter.java
+++ b/commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionWriter.java
@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
+import org.apache.commons.geometry.euclidean.internal.EuclideanUtils;
import org.apache.commons.geometry.euclidean.threed.BoundarySource3D;
import org.apache.commons.geometry.euclidean.threed.PlaneConvexSubset;
import org.apache.commons.geometry.euclidean.threed.Triangle3D;
@@ -247,7 +248,7 @@ public class TextFacetDefinitionWriter extends AbstractTextFormatWriter {
throw new IllegalArgumentException("Cannot write infinite convex subset");
}
- if (facetVertexCount == 3) {
+ if (facetVertexCount == EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
// force conversion to triangles
for (final Triangle3D tri : convexSubset.toTriangles()) {
write(tri.getVertices());
@@ -285,8 +286,9 @@ public class TextFacetDefinitionWriter extends AbstractTextFormatWriter {
*/
public void write(final List<Vector3D> vertices) {
final int size = vertices.size();
- if (size < 3) {
- throw new IllegalArgumentException("At least 3 vertices are required per facet; found " + size);
+ if (size < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
+ throw new IllegalArgumentException("At least " + EuclideanUtils.TRIANGLE_VERTEX_COUNT +
+ " vertices are required per facet; found " + size);
} else if (facetVertexCount > -1 && size != facetVertexCount) {
throw new IllegalArgumentException("Writer requires " + facetVertexCount +
" vertices per facet; found " + size);
diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjFacetDefinitionReaderTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjFacetDefinitionReaderTest.java
index 9eab16d..785c3ff 100644
--- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjFacetDefinitionReaderTest.java
+++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjFacetDefinitionReaderTest.java
@@ -40,7 +40,7 @@ class ObjFacetDefinitionReaderTest {
final ObjFacetDefinitionReader reader = reader("");
// act/assert
- Assertions.assertFalse(reader.getFailOnNonPolygonKeywords());
+ Assertions.assertFalse(reader.isFailOnNonPolygonKeywords());
}
@Test
diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java
index fe2ba1f..a5c48d4 100644
--- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java
+++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java
@@ -42,7 +42,7 @@ class ObjTriangleMeshReaderTest {
final ObjTriangleMeshReader reader = reader("");
// act/assert
- Assertions.assertFalse(reader.getFailOnNonPolygonKeywords());
+ Assertions.assertFalse(reader.isFailOnNonPolygonKeywords());
}
@Test
diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java
index 0e8afc9..4170b0e 100644
--- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java
+++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java
@@ -43,7 +43,7 @@ class PolygonObjParserTest {
Assertions.assertEquals(0, p.getVertexCount());
Assertions.assertEquals(0, p.getVertexNormalCount());
Assertions.assertEquals(0, p.getTextureCoordinateCount());
- Assertions.assertFalse(p.getFailOnNonPolygonKeywords());
+ Assertions.assertFalse(p.isFailOnNonPolygonKeywords());
}
@Test
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/Point1S.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/Point1S.java
index e003ab0..b5a1935 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/Point1S.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/oned/Point1S.java
@@ -45,10 +45,8 @@ public final class Point1S implements Point<Point1S> {
/** A point with coordinates set to {@code pi}. */
public static final Point1S PI = Point1S.of(Math.PI);
- // CHECKSTYLE: stop ConstantName
/** A point with all coordinates set to NaN. */
public static final Point1S NaN = Point1S.of(Double.NaN);
- // CHECKSTYLE: resume ConstantName
/** Comparator that sorts points by normalized azimuth in ascending order.
* Points are only considered equal if their normalized azimuths match exactly.
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/GreatCircles.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/GreatCircles.java
index 3864c69..61f0685 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/GreatCircles.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/GreatCircles.java
@@ -104,7 +104,7 @@ public final class GreatCircles {
* @return an arc representing the shortest path between the given points
* @throws IllegalArgumentException if either of the given points is NaN or infinite, or if the given
* points are equal or antipodal as evaluated by the given precision context
- * @see GreatCircles#fromPoints(Point2S, Point2S, org.apache.commons.geometry.core.precision.Precision.DoubleEquivalence)
+ * @see GreatCircles#fromPoints(Point2S, Point2S, org.apache.commons.numbers.core.Precision.DoubleEquivalence)
*/
public static GreatArc arcFromPoints(final Point2S start, final Point2S end,
final Precision.DoubleEquivalence precision) {
diff --git a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java
index cb3bef6..7b58e3c 100644
--- a/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java
+++ b/commons-geometry-spherical/src/main/java/org/apache/commons/geometry/spherical/twod/Point2S.java
@@ -48,10 +48,8 @@ public final class Point2S implements Point<Point2S> {
/** -K (coordinates: ( azimuth = any angle, polar = pi )). */
public static final Point2S MINUS_K = new Point2S(0, Math.PI, Vector3D.Unit.MINUS_Z);
- // CHECKSTYLE: stop ConstantName
/** A point with all coordinates set to NaN. */
public static final Point2S NaN = new Point2S(Double.NaN, Double.NaN, null);
- // CHECKSTYLE: resume ConstantName
/** Comparator that sorts points in component-wise ascending order, first sorting
* by polar value and then by azimuth value. Points are only considered equal if
diff --git a/pom.xml b/pom.xml
index 1347e77..f28377b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -349,6 +349,10 @@
<configuration>
<!-- Enable MathJax -->
<additionalOptions>${doclint.javadoc.qualifier} --allow-script-in-comments -header '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/${geometry.mathjax.version}/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'</additionalOptions>
+ <links>
+ <link>https://commons.apache.org/proper/commons-numbers/commons-numbers-core/javadocs/api-1.0/</link>
+ <link>https://commons.apache.org/proper/commons-numbers/commons-numbers-quaternion/javadocs/api-1.0/</link>
+ </links>
</configuration>
</plugin>
<plugin>
@@ -475,6 +479,10 @@
<configuration>
<!-- Enable MathJax -->
<additionalOptions>${doclint.javadoc.qualifier} --allow-script-in-comments -header '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/${geometry.mathjax.version}/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'</additionalOptions>
+ <links>
+ <link>https://commons.apache.org/proper/commons-numbers/commons-numbers-core/javadocs/api-1.0/</link>
+ <link>https://commons.apache.org/proper/commons-numbers/commons-numbers-quaternion/javadocs/api-1.0/</link>
+ </links>
</configuration>
</plugin>
diff --git a/src/main/resources/checkstyle/checkstyle-suppressions.xml b/src/main/resources/checkstyle/checkstyle-suppressions.xml
index 99b45c3..a38fb2d 100644
--- a/src/main/resources/checkstyle/checkstyle-suppressions.xml
+++ b/src/main/resources/checkstyle/checkstyle-suppressions.xml
@@ -42,6 +42,7 @@
<suppress checks="MultipleStringLiterals" files=".*[/\\]test[/\\].*" />
<suppress checks="DesignForExtension" files=".*[/\\]test[/\\].*" />
<suppress checks="LineLength" files=".*[/\\]test[/\\].*" />
+ <suppress checks="FileLength" files=".*[/\\]test[/\\].*" />
<suppress checks="IllegalCatch" files=".*[/\\]test[/\\].*" />
<suppress checks="MethodName" files=".*[/\\]test[/\\].*" />
<suppress checks="IllegalInstantiation" files=".*[/\\]test[/\\].*" />
diff --git a/src/main/resources/checkstyle/checkstyle.xml b/src/main/resources/checkstyle/checkstyle.xml
index fd5bea4..f4a591b 100644
--- a/src/main/resources/checkstyle/checkstyle.xml
+++ b/src/main/resources/checkstyle/checkstyle.xml
@@ -96,7 +96,10 @@
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sourceforge.net/config_naming.html -->
- <module name="ConstantName" />
+ <module name="ConstantName">
+ <!-- Allow "NaN" constant names. -->
+ <property name="format" value="^NaN$|^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
+ </module>
<module name="LocalFinalVariableName" />
<module name="LocalVariableName" />
<module name="MemberName" />
@@ -207,9 +210,6 @@
<!-- Switch statements should have independent cases -->
<module name="FallThrough" />
- <!-- Constant names should obey the traditional all uppercase naming convention -->
- <module name="ConstantName" />
-
<!-- No System.out.println() statements -->
<module name="Regexp">
<!-- no sysouts -->
diff --git a/src/main/resources/pmd/pmd-ruleset.xml b/src/main/resources/pmd/pmd-ruleset.xml
index 96025bd..1d9845f 100644
--- a/src/main/resources/pmd/pmd-ruleset.xml
+++ b/src/main/resources/pmd/pmd-ruleset.xml
@@ -41,12 +41,14 @@
<exclude name="UseUnderscoresInNumericLiterals" />
<exclude name="GenericsNaming" />
<exclude name="ConfusingTernary" />
+ <exclude name="FieldDeclarationsShouldBeAtStartOfClass" />
</rule>
<rule ref="category/java/design.xml">
<exclude name="TooManyMethods" />
<exclude name="LawOfDemeter" />
<exclude name="NcssCount" />
- <exclude name="LoosePackageCoupling" />
+ <exclude name="LoosePackageCoupling" />
+ <exclude name="GodClass" />
</rule>
<rule ref="category/java/documentation.xml">
<exclude name="CommentSize" />
diff --git a/src/site/xdoc/userguide/index.xml b/src/site/xdoc/userguide/index.xml
index fdfc9c7..f800610 100644
--- a/src/site/xdoc/userguide/index.xml
+++ b/src/site/xdoc/userguide/index.xml
@@ -275,7 +275,7 @@ v1.eq(v3, precision); // true - approximately equal according to the given preci
hyperplane have an offset of zero.
</p>
<p>
- Hyperplanes place a key role in <em>Commons Geometry</em> not only because of their importance geometrically but also
+ Hyperplanes play a key role in <em>Commons Geometry</em> not only because of their importance geometrically but also
because they form the basis for the region classes and algorithms, such as <a href="#bsp_trees">BSP trees</a>.
Hyperplanes are represented in code with the
<a class="code" href="../commons-geometry-core/apidocs/org/apache/commons/geometry/core/partitioning/Hyperplane.html">Hyperplane</a>
@@ -1082,7 +1082,7 @@ GreatCircle a = GreatCircles.fromPoints(Point2S.PLUS_I, Point2S.PLUS_K, precisio
GreatCircle b = GreatCircles.fromPole(Vector3D.Unit.PLUS_Z, precision);
// find the two intersection points of the great circles
-Point2S ptA = a.intersection(b); //(pi, pi/2)
+Point2S ptA = a.intersection(b); // (pi, pi/2)
Point2S ptB = ptA.antipodal(); // (0, pi/2)
</source>