diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java index 84ea2bc6b..7a5e114f2 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/AbstractConvexHullGenerator2D.java @@ -16,9 +16,7 @@ */ package org.apache.commons.math3.geometry.euclidean.twod.hull; -import java.util.Arrays; import java.util.Collection; -import java.util.Iterator; import org.apache.commons.math3.exception.NullArgumentException; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; @@ -44,16 +42,6 @@ public abstract class AbstractConvexHullGenerator2D implements ConvexHullGenerat */ private final boolean includeCollinearPoints; - /** - * Simple constructor. - *
- * Collinear points on the hull will not be added to the hull vertices and - * {@code 1e-10} will be used as tolerance criteria for identical points. - */ - protected AbstractConvexHullGenerator2D() { - this(false, DEFAULT_TOLERANCE); - } - /** * Simple constructor. *
@@ -100,30 +88,19 @@ public abstract class AbstractConvexHullGenerator2D implements ConvexHullGenerat
// check for null points
MathUtils.checkNotNull(points);
- final int size = points.size();
- if (size == 2) {
- // special case: check that the two points are not identical
- final Iterator
- * The implementation is not sensitive to collinear points. The runtime complexity is O(nh),
- * with n being the number of input points and h the number of points on the convex hull.
+ * The runtime complexity is O(nh), with n being the number of input points and h the number
+ * of points on the convex hull.
+ *
+ * The implementation is not sensitive to collinear points on the hull. The parameter
+ * {@code includeCollinearPoints} allows to control the behavior with regard to collinear points.
+ * If {@code true}, all points on the boundary of the hull will be added to the hull vertices,
+ * otherwise only the extreme points will be present. By default, collinear points are not added
+ * as hull vertices.
+ *
+ * The {@code tolerance} parameter (default: 1e-10) is used as epsilon criteria to determine
+ * identical and collinear points.
*
* @see Gift wrapping algorithm (Wikipedia)
* @since 3.3
@@ -39,21 +48,14 @@ public class GiftWrap extends AbstractConvexHullGenerator2D {
/**
* Create a new GiftWrap instance.
- *
- * Collinear points on the hull will not be added to the hull vertices and
- * {@code 1e-10} will be used as tolerance criteria for identical points.
*/
public GiftWrap() {
- super();
+ this(false);
}
/**
* Create a new GiftWrap instance.
- *
- * The default tolerance (1e-10) will be used to determine identical points.
- *
- * @param includeCollinearPoints indicates if collinear points on the hull shall be
- * added as hull vertices
+ * @param includeCollinearPoints whether collinear points shall be added as hull vertices
*/
public GiftWrap(final boolean includeCollinearPoints) {
super(includeCollinearPoints);
@@ -61,9 +63,7 @@ public class GiftWrap extends AbstractConvexHullGenerator2D {
/**
* Create a new GiftWrap instance.
- *
- * @param includeCollinearPoints indicates if collinear points on the hull shall be
- * added as hull vertices
+ * @param includeCollinearPoints whether collinear points shall be added as hull vertices
* @param tolerance tolerance below which points are considered identical
*/
public GiftWrap(final boolean includeCollinearPoints, final double tolerance) {
@@ -71,7 +71,7 @@ public class GiftWrap extends AbstractConvexHullGenerator2D {
}
@Override
- public Collection
- * The implementation is not sensitive to collinear points. The runtime complexity
- * is O(n log n), with n being the number of input points.
+ * The runtime complexity is O(n log h), with n being the number of input points.
+ *
+ * The implementation is not sensitive to collinear points on the hull. The parameter
+ * {@code includeCollinearPoints} allows to control the behavior with regard to collinear points.
+ * If {@code true}, all points on the boundary of the hull will be added to the hull vertices,
+ * otherwise only the extreme points will be present. By default, collinear points are not added
+ * as hull vertices.
+ *
+ * The {@code tolerance} parameter (default: 1e-10) is used as epsilon criteria to determine
+ * identical and collinear points.
*
* @see Graham's scan algorithm (Wikipedia)
* @since 3.3
@@ -44,21 +52,14 @@ public class GrahamScan extends AbstractConvexHullGenerator2D {
/**
* Create a new GrahamScan instance.
- *
- * Collinear points on the hull will not be added to the hull vertices and
- * {@code 1e-10} will be used as tolerance criteria for identical points.
*/
public GrahamScan() {
- super();
+ this(false);
}
/**
* Create a new GrahamScan instance.
- *
- * The default tolerance (1e-10) will be used to determine identical points.
- *
- * @param includeCollinearPoints indicates if collinear points on the hull shall be
- * added as hull vertices
+ * @param includeCollinearPoints whether collinear points shall be added as hull vertices
*/
public GrahamScan(final boolean includeCollinearPoints) {
super(includeCollinearPoints);
@@ -66,9 +67,7 @@ public class GrahamScan extends AbstractConvexHullGenerator2D {
/**
* Create a new GrahamScan instance.
- *
- * @param includeCollinearPoints indicates if collinear points on the hull shall be
- * added as hull vertices
+ * @param includeCollinearPoints whether collinear points shall be added as hull vertices
* @param tolerance tolerance below which points are considered identical
*/
public GrahamScan(final boolean includeCollinearPoints, final double tolerance) {
@@ -76,7 +75,7 @@ public class GrahamScan extends AbstractConvexHullGenerator2D {
}
@Override
- protected Collection
- * The implementation is not sensitive to collinear points. The runtime complexity
- * is O(n log n), with n being the number of input points. If the point set is already
- * sorted (by x-coordinate), the runtime complexity is O(n).
+ * The runtime complexity is O(n log n), with n being the number of input points. If the
+ * point set is already sorted (by x-coordinate), the runtime complexity is O(n).
+ *
+ * The implementation is not sensitive to collinear points on the hull. The parameter
+ * {@code includeCollinearPoints} allows to control the behavior with regard to collinear points.
+ * If {@code true}, all points on the boundary of the hull will be added to the hull vertices,
+ * otherwise only the extreme points will be present. By default, collinear points are not added
+ * as hull vertices.
+ *
+ * The {@code tolerance} parameter (default: 1e-10) is used as epsilon criteria to determine
+ * identical and collinear points.
*
* @see
* Andrew's monotone chain algorithm (Wikibooks)
@@ -42,21 +50,14 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
/**
* Create a new MonotoneChain instance.
- *
- * Collinear points on the hull will not be added to the hull vertices and
- * {@code 1e-10} will be used as tolerance criteria for identical points.
*/
public MonotoneChain() {
- super();
+ this(false);
}
/**
* Create a new MonotoneChain instance.
- *
- * The default tolerance (1e-10) will be used to determine identical points.
- *
- * @param includeCollinearPoints indicates if collinear points on the hull shall be
- * added as hull vertices
+ * @param includeCollinearPoints whether collinear points shall be added as hull vertices
*/
public MonotoneChain(final boolean includeCollinearPoints) {
super(includeCollinearPoints);
@@ -64,9 +65,7 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
/**
* Create a new MonotoneChain instance.
- *
- * @param includeCollinearPoints indicates if collinear points on the hull shall be
- * added as hull vertices
+ * @param includeCollinearPoints whether collinear points shall be added as hull vertices
* @param tolerance tolerance below which points are considered identical
*/
public MonotoneChain(final boolean includeCollinearPoints, final double tolerance) {
@@ -74,7 +73,7 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
}
@Override
- public Collection