You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2017/05/30 13:12:31 UTC

[1/2] commons-numbers git commit: Javadoc (CheckStyle).

Repository: commons-numbers
Updated Branches:
  refs/heads/master 6fd55c8cc -> 04e92c6eb


Javadoc (CheckStyle).


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/2b955e3a
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/2b955e3a
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/2b955e3a

Branch: refs/heads/master
Commit: 2b955e3a5ba20cbbed011be9caa1f22f59d35994
Parents: 6fd55c8
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Tue May 30 15:08:05 2017 +0200
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Tue May 30 15:08:05 2017 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java  | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/2b955e3a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
----------------------------------------------------------------------
diff --git a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
index 1385ea1..649be45 100644
--- a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
+++ b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java
@@ -128,6 +128,7 @@ public class PlaneAngle {
         return false;
     }
 
+    /** {@inheritDoc} */
     @Override
     public int hashCode() {
         return new Double(value).hashCode();


[2/2] commons-numbers git commit: NUMBERS-41: Utility class (syntactic sugar).

Posted by er...@apache.org.
NUMBERS-41: Utility class (syntactic sugar).


Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/04e92c6e
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/04e92c6e
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/04e92c6e

Branch: refs/heads/master
Commit: 04e92c6ebf0eac14514b381e750beaaf9257eac1
Parents: 2b955e3
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
Authored: Tue May 30 15:10:37 2017 +0200
Committer: Gilles Sadowski <gi...@harfang.homelinux.org>
Committed: Tue May 30 15:10:37 2017 +0200

----------------------------------------------------------------------
 .../numbers/angle/PlaneAngleRadians.java        | 41 ++++++++++++++++++++
 .../numbers/angle/PlaneAngleRadiansTest.java    | 35 +++++++++++++++++
 2 files changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/04e92c6e/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngleRadians.java
----------------------------------------------------------------------
diff --git a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngleRadians.java b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngleRadians.java
new file mode 100644
index 0000000..0dd6b0a
--- /dev/null
+++ b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngleRadians.java
@@ -0,0 +1,41 @@
+/*
+ * 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.numbers.angle;
+
+/**
+ * Utility class where all {@code double} values are assumed to be in
+ * radians.
+ *
+ * @see PlaneAngle
+ */
+public class PlaneAngleRadians {
+    /**
+     * Normalize an angle in an interval of size 2&pi; around a
+     * center value.
+     *
+     * @param angle Value to be normalized.
+     * @param center Center of the desired interval for the result.
+     * @return {@code a - 2 * k} with integer {@code k} such that
+     * {@code center - pi <= a - 2 * k * pi <= center + pi}.
+     */
+    public static double normalize(double angle,
+                                   double center) {
+        final PlaneAngle a = PlaneAngle.ofRadians(angle);
+        final PlaneAngle c = PlaneAngle.ofRadians(center);
+        return a.normalize(c).toRadians();
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/04e92c6e/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleRadiansTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleRadiansTest.java b/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleRadiansTest.java
new file mode 100644
index 0000000..1244915
--- /dev/null
+++ b/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/PlaneAngleRadiansTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.numbers.angle;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test cases for the {@link PlaneAngleRadians} class.
+ */
+public class PlaneAngleRadiansTest {
+    @Test
+    public void testNormalize() {
+        for (double a = -15.0; a <= 15.0; a += 0.1) {
+            for (double b = -15.0; b <= 15.0; b += 0.2) {
+                final double c = PlaneAngleRadians.normalize(a, b);
+                Assert.assertTrue((b - Math.PI) <= c);
+                Assert.assertTrue(c <= (b + Math.PI));
+                double twoK = Math.rint((a - c) / Math.PI);
+                Assert.assertEquals(c, a - twoK * Math.PI, 1e-14);
+            }
+        }
+    }
+}