diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9129a8c78..dec7ea537 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -52,6 +52,9 @@ If the output is not quite correct, check for invisible trailing spaces! + + Fixed naming inconsistencies between Interval and IntervalsSet classes. + Added a method to check points in the Interval class, with a tolerance for boundary. diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java index 5c3c2a853..414c7793b 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java @@ -43,30 +43,70 @@ public class Interval { /** Get the lower bound of the interval. * @return lower bound of the interval + * @since 3.1 */ - public double getLower() { + public double getInf() { return lower; } + /** Get the lower bound of the interval. + * @return lower bound of the interval + * @deprecated as of 3.1, replaced by {@link #getInf()} + */ + @Deprecated + public double getLower() { + return getInf(); + } + /** Get the upper bound of the interval. * @return upper bound of the interval + * @since 3.1 */ - public double getUpper() { + public double getSup() { return upper; } + /** Get the upper bound of the interval. + * @return upper bound of the interval + * @deprecated as of 3.1, replaced by {@link #getSup()} + */ + @Deprecated + public double getUpper() { + return getSup(); + } + + /** Get the size of the interval. + * @return size of the interval + * @since 3.1 + */ + public double getSize() { + return upper - lower; + } + /** Get the length of the interval. * @return length of the interval + * @deprecated as of 3.1, replaced by {@link #getSize()} */ + @Deprecated public double getLength() { - return upper - lower; + return getSize(); + } + + /** Get the barycenter of the interval. + * @return barycenter of the interval + * @since 3.1 + */ + public double getBarycenter() { + return 0.5 * (lower + upper); } /** Get the midpoint of the interval. * @return midpoint of the interval + * @deprecated as of 3.1, replaced by {@link #getBarycenter()} */ + @Deprecated public double getMidPoint() { - return 0.5 * (lower + upper); + return getBarycenter(); } /** Check a point with respect to the interval. diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java index d8861f5c6..674fb0ab2 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java @@ -143,8 +143,8 @@ public class IntervalsSet extends AbstractRegion { double size = 0.0; double sum = 0.0; for (final Interval interval : asList()) { - size += interval.getLength(); - sum += interval.getLength() * interval.getMidPoint(); + size += interval.getSize(); + sum += interval.getSize() * interval.getBarycenter(); } setSize(size); if (Double.isInfinite(size)) { @@ -241,7 +241,7 @@ public class IntervalsSet extends AbstractRegion { if ((checkPoint(low, loc) == Location.INSIDE) && (checkPoint(high, loc) == Location.INSIDE)) { // merge the last interval added and the first one of the high sub-tree - x = list.remove(list.size() - 1).getLower(); + x = list.remove(list.size() - 1).getInf(); } recurseList(high, list, x, upper); diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java index f23d06903..a146cb661 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java @@ -84,8 +84,8 @@ public class SubLine { final List segments = new ArrayList(); for (final Interval interval : list) { - final Vector3D start = line.toSpace(new Vector1D(interval.getLower())); - final Vector3D end = line.toSpace(new Vector1D(interval.getUpper())); + final Vector3D start = line.toSpace(new Vector1D(interval.getInf())); + final Vector3D end = line.toSpace(new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java index ba4412e36..8a7455f5b 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java @@ -840,10 +840,10 @@ public class PolygonsSet extends AbstractRegion { final Line line = (Line) sub.getHyperplane(); final List intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList(); for (final Interval i : intervals) { - final Vector2D start = Double.isInfinite(i.getLower()) ? - null : (Vector2D) line.toSpace(new Vector1D(i.getLower())); - final Vector2D end = Double.isInfinite(i.getUpper()) ? - null : (Vector2D) line.toSpace(new Vector1D(i.getUpper())); + final Vector2D start = Double.isInfinite(i.getInf()) ? + null : (Vector2D) line.toSpace(new Vector1D(i.getInf())); + final Vector2D end = Double.isInfinite(i.getSup()) ? + null : (Vector2D) line.toSpace(new Vector1D(i.getSup())); if (reversed) { sorted.insert(new ComparableSegment(end, start, line.getReverse())); } else { diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java index cf47f88a3..a9d621a44 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java @@ -84,8 +84,8 @@ public class SubLine extends AbstractSubHyperplane { final List segments = new ArrayList(); for (final Interval interval : list) { - final Vector2D start = line.toSpace(new Vector1D(interval.getLower())); - final Vector2D end = line.toSpace(new Vector1D(interval.getUpper())); + final Vector2D start = line.toSpace(new Vector1D(interval.getInf())); + final Vector2D end = line.toSpace(new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } diff --git a/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java b/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java index 433c9f1d7..dd3b461ca 100644 --- a/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java +++ b/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java @@ -27,15 +27,15 @@ public class IntervalTest { @Test public void testInterval() { Interval interval = new Interval(2.3, 5.7); - Assert.assertEquals(3.4, interval.getLength(), 1.0e-10); - Assert.assertEquals(4.0, interval.getMidPoint(), 1.0e-10); + Assert.assertEquals(3.4, interval.getSize(), 1.0e-10); + Assert.assertEquals(4.0, interval.getBarycenter(), 1.0e-10); Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(2.3, 1.0e-10)); Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(5.7, 1.0e-10)); Assert.assertEquals(Region.Location.OUTSIDE, interval.checkPoint(1.2, 1.0e-10)); Assert.assertEquals(Region.Location.OUTSIDE, interval.checkPoint(8.7, 1.0e-10)); Assert.assertEquals(Region.Location.INSIDE, interval.checkPoint(3.0, 1.0e-10)); - Assert.assertEquals(2.3, interval.getLower(), 1.0e-10); - Assert.assertEquals(5.7, interval.getUpper(), 1.0e-10); + Assert.assertEquals(2.3, interval.getInf(), 1.0e-10); + Assert.assertEquals(5.7, interval.getSup(), 1.0e-10); } @Test @@ -58,17 +58,17 @@ public class IntervalTest { Assert.assertEquals(Region.Location.INSIDE, interval.checkPoint(FastMath.pow(10.0, e), 1.0e-10)); } - Assert.assertTrue(Double.isInfinite(interval.getLength())); - Assert.assertEquals(9.0, interval.getLower(), 1.0e-10); - Assert.assertTrue(Double.isInfinite(interval.getUpper())); + Assert.assertTrue(Double.isInfinite(interval.getSize())); + Assert.assertEquals(9.0, interval.getInf(), 1.0e-10); + Assert.assertTrue(Double.isInfinite(interval.getSup())); } @Test public void testSinglePoint() { Interval interval = new Interval(1.0, 1.0); - Assert.assertEquals(0.0, interval.getLength(), Precision.SAFE_MIN); - Assert.assertEquals(1.0, interval.getMidPoint(), Precision.EPSILON); + Assert.assertEquals(0.0, interval.getSize(), Precision.SAFE_MIN); + Assert.assertEquals(1.0, interval.getBarycenter(), Precision.EPSILON); } } diff --git a/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSetTest.java b/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSetTest.java index 25e1cb2db..5896dc256 100644 --- a/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSetTest.java +++ b/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSetTest.java @@ -87,12 +87,12 @@ public class IntervalsSetTest { List list = set.asList(); Assert.assertEquals(3, list.size()); - Assert.assertEquals( 1.0, list.get(0).getLower(), 1.0e-10); - Assert.assertEquals( 3.0, list.get(0).getUpper(), 1.0e-10); - Assert.assertEquals( 5.0, list.get(1).getLower(), 1.0e-10); - Assert.assertEquals( 6.0, list.get(1).getUpper(), 1.0e-10); - Assert.assertEquals( 9.0, list.get(2).getLower(), 1.0e-10); - Assert.assertEquals(11.0, list.get(2).getUpper(), 1.0e-10); + Assert.assertEquals( 1.0, list.get(0).getInf(), 1.0e-10); + Assert.assertEquals( 3.0, list.get(0).getSup(), 1.0e-10); + Assert.assertEquals( 5.0, list.get(1).getInf(), 1.0e-10); + Assert.assertEquals( 6.0, list.get(1).getSup(), 1.0e-10); + Assert.assertEquals( 9.0, list.get(2).getInf(), 1.0e-10); + Assert.assertEquals(11.0, list.get(2).getSup(), 1.0e-10); } diff --git a/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java b/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java index d50addd1f..a1823eaa3 100644 --- a/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java @@ -231,17 +231,17 @@ public class PolygonsSetTest { List i1 = ((IntervalsSet) s1.getRemainingRegion()).asList(); Assert.assertEquals(2, i1.size()); Interval v10 = i1.get(0); - Vector2D p10Lower = l1.toSpace(new Vector1D(v10.getLower())); + Vector2D p10Lower = l1.toSpace(new Vector1D(v10.getInf())); Assert.assertEquals(0.0, p10Lower.getX(), 1.0e-10); Assert.assertEquals(1.5, p10Lower.getY(), 1.0e-10); - Vector2D p10Upper = l1.toSpace(new Vector1D(v10.getUpper())); + Vector2D p10Upper = l1.toSpace(new Vector1D(v10.getSup())); Assert.assertEquals(0.5, p10Upper.getX(), 1.0e-10); Assert.assertEquals(2.0, p10Upper.getY(), 1.0e-10); Interval v11 = i1.get(1); - Vector2D p11Lower = l1.toSpace(new Vector1D(v11.getLower())); + Vector2D p11Lower = l1.toSpace(new Vector1D(v11.getInf())); Assert.assertEquals(1.0, p11Lower.getX(), 1.0e-10); Assert.assertEquals(2.5, p11Lower.getY(), 1.0e-10); - Vector2D p11Upper = l1.toSpace(new Vector1D(v11.getUpper())); + Vector2D p11Upper = l1.toSpace(new Vector1D(v11.getSup())); Assert.assertEquals(1.5, p11Upper.getX(), 1.0e-10); Assert.assertEquals(3.0, p11Upper.getY(), 1.0e-10); @@ -250,10 +250,10 @@ public class PolygonsSetTest { List i2 = ((IntervalsSet) s2.getRemainingRegion()).asList(); Assert.assertEquals(1, i2.size()); Interval v20 = i2.get(0); - Vector2D p20Lower = l2.toSpace(new Vector1D(v20.getLower())); + Vector2D p20Lower = l2.toSpace(new Vector1D(v20.getInf())); Assert.assertEquals(1.0, p20Lower.getX(), 1.0e-10); Assert.assertEquals(2.0, p20Lower.getY(), 1.0e-10); - Vector2D p20Upper = l2.toSpace(new Vector1D(v20.getUpper())); + Vector2D p20Upper = l2.toSpace(new Vector1D(v20.getSup())); Assert.assertEquals(3.0, p20Upper.getX(), 1.0e-10); Assert.assertEquals(2.0, p20Upper.getY(), 1.0e-10);