commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1405706 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java
Date Mon, 05 Nov 2012 08:00:19 GMT
Author: luc
Date: Mon Nov  5 08:00:19 2012
New Revision: 1405706

URL: http://svn.apache.org/viewvc?rev=1405706&view=rev
Log:
Added a method to check points in the Interval class.

JIRA: MATH-889

Added:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java
  (with props)
Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1405706&r1=1405705&r2=1405706&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Mon Nov  5 08:00:19 2012
@@ -52,6 +52,9 @@ If the output is not quite correct, chec
   <body>
     <release version="3.1" date="TBD" description="
 ">
+      <action dev="luc" type="add" issue="MATH-889">
+        Added a method to check points in the Interval class, with a tolerance for boundary.
+      </action>
       <action dev="psteitz" type="add" issue="MATH-878" due-to="Radoslav Tsvetkov">
         Added G-test statistics.
       </action>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java?rev=1405706&r1=1405705&r2=1405706&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/Interval.java
Mon Nov  5 08:00:19 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math3.geometry.euclidean.oned;
 
+import org.apache.commons.math3.geometry.partitioning.Region.Location;
+
 
 /** This class represents a 1D interval.
  * @see IntervalsSet
@@ -67,4 +69,21 @@ public class Interval {
         return 0.5 * (lower + upper);
     }
 
+    /** Check a point with respect to the interval.
+     * @param point point to check
+     * @param tolerance tolerance below which points are considered to
+     * belong to the boundary
+     * @return a code representing the point status: either {@link
+     * Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY}
+     */
+    public Location checkPoint(final double point, final double tolerance) {
+        if (point < lower - tolerance || point > upper + tolerance) {
+            return Location.OUTSIDE;
+        } else if (point > lower + tolerance && point < upper - tolerance)
{
+            return Location.INSIDE;
+        } else {
+            return Location.BOUNDARY;
+        }
+    }
+
 }

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java?rev=1405706&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java
(added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java
Mon Nov  5 08:00:19 2012
@@ -0,0 +1,74 @@
+/*
+ * 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.math3.geometry.euclidean.oned;
+
+import org.apache.commons.math3.geometry.partitioning.Region;
+import org.apache.commons.math3.util.FastMath;
+import org.apache.commons.math3.util.Precision;
+import org.junit.Assert;
+import org.junit.Test;
+
+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(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);
+    }
+
+    @Test
+    public void testTolerance() {
+        Interval interval = new Interval(2.3, 5.7);
+        Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(1.2, 1.0));
+        Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(1.2, 1.2));
+        Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(8.7, 2.9));
+        Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(8.7, 3.1));
+        Assert.assertEquals(Region.Location.INSIDE,   interval.checkPoint(3.0, 0.6));
+        Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(3.0, 0.8));
+    }
+
+    @Test
+    public void testInfinite() {
+        Interval interval = new Interval(9.0, Double.POSITIVE_INFINITY);
+        Assert.assertEquals(Region.Location.BOUNDARY, interval.checkPoint(9.0, 1.0e-10));
+        Assert.assertEquals(Region.Location.OUTSIDE,  interval.checkPoint(8.4, 1.0e-10));
+        for (double e = 1.0; e <= 6.0; e += 1.0) {
+            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()));
+
+    }
+
+    @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);
+    }
+
+}

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message