[1/5] commons-numbers git commit: Create structure for fraction module within commons-numbers. Add dependencyManagement to parent pom.xml for uniform dependency on numbers core; remove version from re
Repository: commons-numbers Updated Branches: refs/heads/multimodule 69d3b6231 -> 763ec4fea http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/aaef6f7a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java -- diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java new file mode 100644 index 000..2c9a398 --- /dev/null +++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java @@ -0,0 +1,349 @@ +/* + * 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.fraction; + +import java.text.NumberFormat; +import java.util.Locale; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +public class FractionFormatTest { + +FractionFormat properFormat = null; +FractionFormat improperFormat = null; + +protected Locale getLocale() { +return Locale.getDefault(); +} + +@Before +public void setUp() { +properFormat = FractionFormat.getProperInstance(getLocale()); +improperFormat = FractionFormat.getImproperInstance(getLocale()); +} + +@Test +public void testFormat() { +Fraction c = new Fraction(1, 2); +String expected = "1 / 2"; + +String actual = properFormat.format(c); +Assert.assertEquals(expected, actual); + +actual = improperFormat.format(c); +Assert.assertEquals(expected, actual); +} + +@Test +public void testFormatNegative() { +Fraction c = new Fraction(-1, 2); +String expected = "-1 / 2"; + +String actual = properFormat.format(c); +Assert.assertEquals(expected, actual); + +actual = improperFormat.format(c); +Assert.assertEquals(expected, actual); +} + +@Test +public void testFormatZero() { +Fraction c = new Fraction(0, 1); +String expected = "0 / 1"; + +String actual = properFormat.format(c); +Assert.assertEquals(expected, actual); + +actual = improperFormat.format(c); +Assert.assertEquals(expected, actual); +} + +@Test +public void testFormatImproper() { +Fraction c = new Fraction(5, 3); + +String actual = properFormat.format(c); +Assert.assertEquals("1 2 / 3", actual); + +actual = improperFormat.format(c); +Assert.assertEquals("5 / 3", actual); +} + +@Test +public void testFormatImproperNegative() { +Fraction c = new Fraction(-5, 3); + +String actual = properFormat.format(c); +Assert.assertEquals("-1 2 / 3", actual); + +actual = improperFormat.format(c); +Assert.assertEquals("-5 / 3", actual); +} + +@Test +public void testParse() { +String source = "1 / 2"; + +try { +Fraction c = properFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(1, c.getNumerator()); +Assert.assertEquals(2, c.getDenominator()); + +c = improperFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(1, c.getNumerator()); +Assert.assertEquals(2, c.getDenominator()); +} catch (FractionParseException ex) { +Assert.fail(ex.getMessage()); +} +} + +@Test +public void testParseInteger() { +String source = "10"; +{ +Fraction c = properFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(10, c.getNumerator()); +Assert.assertEquals(1, c.getDenominator()); +} +{ +Fraction c = improperFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(10, c.getNumerator()); +Assert.assertEquals(1, c.getDenominator()); +} +} + +@Test +public void testParseOne1() { +String source = "1 / 1"; +Fraction c = properFormat.parse(s
[2/5] commons-numbers git commit: Create structure for fraction module within commons-numbers. Add dependencyManagement to parent pom.xml for uniform dependency on numbers core; remove version from re
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/aaef6f7a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java new file mode 100644 index 000..07db867 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java @@ -0,0 +1,51 @@ +/* + * 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.fraction; + +/** + * Error thrown when a double value cannot be converted to a fraction + * in the allowed number of iterations. + * + * @since 1.2 + */ +public class FractionConversionException extends FractionException { + +/** Serializable version identifier. */ +private static final long serialVersionUID = 201701181859L; + +/** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param value double value to convert + * @param maxIterations maximal number of iterations allowed + */ +public FractionConversionException(double value, int maxIterations) { +super("Unable to convert {0} to fraction after {1} iterations", value, maxIterations); +} + +/** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param value double value to convert + * @param p current numerator + * @param q current denominator + */ +public FractionConversionException(double value, long p, long q) { +super("Overflow trying to convert {0} to fraction ({1}/{2})", value, p, q); +} +} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/aaef6f7a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java new file mode 100644 index 000..6080981 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java @@ -0,0 +1,44 @@ +/* + * 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.fraction; + +import org.apache.commons.numbers.core.NumbersArithmeticException; + +/** + * Base class for all exceptions thrown in the module. + */ +public class FractionException extends NumbersArithmeticException { + +/** Serializable version identifier. */ +private static final long serialVersionUID = 201701191744L; + +protected Object[] formatArguments; + +public FractionException() { +} + +public FractionException(String message, Object... formatArguments) { +super(message); +this.formatArguments = formatArguments; +} + +public FractionException(String message, Throwable cause, Object... formatArguments) { +super(message, cause); +this.formatArguments = fo
[4/5] commons-numbers git commit: Create structure for fraction module within commons-numbers. Add dependencyManagement to parent pom.xml for uniform dependency on numbers core; remove version from re
Create structure for fraction module within commons-numbers. Add dependencyManagement to parent pom.xml for uniform dependency on numbers core; remove version from references to numbers-core in child modules. Add test jar to numbers core pom.xml to allow for re-use of TestUtils. Add ArithmeticUtils from commons-math since Fraction, BigFraction heavily depends on it. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/aaef6f7a Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/aaef6f7a Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/aaef6f7a Branch: refs/heads/multimodule Commit: aaef6f7aa74da893b018ec3debe4367de3243c48 Parents: b026db1 Author: Ray DeCampo Authored: Sun Jan 22 20:41:30 2017 -0500 Committer: Ray DeCampo Committed: Sun Jan 22 20:41:30 2017 -0500 -- commons-numbers-complex/pom.xml |1 - commons-numbers-core/pom.xml| 15 + .../commons/numbers/core/ArithmeticUtils.java | 772 +++ .../core/NumbersArithmeticException.java| 54 + .../numbers/core/ArithmeticUtilsTest.java | 782 commons-numbers-fraction/LICENSE.txt| 201 +++ commons-numbers-fraction/NOTICE.txt |6 + commons-numbers-fraction/README.md | 98 ++ commons-numbers-fraction/pom.xml| 58 + .../numbers/fraction/AbstractFormat.java| 206 +++ .../commons/numbers/fraction/BigFraction.java | 1199 ++ .../numbers/fraction/BigFractionField.java | 83 ++ .../numbers/fraction/BigFractionFormat.java | 283 + .../commons/numbers/fraction/Fraction.java | 664 ++ .../fraction/FractionConversionException.java | 51 + .../numbers/fraction/FractionException.java | 44 + .../commons/numbers/fraction/FractionField.java | 82 ++ .../numbers/fraction/FractionFormat.java| 261 .../fraction/FractionOverflowException.java | 47 + .../fraction/FractionParseException.java| 38 + .../fraction/ProperBigFractionFormat.java | 235 .../numbers/fraction/ProperFractionFormat.java | 227 .../fraction/ZeroDenominatorException.java | 53 + .../commons/numbers/fraction/package-info.java | 22 + .../numbers/fraction/BigFractionFieldTest.java | 43 + .../numbers/fraction/BigFractionFormatTest.java | 330 + .../numbers/fraction/BigFractionTest.java | 635 ++ .../numbers/fraction/FractionFieldTest.java | 43 + .../numbers/fraction/FractionFormatTest.java| 349 + .../commons/numbers/fraction/FractionTest.java | 625 + commons-numbers-quaternion/pom.xml |1 - pom.xml | 20 +- 32 files changed, 7525 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/aaef6f7a/commons-numbers-complex/pom.xml -- diff --git a/commons-numbers-complex/pom.xml b/commons-numbers-complex/pom.xml index 735348f..3fec4ba 100644 --- a/commons-numbers-complex/pom.xml +++ b/commons-numbers-complex/pom.xml @@ -46,7 +46,6 @@ org.apache.commons commons-numbers-core - 1.0-SNAPSHOT http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/aaef6f7a/commons-numbers-core/pom.xml -- diff --git a/commons-numbers-core/pom.xml b/commons-numbers-core/pom.xml index 39dbdcb..76c2512 100644 --- a/commons-numbers-core/pom.xml +++ b/commons-numbers-core/pom.xml @@ -42,5 +42,20 @@ ${basedir}/.. + + + +org.apache.maven.plugins +maven-jar-plugin + + + + test-jar + + + + + + http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/aaef6f7a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java new file mode 100644 index 000..343d24b --- /dev/null +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -0,0 +1,772 @@ +/* + * 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 "L
[3/5] commons-numbers git commit: Create structure for fraction module within commons-numbers. Add dependencyManagement to parent pom.xml for uniform dependency on numbers core; remove version from re
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/aaef6f7a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java new file mode 100644 index 000..b77b522 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java @@ -0,0 +1,206 @@ +/* + * 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.fraction; + +import java.io.Serializable; +import java.text.FieldPosition; +import java.text.NumberFormat; +import java.text.ParsePosition; +import java.util.Locale; + +/** + * Common part shared by both {@link FractionFormat} and {@link BigFractionFormat}. + * @since 2.0 + */ +public abstract class AbstractFormat extends NumberFormat implements Serializable { + +/** Serializable version identifier. */ +private static final long serialVersionUID = -6981118387974191891L; + +/** The format used for the denominator. */ +private NumberFormat denominatorFormat; + +/** The format used for the numerator. */ +private NumberFormat numeratorFormat; + +/** + * Create an improper formatting instance with the default number format + * for the numerator and denominator. + */ +protected AbstractFormat() { +this(getDefaultNumberFormat()); +} + +/** + * Create an improper formatting instance with a custom number format for + * both the numerator and denominator. + * @param format the custom format for both the numerator and denominator. + */ +protected AbstractFormat(final NumberFormat format) { +this(format, (NumberFormat) format.clone()); +} + +/** + * Create an improper formatting instance with a custom number format for + * the numerator and a custom number format for the denominator. + * @param numeratorFormat the custom format for the numerator. + * @param denominatorFormat the custom format for the denominator. + */ +protected AbstractFormat(final NumberFormat numeratorFormat, + final NumberFormat denominatorFormat) { +this.numeratorFormat = numeratorFormat; +this.denominatorFormat = denominatorFormat; +} + +/** + * Create a default number format. The default number format is based on + * {@link NumberFormat#getNumberInstance(java.util.Locale)}. The only + * customization is the maximum number of BigFraction digits, which is set to 0. + * @return the default number format. + */ +protected static NumberFormat getDefaultNumberFormat() { +return getDefaultNumberFormat(Locale.getDefault()); +} + +/** + * Create a default number format. The default number format is based on + * {@link NumberFormat#getNumberInstance(java.util.Locale)}. The only + * customization is the maximum number of BigFraction digits, which is set to 0. + * @param locale the specific locale used by the format. + * @return the default number format specific to the given locale. + */ +protected static NumberFormat getDefaultNumberFormat(final Locale locale) { +final NumberFormat nf = NumberFormat.getNumberInstance(locale); +nf.setMaximumFractionDigits(0); +nf.setParseIntegerOnly(true); +return nf; +} + +/** + * Access the denominator format. + * @return the denominator format. + */ +public NumberFormat getDenominatorFormat() { +return denominatorFormat; +} + +/** + * Access the numerator format. + * @return the numerator format. + */ +public NumberFormat getNumeratorFormat() { +return numeratorFormat; +} + +/** + * Modify the denominator format. + * @param format the new denominator format value. + * @throws NullPointerException if {@code format} is {@code null}. + */ +public void setDenominatorFormat(final NumberFormat format) { +
[5/5] commons-numbers git commit: Add maven module for fractions package from commons-math Resolves pull request #4
Add maven module for fractions package from commons-math Resolves pull request #4 Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/763ec4fe Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/763ec4fe Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/763ec4fe Branch: refs/heads/multimodule Commit: 763ec4fea595ea53792bf2a7d3dd08dedc567909 Parents: 69d3b62 aaef6f7 Author: Ray DeCampo Authored: Sat Jan 28 07:41:48 2017 -0500 Committer: Ray DeCampo Committed: Sat Jan 28 07:41:48 2017 -0500 -- commons-numbers-complex/pom.xml |1 - commons-numbers-core/pom.xml| 15 + .../commons/numbers/core/ArithmeticUtils.java | 772 +++ .../core/NumbersArithmeticException.java| 54 + .../numbers/core/ArithmeticUtilsTest.java | 782 commons-numbers-fraction/LICENSE.txt| 201 +++ commons-numbers-fraction/NOTICE.txt |6 + commons-numbers-fraction/README.md | 98 ++ commons-numbers-fraction/pom.xml| 58 + .../numbers/fraction/AbstractFormat.java| 206 +++ .../commons/numbers/fraction/BigFraction.java | 1199 ++ .../numbers/fraction/BigFractionField.java | 83 ++ .../numbers/fraction/BigFractionFormat.java | 283 + .../commons/numbers/fraction/Fraction.java | 664 ++ .../fraction/FractionConversionException.java | 51 + .../numbers/fraction/FractionException.java | 44 + .../commons/numbers/fraction/FractionField.java | 82 ++ .../numbers/fraction/FractionFormat.java| 261 .../fraction/FractionOverflowException.java | 47 + .../fraction/FractionParseException.java| 38 + .../fraction/ProperBigFractionFormat.java | 235 .../numbers/fraction/ProperFractionFormat.java | 227 .../fraction/ZeroDenominatorException.java | 53 + .../commons/numbers/fraction/package-info.java | 22 + .../numbers/fraction/BigFractionFieldTest.java | 43 + .../numbers/fraction/BigFractionFormatTest.java | 330 + .../numbers/fraction/BigFractionTest.java | 635 ++ .../numbers/fraction/FractionFieldTest.java | 43 + .../numbers/fraction/FractionFormatTest.java| 349 + .../commons/numbers/fraction/FractionTest.java | 625 + commons-numbers-quaternion/pom.xml |1 - pom.xml | 20 +- 32 files changed, 7525 insertions(+), 3 deletions(-) --
commons-numbers git commit: NUMBERS-6: Remove @since from classes as there has not been a release of common-numbers yet.
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 ca71f3559 -> fe27e8ec9 NUMBERS-6: Remove @since from classes as there has not been a release of common-numbers yet. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/fe27e8ec Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/fe27e8ec Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/fe27e8ec Branch: refs/heads/fraction__NUMBERS-6 Commit: fe27e8ec9e02ce99ed840d56ab6ecd6303fd2f3f Parents: ca71f35 Author: Ray DeCampo Authored: Sat Jan 28 14:56:34 2017 -0500 Committer: Ray DeCampo Committed: Sat Jan 28 14:56:34 2017 -0500 -- .../commons/numbers/core/ArithmeticUtils.java| 19 --- .../commons/numbers/fraction/AbstractFormat.java | 1 - .../commons/numbers/fraction/BigFraction.java| 2 -- .../numbers/fraction/BigFractionField.java | 1 - .../numbers/fraction/BigFractionFormat.java | 2 -- .../commons/numbers/fraction/Fraction.java | 2 -- .../fraction/FractionConversionException.java| 2 -- .../commons/numbers/fraction/FractionField.java | 1 - .../commons/numbers/fraction/FractionFormat.java | 2 -- .../fraction/ProperBigFractionFormat.java| 2 -- .../numbers/fraction/ProperFractionFormat.java | 2 -- 11 files changed, 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/fe27e8ec/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java index 343d24b..4f1d6cf 100644 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -38,7 +38,6 @@ public final class ArithmeticUtils { * @return the sum {@code x+y} * @throws NumbersArithmeticException if the result can not be represented * as an {@code int}. - * @since 1.1 */ public static int addAndCheck(int x, int y) throws NumbersArithmeticException { @@ -56,7 +55,6 @@ public final class ArithmeticUtils { * @param b an addend * @return the sum {@code a+b} * @throws NumbersArithmeticException if the result can not be represented as an long - * @since 1.2 */ public static long addAndCheck(long a, long b) throws NumbersArithmeticException { return addAndCheck(a, b, "overflow in addition: {0} + {1}"); @@ -88,7 +86,6 @@ public final class ArithmeticUtils { * @return the greatest common divisor (never negative). * @throws NumbersArithmeticException if the result cannot be represented as * a non-negative {@code int} value. - * @since 1.1 */ public static int gcd(int p, int q) throws NumbersArithmeticException { int a = p; @@ -228,7 +225,6 @@ public final class ArithmeticUtils { * @return the greatest common divisor, never negative. * @throws NumbersArithmeticException if the result cannot be represented as * a non-negative {@code long} value. - * @since 2.1 */ public static long gcd(final long p, final long q) throws NumbersArithmeticException { long u = p; @@ -308,7 +304,6 @@ public final class ArithmeticUtils { * @return the least common multiple, never negative. * @throws NumbersArithmeticException if the result cannot be represented as * a non-negative {@code int} value. - * @since 1.1 */ public static int lcm(int a, int b) throws NumbersArithmeticException { if (a == 0 || b == 0){ @@ -342,7 +337,6 @@ public final class ArithmeticUtils { * @return the least common multiple, never negative. * @throws NumbersArithmeticException if the result cannot be represented * as a non-negative {@code long} value. - * @since 2.1 */ public static long lcm(long a, long b) throws NumbersArithmeticException { if (a == 0 || b == 0){ @@ -364,7 +358,6 @@ public final class ArithmeticUtils { * @return the product {@code x * y}. * @throws NumbersArithmeticException if the result can not be * represented as an {@code int}. - * @since 1.1 */ public static int mulAndCheck(int x, int y) throws NumbersArithmeticException { long m = ((long)x) * ((long)y); @@ -382,7 +375,6 @@ public final class ArithmeticUtils { * @return the product {@code a * b}. * @throws NumbersArithmeticException if the result can not be represented * as a {@cod
commons-numbers git commit: NUMBERS-6: Make NumbersArithmeticException a private exception within ArithmeticUtils and change public API to reflect java.lang.ArithmeticException
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 fe27e8ec9 -> dca007d22 NUMBERS-6: Make NumbersArithmeticException a private exception within ArithmeticUtils and change public API to reflect java.lang.ArithmeticException Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/dca007d2 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/dca007d2 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/dca007d2 Branch: refs/heads/fraction__NUMBERS-6 Commit: dca007d2226649a55bd3ee512580ca63d7354e56 Parents: fe27e8e Author: Ray DeCampo Authored: Sun Jan 29 10:14:14 2017 -0500 Committer: Ray DeCampo Committed: Sun Jan 29 10:14:14 2017 -0500 -- .../commons/numbers/core/ArithmeticUtils.java | 83 ++-- .../core/NumbersArithmeticException.java| 54 - .../numbers/core/ArithmeticUtilsTest.java | 52 ++-- .../commons/numbers/fraction/Fraction.java | 12 +-- .../numbers/fraction/FractionException.java | 9 +-- .../numbers/fraction/BigFractionTest.java | 5 +- .../commons/numbers/fraction/FractionTest.java | 51 ++-- 7 files changed, 117 insertions(+), 149 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java index 4f1d6cf..ee502ca 100644 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -17,6 +17,7 @@ package org.apache.commons.numbers.core; import java.math.BigInteger; +import java.text.MessageFormat; /** * Some useful, arithmetics related, additions to the built-in functions in @@ -36,11 +37,11 @@ public final class ArithmeticUtils { * @param x an addend * @param y an addend * @return the sum {@code x+y} - * @throws NumbersArithmeticException if the result can not be represented + * @throws ArithmeticException if the result can not be represented * as an {@code int}. */ public static int addAndCheck(int x, int y) -throws NumbersArithmeticException { +throws ArithmeticException { long s = (long)x + (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { throw new NumbersArithmeticException("overflow in addition: {0} + {1}", x, y); @@ -54,9 +55,9 @@ public final class ArithmeticUtils { * @param a an addend * @param b an addend * @return the sum {@code a+b} - * @throws NumbersArithmeticException if the result can not be represented as an long + * @throws ArithmeticException if the result can not be represented as an long */ -public static long addAndCheck(long a, long b) throws NumbersArithmeticException { +public static long addAndCheck(long a, long b) throws ArithmeticException { return addAndCheck(a, b, "overflow in addition: {0} + {1}"); } @@ -84,10 +85,10 @@ public final class ArithmeticUtils { * @param p Number. * @param q Number. * @return the greatest common divisor (never negative). - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ -public static int gcd(int p, int q) throws NumbersArithmeticException { +public static int gcd(int p, int q) throws ArithmeticException { int a = p; int b = q; if (a == 0 || @@ -223,10 +224,10 @@ public final class ArithmeticUtils { * @param p Number. * @param q Number. * @return the greatest common divisor, never negative. - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code long} value. */ -public static long gcd(final long p, final long q) throws NumbersArithmeticException { +public static long gcd(final long p, final long q) throws ArithmeticException { long u = p; long v = q; if ((u == 0) || (v == 0)) { @@ -302,10 +303,10 @@ public final class ArithmeticUtils { * @param a Number. * @param b Number. * @return the least common multiple, never negative. - * @throws NumbersArithmeticException if the result cannot be r
commons-numbers git commit: NUMBERS-6: Remove throws clause for (unchecked) ArithmeticException
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 dca007d22 -> fbb60fbf9 NUMBERS-6: Remove throws clause for (unchecked) ArithmeticException Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/fbb60fbf Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/fbb60fbf Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/fbb60fbf Branch: refs/heads/fraction__NUMBERS-6 Commit: fbb60fbf90c4912492c748bca6638ccbcad399bd Parents: dca007d Author: Ray DeCampo Authored: Sun Jan 29 10:42:20 2017 -0500 Committer: Ray DeCampo Committed: Sun Jan 29 10:42:20 2017 -0500 -- .../commons/numbers/core/ArithmeticUtils.java | 29 +--- 1 file changed, 13 insertions(+), 16 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/fbb60fbf/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java index ee502ca..13055f2 100644 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -40,8 +40,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be represented * as an {@code int}. */ -public static int addAndCheck(int x, int y) -throws ArithmeticException { +public static int addAndCheck(int x, int y) { long s = (long)x + (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { throw new NumbersArithmeticException("overflow in addition: {0} + {1}", x, y); @@ -57,7 +56,7 @@ public final class ArithmeticUtils { * @return the sum {@code a+b} * @throws ArithmeticException if the result can not be represented as an long */ -public static long addAndCheck(long a, long b) throws ArithmeticException { +public static long addAndCheck(long a, long b) { return addAndCheck(a, b, "overflow in addition: {0} + {1}"); } @@ -88,7 +87,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ -public static int gcd(int p, int q) throws ArithmeticException { +public static int gcd(int p, int q) { int a = p; int b = q; if (a == 0 || @@ -227,7 +226,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code long} value. */ -public static long gcd(final long p, final long q) throws ArithmeticException { +public static long gcd(final long p, final long q) { long u = p; long v = q; if ((u == 0) || (v == 0)) { @@ -306,7 +305,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ -public static int lcm(int a, int b) throws ArithmeticException { +public static int lcm(int a, int b) { if (a == 0 || b == 0){ return 0; } @@ -339,7 +338,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented * as a non-negative {@code long} value. */ -public static long lcm(long a, long b) throws ArithmeticException { +public static long lcm(long a, long b) { if (a == 0 || b == 0){ return 0; } @@ -360,7 +359,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be * represented as an {@code int}. */ -public static int mulAndCheck(int x, int y) throws ArithmeticException { +public static int mulAndCheck(int x, int y) { long m = ((long)x) * ((long)y); if (m < Integer.MIN_VALUE || m > Integer.MAX_VALUE) { throw new NumbersArithmeticException(); @@ -377,7 +376,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be represented * as a {@code long}. */ -public static long mulAndCheck(long a, long b) throws ArithmeticException { +public static long mulAndCheck(long a, long b) { long ret; if (a > b) { // use symmetry to reduce boundary cases @@ -430,7 +429,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be represented * a
commons-numbers git commit: NUMBERS-6: Remove specialized exception from public API. FractionException becomes package private and inherits from java.lang.ArithmeticException. Subclasses of FractionEx
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 fbb60fbf9 -> 41e2f65b3 NUMBERS-6: Remove specialized exception from public API. FractionException becomes package private and inherits from java.lang.ArithmeticException. Subclasses of FractionException are eliminated. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/41e2f65b Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/41e2f65b Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/41e2f65b Branch: refs/heads/fraction__NUMBERS-6 Commit: 41e2f65b34c978f4377b2f043fec28a61402962d Parents: fbb60fb Author: Ray DeCampo Authored: Tue Jan 31 20:19:35 2017 -0500 Committer: Ray DeCampo Committed: Tue Jan 31 20:19:35 2017 -0500 -- .../commons/numbers/fraction/BigFraction.java | 21 .../commons/numbers/fraction/Fraction.java | 42 +++- .../fraction/FractionConversionException.java | 49 -- .../numbers/fraction/FractionException.java | 7 ++- .../numbers/fraction/FractionFormat.java| 4 +- .../fraction/FractionOverflowException.java | 47 - .../fraction/FractionParseException.java| 9 +++- .../fraction/ZeroDenominatorException.java | 53 .../numbers/fraction/BigFractionFormatTest.java | 12 ++--- .../numbers/fraction/BigFractionTest.java | 22 .../numbers/fraction/FractionFormatTest.java| 16 +++--- .../commons/numbers/fraction/FractionTest.java | 20 12 files changed, 78 insertions(+), 224 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index 4ba8e01..a5ab6f7 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -108,7 +108,7 @@ public class BigFraction checkNotNull(num, "numerator"); checkNotNull(den, "denominator"); if (den.signum() == 0) { -throw new ZeroDenominatorException(); +throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR); } if (num.signum() == 0) { numerator = BigInteger.ZERO; @@ -214,8 +214,7 @@ public class BigFraction * @see #BigFraction(double) */ public BigFraction(final double value, final double epsilon, - final int maxIterations) -throws FractionConversionException { + final int maxIterations) { this(value, epsilon, Integer.MAX_VALUE, maxIterations); } @@ -254,14 +253,13 @@ public class BigFraction * if the continued fraction failed to converge. */ private BigFraction(final double value, final double epsilon, -final int maxDenominator, int maxIterations) -throws FractionConversionException { +final int maxDenominator, int maxIterations) { long overflow = Integer.MAX_VALUE; double r0 = value; long a0 = (long) Math.floor(r0); if (Math.abs(a0) > overflow) { -throw new FractionConversionException(value, a0, 1l); +throw new FractionException(FractionException.ERROR_CONVERSION_OVERFLOW, value, a0, 1l); } // check for (almost) integer arguments, which should not go @@ -294,7 +292,7 @@ public class BigFraction if (epsilon == 0.0 && Math.abs(q1) < maxDenominator) { break; } -throw new FractionConversionException(value, p2, q2); +throw new FractionException(FractionException.ERROR_CONVERSION_OVERFLOW, value, p2, q2); } final double convergent = (double) p2 / (double) q2; @@ -313,7 +311,7 @@ public class BigFraction } while (!stop); if (n >= maxIterations) { -throw new FractionConversionException(value, maxIterations); +throw new FractionException(FractionException.ERROR_CONVERSION, value, maxIterations); } if (q2 < maxDenominator) { @@ -342,8 +340,7 @@ public class BigFraction * @throws FractionConversionException * if the continued fraction failed to converge. */ -public BigFraction(final double value, final int maxD
commons-numbers git commit: NUMBERS-6: Remove specialized exception from public API (contd). FractionParseException becomes package private and inherits from java.text.ParseException.
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 41e2f65b3 -> ec826b0fc NUMBERS-6: Remove specialized exception from public API (contd). FractionParseException becomes package private and inherits from java.text.ParseException. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/ec826b0f Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/ec826b0f Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/ec826b0f Branch: refs/heads/fraction__NUMBERS-6 Commit: ec826b0fc1ae6d731d3b848cf9f60f676c4bc261 Parents: 41e2f65 Author: Ray DeCampo Authored: Tue Jan 31 20:26:59 2017 -0500 Committer: Ray DeCampo Committed: Tue Jan 31 20:26:59 2017 -0500 -- .../numbers/fraction/BigFractionFormat.java | 5 +++-- .../commons/numbers/fraction/Fraction.java | 4 ++-- .../numbers/fraction/FractionException.java | 17 - .../commons/numbers/fraction/FractionFormat.java | 5 +++-- .../numbers/fraction/FractionParseException.java | 2 +- .../numbers/fraction/BigFractionFormatTest.java | 17 + .../numbers/fraction/FractionFormatTest.java | 19 ++- 7 files changed, 44 insertions(+), 25 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java index aca674c..822e6a2 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.math.BigInteger; import java.text.FieldPosition; import java.text.NumberFormat; +import java.text.ParseException; import java.text.ParsePosition; import java.util.Locale; @@ -177,11 +178,11 @@ public class BigFractionFormat extends AbstractFormat implements Serializable { * Parses a string to produce a {@link BigFraction} object. * @param source the string to parse * @return the parsed {@link BigFraction} object. - * @exception FractionParseException if the beginning of the specified string + * @exception ParseException if the beginning of the specified string *cannot be parsed. */ @Override -public BigFraction parse(final String source) throws FractionParseException { +public BigFraction parse(final String source) throws ParseException { final ParsePosition parsePosition = new ParsePosition(0); final BigFraction result = parse(source, parsePosition); if (parsePosition.getIndex() == 0) { http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java index 31abd17..bfd7734 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java @@ -257,7 +257,7 @@ public class Fraction if (den < 0) { if (num == Integer.MIN_VALUE || den == Integer.MIN_VALUE) { -throw new FractionException("overflow in fraction {0}/{1}, cannot negate", num, den); +throw new FractionException(FractionException.ERROR_NEGATION_OVERFLOW, num, den); } num = -num; den = -den; @@ -617,7 +617,7 @@ public class Fraction if (denominator < 0) { if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { -throw new FractionException("overflow in fraction {0}/{1}, cannot negate", numerator, denominator); +throw new FractionException(FractionException.ERROR_NEGATION_OVERFLOW, numerator, denominator); } numerator = -numerator; denominator = -denominator; http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java -
commons-numbers git commit: NUMBERS-6: Fix javadoc errors
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 ec826b0fc -> ffe11d9d8 NUMBERS-6: Fix javadoc errors Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/ffe11d9d Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/ffe11d9d Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/ffe11d9d Branch: refs/heads/fraction__NUMBERS-6 Commit: ffe11d9d884594f08792f688bf5c78c9e07e61dd Parents: ec826b0 Author: Ray DeCampo Authored: Tue Jan 31 20:32:37 2017 -0500 Committer: Ray DeCampo Committed: Tue Jan 31 20:32:37 2017 -0500 -- .../apache/commons/numbers/fraction/BigFraction.java| 12 +--- .../org/apache/commons/numbers/fraction/Fraction.java | 4 ++-- .../apache/commons/numbers/fraction/FractionFormat.java | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ffe11d9d/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index a5ab6f7..9d653b1 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -102,7 +102,7 @@ public class BigFraction * * @param num the numerator, must not be {@code null}. * @param den the denominator, must not be {@code null}. - * @throws ZeroDenominatorException if the denominator is zero. + * @throws ArithmeticException if the denominator is zero. */ public BigFraction(BigInteger num, BigInteger den) { checkNotNull(num, "numerator"); @@ -200,7 +200,6 @@ public class BigFraction * http://mathworld.wolfram.com/ContinuedFraction.html";> * Continued Fraction equations (11) and (22)-(26) * - * * * @param value *the double value to convert to a fraction. @@ -209,7 +208,7 @@ public class BigFraction *epsilon of value, in absolute terms. * @param maxIterations *maximum number of convergents. - * @throws FractionConversionException + * @throws ArithmeticException * if the continued fraction failed to converge. * @see #BigFraction(double) */ @@ -331,13 +330,12 @@ public class BigFraction * http://mathworld.wolfram.com/ContinuedFraction.html";> * Continued Fraction equations (11) and (22)-(26) * - * * * @param value *the double value to convert to a fraction. * @param maxDenominator *The maximum allowed value for denominator. - * @throws FractionConversionException + * @throws ArithmeticException * if the continued fraction failed to converge. */ public BigFraction(final double value, final int maxDenominator) { @@ -617,7 +615,7 @@ public class BigFraction * * @param bg the {@code BigInteger} to divide by, must not be {@code null} * @return a {@link BigFraction} instance with the resulting values - * @throws ZeroDenominatorException if the fraction to divide by is zero + * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigInteger bg) { checkNotNull(bg, "bg"); @@ -666,7 +664,7 @@ public class BigFraction * * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws ZeroDenominatorException if the fraction to divide by is zero + * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigFraction fraction) { checkNotNull(fraction, "fraction"); http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ffe11d9d/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java index bfd7734..1697d8d 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java @@ -101,7 +101,7 @@ public class Fraction
commons-numbers git commit: NUMBERS-6: Remove Field classes and references to same
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 ffe11d9d8 -> 16352312b NUMBERS-6: Remove Field classes and references to same Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/16352312 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/16352312 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/16352312 Branch: refs/heads/fraction__NUMBERS-6 Commit: 16352312bac6661d4facd234f6d00dd4ed37ff58 Parents: ffe11d9 Author: Ray DeCampo Authored: Thu Feb 2 18:04:19 2017 -0500 Committer: Ray DeCampo Committed: Thu Feb 2 18:04:19 2017 -0500 -- .../commons/numbers/fraction/BigFraction.java | 6 +- .../numbers/fraction/BigFractionField.java | 82 .../commons/numbers/fraction/Fraction.java | 7 +- .../commons/numbers/fraction/FractionField.java | 81 --- .../numbers/fraction/BigFractionFieldTest.java | 43 -- .../numbers/fraction/FractionFieldTest.java | 43 -- 6 files changed, 2 insertions(+), 260 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/16352312/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index 9d653b1..eae82ea 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -27,7 +27,7 @@ import org.apache.commons.numbers.core.ArithmeticUtils; */ public class BigFraction extends Number -implements /*FieldElement, */Comparable, Serializable { +implements Comparable, Serializable { /** A fraction representing "2 / 1". */ public static final BigFraction TWO = new BigFraction(2); @@ -1179,10 +1179,6 @@ public class BigFraction return str; } -public BigFractionField getField() { -return BigFractionField.getInstance(); -} - private static void checkNotNull(Object arg, String argName) { if (arg == null) { throw new NullPointerException(argName); http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/16352312/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java deleted file mode 100644 index 7430eaa..000 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.fraction; - -import java.io.Serializable; - - -/** - * Representation of the fractional numbers without any overflow field. - * - * This class is a singleton. - * - * @see Fraction - */ -public class BigFractionField implements /*Field, */Serializable { - -/** Serializable version identifier */ -private static final long serialVersionUID = -1699294557189741703L; - -/** Private constructor for the singleton. - */ -private BigFractionField() { -} - -/** Get the unique instance. - * @return the unique instance - */ -public static BigFractionField getInstance() { -return LazyHolder.INSTANCE; -} - -/** {@inheritDoc} */ -public BigFraction getOne() { -return BigFraction.ONE; -} - -/** {@inheritDoc} */ -public BigFraction getZero() { -return BigFraction.ZERO; -} - -/** {@inheritDoc} */ -/* -
commons-numbers git commit: NUMBERS-6: Fix checkstyle issues.
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 16352312b -> 985d44fca NUMBERS-6: Fix checkstyle issues. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/985d44fc Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/985d44fc Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/985d44fc Branch: refs/heads/fraction__NUMBERS-6 Commit: 985d44fca746154042730c3b2743678f5df934ae Parents: 1635231 Author: Ray DeCampo Authored: Thu Feb 2 18:58:44 2017 -0500 Committer: Ray DeCampo Committed: Thu Feb 2 18:58:44 2017 -0500 -- .../commons/numbers/fraction/BigFraction.java | 32 ++-- .../commons/numbers/fraction/Fraction.java | 13 +--- .../numbers/fraction/FractionException.java | 20 ++-- .../fraction/FractionParseException.java| 2 +- 4 files changed, 42 insertions(+), 25 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/985d44fc/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index eae82ea..eab9b7f 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -77,6 +77,12 @@ public class BigFraction /** BigInteger representation of 100. */ private static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100); +/** Parameter name for fraction (to satisfy checkstyle). */ +private static final String PARAM_NAME_FRACTION = "fraction"; + +/** Parameter name for BigIntegers (to satisfy checkstyle). */ +private static final String PARAM_NAME_BG = "bg"; + /** The numerator. */ private final BigInteger numerator; @@ -248,7 +254,7 @@ public class BigFraction *maximum denominator value allowed. * @param maxIterations *maximum number of convergents. - * @throws FractionConversionException + * @throws ArithmeticException * if the continued fraction failed to converge. */ private BigFraction(final double value, final double epsilon, @@ -446,8 +452,8 @@ public class BigFraction *the {@link BigInteger} to add, must'nt be null. * @return a BigFraction instance with the resulting values. */ -public BigFraction add(final BigInteger bg) throws NullPointerException { -checkNotNull(bg, "bg"); +public BigFraction add(final BigInteger bg) { +checkNotNull(bg, PARAM_NAME_BG); if (numerator.signum() == 0) { return new BigFraction(bg); @@ -498,7 +504,7 @@ public class BigFraction * @return a {@link BigFraction} instance with the resulting values. */ public BigFraction add(final BigFraction fraction) { -checkNotNull(fraction, "fraction"); +checkNotNull(fraction, PARAM_NAME_FRACTION); if (fraction.numerator.signum() == 0) { return this; } @@ -618,7 +624,7 @@ public class BigFraction * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigInteger bg) { -checkNotNull(bg, "bg"); +checkNotNull(bg, PARAM_NAME_BG); if (bg.signum() == 0) { throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR); } @@ -667,7 +673,7 @@ public class BigFraction * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigFraction fraction) { -checkNotNull(fraction, "fraction"); +checkNotNull(fraction, PARAM_NAME_FRACTION); if (fraction.numerator.signum() == 0) { throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR); } @@ -871,7 +877,7 @@ public class BigFraction * @return a {@code BigFraction} instance with the resulting values. */ public BigFraction multiply(final BigInteger bg) { -checkNotNull(bg, "bg"); +checkNotNull(bg, PARAM_NAME_BG); if (numerator.signum() == 0 || bg.signum() == 0) { return ZERO; } @@ -924,7 +930,7 @@ public class BigFraction * @return a {@link BigFraction} instance with the resulting values. */ public BigFraction multiply(final BigFraction fraction) { -checkNotNull(fraction, "fraction"); +checkNotNull(fraction, PARAM_NAME_FRACTION);
[01/13] commons-numbers git commit: NUMBERS-6: Create structure for fraction module within commons-numbers.
Repository: commons-numbers Updated Branches: refs/heads/master 237697268 -> 39b5119cc http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ca71f355/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java -- diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java new file mode 100644 index 000..2c9a398 --- /dev/null +++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java @@ -0,0 +1,349 @@ +/* + * 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.fraction; + +import java.text.NumberFormat; +import java.util.Locale; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +public class FractionFormatTest { + +FractionFormat properFormat = null; +FractionFormat improperFormat = null; + +protected Locale getLocale() { +return Locale.getDefault(); +} + +@Before +public void setUp() { +properFormat = FractionFormat.getProperInstance(getLocale()); +improperFormat = FractionFormat.getImproperInstance(getLocale()); +} + +@Test +public void testFormat() { +Fraction c = new Fraction(1, 2); +String expected = "1 / 2"; + +String actual = properFormat.format(c); +Assert.assertEquals(expected, actual); + +actual = improperFormat.format(c); +Assert.assertEquals(expected, actual); +} + +@Test +public void testFormatNegative() { +Fraction c = new Fraction(-1, 2); +String expected = "-1 / 2"; + +String actual = properFormat.format(c); +Assert.assertEquals(expected, actual); + +actual = improperFormat.format(c); +Assert.assertEquals(expected, actual); +} + +@Test +public void testFormatZero() { +Fraction c = new Fraction(0, 1); +String expected = "0 / 1"; + +String actual = properFormat.format(c); +Assert.assertEquals(expected, actual); + +actual = improperFormat.format(c); +Assert.assertEquals(expected, actual); +} + +@Test +public void testFormatImproper() { +Fraction c = new Fraction(5, 3); + +String actual = properFormat.format(c); +Assert.assertEquals("1 2 / 3", actual); + +actual = improperFormat.format(c); +Assert.assertEquals("5 / 3", actual); +} + +@Test +public void testFormatImproperNegative() { +Fraction c = new Fraction(-5, 3); + +String actual = properFormat.format(c); +Assert.assertEquals("-1 2 / 3", actual); + +actual = improperFormat.format(c); +Assert.assertEquals("-5 / 3", actual); +} + +@Test +public void testParse() { +String source = "1 / 2"; + +try { +Fraction c = properFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(1, c.getNumerator()); +Assert.assertEquals(2, c.getDenominator()); + +c = improperFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(1, c.getNumerator()); +Assert.assertEquals(2, c.getDenominator()); +} catch (FractionParseException ex) { +Assert.fail(ex.getMessage()); +} +} + +@Test +public void testParseInteger() { +String source = "10"; +{ +Fraction c = properFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(10, c.getNumerator()); +Assert.assertEquals(1, c.getDenominator()); +} +{ +Fraction c = improperFormat.parse(source); +Assert.assertNotNull(c); +Assert.assertEquals(10, c.getNumerator()); +Assert.assertEquals(1, c.getDenominator()); +} +} + +@Test +public void testParseOne1() { +String source = "1 / 1"; +Fraction c = properFormat.parse(source
[05/13] commons-numbers git commit: NUMBERS-6: Remove @since from classes as there has not been a release of common-numbers yet.
NUMBERS-6: Remove @since from classes as there has not been a release of common-numbers yet. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/fe27e8ec Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/fe27e8ec Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/fe27e8ec Branch: refs/heads/master Commit: fe27e8ec9e02ce99ed840d56ab6ecd6303fd2f3f Parents: ca71f35 Author: Ray DeCampo Authored: Sat Jan 28 14:56:34 2017 -0500 Committer: Ray DeCampo Committed: Sat Jan 28 14:56:34 2017 -0500 -- .../commons/numbers/core/ArithmeticUtils.java| 19 --- .../commons/numbers/fraction/AbstractFormat.java | 1 - .../commons/numbers/fraction/BigFraction.java| 2 -- .../numbers/fraction/BigFractionField.java | 1 - .../numbers/fraction/BigFractionFormat.java | 2 -- .../commons/numbers/fraction/Fraction.java | 2 -- .../fraction/FractionConversionException.java| 2 -- .../commons/numbers/fraction/FractionField.java | 1 - .../commons/numbers/fraction/FractionFormat.java | 2 -- .../fraction/ProperBigFractionFormat.java| 2 -- .../numbers/fraction/ProperFractionFormat.java | 2 -- 11 files changed, 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/fe27e8ec/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java index 343d24b..4f1d6cf 100644 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -38,7 +38,6 @@ public final class ArithmeticUtils { * @return the sum {@code x+y} * @throws NumbersArithmeticException if the result can not be represented * as an {@code int}. - * @since 1.1 */ public static int addAndCheck(int x, int y) throws NumbersArithmeticException { @@ -56,7 +55,6 @@ public final class ArithmeticUtils { * @param b an addend * @return the sum {@code a+b} * @throws NumbersArithmeticException if the result can not be represented as an long - * @since 1.2 */ public static long addAndCheck(long a, long b) throws NumbersArithmeticException { return addAndCheck(a, b, "overflow in addition: {0} + {1}"); @@ -88,7 +86,6 @@ public final class ArithmeticUtils { * @return the greatest common divisor (never negative). * @throws NumbersArithmeticException if the result cannot be represented as * a non-negative {@code int} value. - * @since 1.1 */ public static int gcd(int p, int q) throws NumbersArithmeticException { int a = p; @@ -228,7 +225,6 @@ public final class ArithmeticUtils { * @return the greatest common divisor, never negative. * @throws NumbersArithmeticException if the result cannot be represented as * a non-negative {@code long} value. - * @since 2.1 */ public static long gcd(final long p, final long q) throws NumbersArithmeticException { long u = p; @@ -308,7 +304,6 @@ public final class ArithmeticUtils { * @return the least common multiple, never negative. * @throws NumbersArithmeticException if the result cannot be represented as * a non-negative {@code int} value. - * @since 1.1 */ public static int lcm(int a, int b) throws NumbersArithmeticException { if (a == 0 || b == 0){ @@ -342,7 +337,6 @@ public final class ArithmeticUtils { * @return the least common multiple, never negative. * @throws NumbersArithmeticException if the result cannot be represented * as a non-negative {@code long} value. - * @since 2.1 */ public static long lcm(long a, long b) throws NumbersArithmeticException { if (a == 0 || b == 0){ @@ -364,7 +358,6 @@ public final class ArithmeticUtils { * @return the product {@code x * y}. * @throws NumbersArithmeticException if the result can not be * represented as an {@code int}. - * @since 1.1 */ public static int mulAndCheck(int x, int y) throws NumbersArithmeticException { long m = ((long)x) * ((long)y); @@ -382,7 +375,6 @@ public final class ArithmeticUtils { * @return the product {@code a * b}. * @throws NumbersArithmeticException if the result can not be represented * as a {@code long}. - * @since 1.2 */ public static long mulAndCheck(long a, long b) throws NumbersArithmeticExc
[07/13] commons-numbers git commit: NUMBERS-6: Remove throws clause for (unchecked) ArithmeticException
NUMBERS-6: Remove throws clause for (unchecked) ArithmeticException Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/fbb60fbf Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/fbb60fbf Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/fbb60fbf Branch: refs/heads/master Commit: fbb60fbf90c4912492c748bca6638ccbcad399bd Parents: dca007d Author: Ray DeCampo Authored: Sun Jan 29 10:42:20 2017 -0500 Committer: Ray DeCampo Committed: Sun Jan 29 10:42:20 2017 -0500 -- .../commons/numbers/core/ArithmeticUtils.java | 29 +--- 1 file changed, 13 insertions(+), 16 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/fbb60fbf/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java index ee502ca..13055f2 100644 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -40,8 +40,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be represented * as an {@code int}. */ -public static int addAndCheck(int x, int y) -throws ArithmeticException { +public static int addAndCheck(int x, int y) { long s = (long)x + (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { throw new NumbersArithmeticException("overflow in addition: {0} + {1}", x, y); @@ -57,7 +56,7 @@ public final class ArithmeticUtils { * @return the sum {@code a+b} * @throws ArithmeticException if the result can not be represented as an long */ -public static long addAndCheck(long a, long b) throws ArithmeticException { +public static long addAndCheck(long a, long b) { return addAndCheck(a, b, "overflow in addition: {0} + {1}"); } @@ -88,7 +87,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ -public static int gcd(int p, int q) throws ArithmeticException { +public static int gcd(int p, int q) { int a = p; int b = q; if (a == 0 || @@ -227,7 +226,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code long} value. */ -public static long gcd(final long p, final long q) throws ArithmeticException { +public static long gcd(final long p, final long q) { long u = p; long v = q; if ((u == 0) || (v == 0)) { @@ -306,7 +305,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ -public static int lcm(int a, int b) throws ArithmeticException { +public static int lcm(int a, int b) { if (a == 0 || b == 0){ return 0; } @@ -339,7 +338,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result cannot be represented * as a non-negative {@code long} value. */ -public static long lcm(long a, long b) throws ArithmeticException { +public static long lcm(long a, long b) { if (a == 0 || b == 0){ return 0; } @@ -360,7 +359,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be * represented as an {@code int}. */ -public static int mulAndCheck(int x, int y) throws ArithmeticException { +public static int mulAndCheck(int x, int y) { long m = ((long)x) * ((long)y); if (m < Integer.MIN_VALUE || m > Integer.MAX_VALUE) { throw new NumbersArithmeticException(); @@ -377,7 +376,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be represented * as a {@code long}. */ -public static long mulAndCheck(long a, long b) throws ArithmeticException { +public static long mulAndCheck(long a, long b) { long ret; if (a > b) { // use symmetry to reduce boundary cases @@ -430,7 +429,7 @@ public final class ArithmeticUtils { * @throws ArithmeticException if the result can not be represented * as an {@code int}. */ -public static int subAndCheck(int x, int y) throws ArithmeticException { +public
[02/13] commons-numbers git commit: NUMBERS-6: Create structure for fraction module within commons-numbers.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ca71f355/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java new file mode 100644 index 000..07db867 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java @@ -0,0 +1,51 @@ +/* + * 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.fraction; + +/** + * Error thrown when a double value cannot be converted to a fraction + * in the allowed number of iterations. + * + * @since 1.2 + */ +public class FractionConversionException extends FractionException { + +/** Serializable version identifier. */ +private static final long serialVersionUID = 201701181859L; + +/** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param value double value to convert + * @param maxIterations maximal number of iterations allowed + */ +public FractionConversionException(double value, int maxIterations) { +super("Unable to convert {0} to fraction after {1} iterations", value, maxIterations); +} + +/** + * Constructs an exception with specified formatted detail message. + * Message formatting is delegated to {@link java.text.MessageFormat}. + * @param value double value to convert + * @param p current numerator + * @param q current denominator + */ +public FractionConversionException(double value, long p, long q) { +super("Overflow trying to convert {0} to fraction ({1}/{2})", value, p, q); +} +} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ca71f355/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java new file mode 100644 index 000..6080981 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java @@ -0,0 +1,44 @@ +/* + * 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.fraction; + +import org.apache.commons.numbers.core.NumbersArithmeticException; + +/** + * Base class for all exceptions thrown in the module. + */ +public class FractionException extends NumbersArithmeticException { + +/** Serializable version identifier. */ +private static final long serialVersionUID = 201701191744L; + +protected Object[] formatArguments; + +public FractionException() { +} + +public FractionException(String message, Object... formatArguments) { +super(message); +this.formatArguments = formatArguments; +} + +public FractionException(String message, Throwable cause, Object... formatArguments) { +super(message, cause); +this.formatArguments = fo
[10/13] commons-numbers git commit: NUMBERS-6: Fix javadoc errors
NUMBERS-6: Fix javadoc errors Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/ffe11d9d Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/ffe11d9d Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/ffe11d9d Branch: refs/heads/master Commit: ffe11d9d884594f08792f688bf5c78c9e07e61dd Parents: ec826b0 Author: Ray DeCampo Authored: Tue Jan 31 20:32:37 2017 -0500 Committer: Ray DeCampo Committed: Tue Jan 31 20:32:37 2017 -0500 -- .../apache/commons/numbers/fraction/BigFraction.java| 12 +--- .../org/apache/commons/numbers/fraction/Fraction.java | 4 ++-- .../apache/commons/numbers/fraction/FractionFormat.java | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ffe11d9d/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index a5ab6f7..9d653b1 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -102,7 +102,7 @@ public class BigFraction * * @param num the numerator, must not be {@code null}. * @param den the denominator, must not be {@code null}. - * @throws ZeroDenominatorException if the denominator is zero. + * @throws ArithmeticException if the denominator is zero. */ public BigFraction(BigInteger num, BigInteger den) { checkNotNull(num, "numerator"); @@ -200,7 +200,6 @@ public class BigFraction * http://mathworld.wolfram.com/ContinuedFraction.html";> * Continued Fraction equations (11) and (22)-(26) * - * * * @param value *the double value to convert to a fraction. @@ -209,7 +208,7 @@ public class BigFraction *epsilon of value, in absolute terms. * @param maxIterations *maximum number of convergents. - * @throws FractionConversionException + * @throws ArithmeticException * if the continued fraction failed to converge. * @see #BigFraction(double) */ @@ -331,13 +330,12 @@ public class BigFraction * http://mathworld.wolfram.com/ContinuedFraction.html";> * Continued Fraction equations (11) and (22)-(26) * - * * * @param value *the double value to convert to a fraction. * @param maxDenominator *The maximum allowed value for denominator. - * @throws FractionConversionException + * @throws ArithmeticException * if the continued fraction failed to converge. */ public BigFraction(final double value, final int maxDenominator) { @@ -617,7 +615,7 @@ public class BigFraction * * @param bg the {@code BigInteger} to divide by, must not be {@code null} * @return a {@link BigFraction} instance with the resulting values - * @throws ZeroDenominatorException if the fraction to divide by is zero + * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigInteger bg) { checkNotNull(bg, "bg"); @@ -666,7 +664,7 @@ public class BigFraction * * @param fraction Fraction to divide by, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values. - * @throws ZeroDenominatorException if the fraction to divide by is zero + * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigFraction fraction) { checkNotNull(fraction, "fraction"); http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ffe11d9d/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java index bfd7734..1697d8d 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java @@ -101,7 +101,7 @@ public class Fraction * http://mathworld.wolfram.com/ContinuedFraction.html";> * Continued Fraction equations (11) and (22)-(26)
[03/13] commons-numbers git commit: NUMBERS-6: Create structure for fraction module within commons-numbers.
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ca71f355/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java new file mode 100644 index 000..b77b522 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/AbstractFormat.java @@ -0,0 +1,206 @@ +/* + * 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.fraction; + +import java.io.Serializable; +import java.text.FieldPosition; +import java.text.NumberFormat; +import java.text.ParsePosition; +import java.util.Locale; + +/** + * Common part shared by both {@link FractionFormat} and {@link BigFractionFormat}. + * @since 2.0 + */ +public abstract class AbstractFormat extends NumberFormat implements Serializable { + +/** Serializable version identifier. */ +private static final long serialVersionUID = -6981118387974191891L; + +/** The format used for the denominator. */ +private NumberFormat denominatorFormat; + +/** The format used for the numerator. */ +private NumberFormat numeratorFormat; + +/** + * Create an improper formatting instance with the default number format + * for the numerator and denominator. + */ +protected AbstractFormat() { +this(getDefaultNumberFormat()); +} + +/** + * Create an improper formatting instance with a custom number format for + * both the numerator and denominator. + * @param format the custom format for both the numerator and denominator. + */ +protected AbstractFormat(final NumberFormat format) { +this(format, (NumberFormat) format.clone()); +} + +/** + * Create an improper formatting instance with a custom number format for + * the numerator and a custom number format for the denominator. + * @param numeratorFormat the custom format for the numerator. + * @param denominatorFormat the custom format for the denominator. + */ +protected AbstractFormat(final NumberFormat numeratorFormat, + final NumberFormat denominatorFormat) { +this.numeratorFormat = numeratorFormat; +this.denominatorFormat = denominatorFormat; +} + +/** + * Create a default number format. The default number format is based on + * {@link NumberFormat#getNumberInstance(java.util.Locale)}. The only + * customization is the maximum number of BigFraction digits, which is set to 0. + * @return the default number format. + */ +protected static NumberFormat getDefaultNumberFormat() { +return getDefaultNumberFormat(Locale.getDefault()); +} + +/** + * Create a default number format. The default number format is based on + * {@link NumberFormat#getNumberInstance(java.util.Locale)}. The only + * customization is the maximum number of BigFraction digits, which is set to 0. + * @param locale the specific locale used by the format. + * @return the default number format specific to the given locale. + */ +protected static NumberFormat getDefaultNumberFormat(final Locale locale) { +final NumberFormat nf = NumberFormat.getNumberInstance(locale); +nf.setMaximumFractionDigits(0); +nf.setParseIntegerOnly(true); +return nf; +} + +/** + * Access the denominator format. + * @return the denominator format. + */ +public NumberFormat getDenominatorFormat() { +return denominatorFormat; +} + +/** + * Access the numerator format. + * @return the numerator format. + */ +public NumberFormat getNumeratorFormat() { +return numeratorFormat; +} + +/** + * Modify the denominator format. + * @param format the new denominator format value. + * @throws NullPointerException if {@code format} is {@code null}. + */ +public void setDenominatorFormat(final NumberFormat format) { +
[06/13] commons-numbers git commit: NUMBERS-6: Make NumbersArithmeticException a private exception within ArithmeticUtils and change public API to reflect java.lang.ArithmeticException
NUMBERS-6: Make NumbersArithmeticException a private exception within ArithmeticUtils and change public API to reflect java.lang.ArithmeticException Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/dca007d2 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/dca007d2 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/dca007d2 Branch: refs/heads/master Commit: dca007d2226649a55bd3ee512580ca63d7354e56 Parents: fe27e8e Author: Ray DeCampo Authored: Sun Jan 29 10:14:14 2017 -0500 Committer: Ray DeCampo Committed: Sun Jan 29 10:14:14 2017 -0500 -- .../commons/numbers/core/ArithmeticUtils.java | 83 ++-- .../core/NumbersArithmeticException.java| 54 - .../numbers/core/ArithmeticUtilsTest.java | 52 ++-- .../commons/numbers/fraction/Fraction.java | 12 +-- .../numbers/fraction/FractionException.java | 9 +-- .../numbers/fraction/BigFractionTest.java | 5 +- .../commons/numbers/fraction/FractionTest.java | 51 ++-- 7 files changed, 117 insertions(+), 149 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java index 4f1d6cf..ee502ca 100644 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -17,6 +17,7 @@ package org.apache.commons.numbers.core; import java.math.BigInteger; +import java.text.MessageFormat; /** * Some useful, arithmetics related, additions to the built-in functions in @@ -36,11 +37,11 @@ public final class ArithmeticUtils { * @param x an addend * @param y an addend * @return the sum {@code x+y} - * @throws NumbersArithmeticException if the result can not be represented + * @throws ArithmeticException if the result can not be represented * as an {@code int}. */ public static int addAndCheck(int x, int y) -throws NumbersArithmeticException { +throws ArithmeticException { long s = (long)x + (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { throw new NumbersArithmeticException("overflow in addition: {0} + {1}", x, y); @@ -54,9 +55,9 @@ public final class ArithmeticUtils { * @param a an addend * @param b an addend * @return the sum {@code a+b} - * @throws NumbersArithmeticException if the result can not be represented as an long + * @throws ArithmeticException if the result can not be represented as an long */ -public static long addAndCheck(long a, long b) throws NumbersArithmeticException { +public static long addAndCheck(long a, long b) throws ArithmeticException { return addAndCheck(a, b, "overflow in addition: {0} + {1}"); } @@ -84,10 +85,10 @@ public final class ArithmeticUtils { * @param p Number. * @param q Number. * @return the greatest common divisor (never negative). - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ -public static int gcd(int p, int q) throws NumbersArithmeticException { +public static int gcd(int p, int q) throws ArithmeticException { int a = p; int b = q; if (a == 0 || @@ -223,10 +224,10 @@ public final class ArithmeticUtils { * @param p Number. * @param q Number. * @return the greatest common divisor, never negative. - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code long} value. */ -public static long gcd(final long p, final long q) throws NumbersArithmeticException { +public static long gcd(final long p, final long q) throws ArithmeticException { long u = p; long v = q; if ((u == 0) || (v == 0)) { @@ -302,10 +303,10 @@ public final class ArithmeticUtils { * @param a Number. * @param b Number. * @return the least common multiple, never negative. - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@co
[08/13] commons-numbers git commit: NUMBERS-6: Remove specialized exception from public API. FractionException becomes package private and inherits from java.lang.ArithmeticException. Subclasses of Fr
NUMBERS-6: Remove specialized exception from public API. FractionException becomes package private and inherits from java.lang.ArithmeticException. Subclasses of FractionException are eliminated. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/41e2f65b Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/41e2f65b Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/41e2f65b Branch: refs/heads/master Commit: 41e2f65b34c978f4377b2f043fec28a61402962d Parents: fbb60fb Author: Ray DeCampo Authored: Tue Jan 31 20:19:35 2017 -0500 Committer: Ray DeCampo Committed: Tue Jan 31 20:19:35 2017 -0500 -- .../commons/numbers/fraction/BigFraction.java | 21 .../commons/numbers/fraction/Fraction.java | 42 +++- .../fraction/FractionConversionException.java | 49 -- .../numbers/fraction/FractionException.java | 7 ++- .../numbers/fraction/FractionFormat.java| 4 +- .../fraction/FractionOverflowException.java | 47 - .../fraction/FractionParseException.java| 9 +++- .../fraction/ZeroDenominatorException.java | 53 .../numbers/fraction/BigFractionFormatTest.java | 12 ++--- .../numbers/fraction/BigFractionTest.java | 22 .../numbers/fraction/FractionFormatTest.java| 16 +++--- .../commons/numbers/fraction/FractionTest.java | 20 12 files changed, 78 insertions(+), 224 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index 4ba8e01..a5ab6f7 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -108,7 +108,7 @@ public class BigFraction checkNotNull(num, "numerator"); checkNotNull(den, "denominator"); if (den.signum() == 0) { -throw new ZeroDenominatorException(); +throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR); } if (num.signum() == 0) { numerator = BigInteger.ZERO; @@ -214,8 +214,7 @@ public class BigFraction * @see #BigFraction(double) */ public BigFraction(final double value, final double epsilon, - final int maxIterations) -throws FractionConversionException { + final int maxIterations) { this(value, epsilon, Integer.MAX_VALUE, maxIterations); } @@ -254,14 +253,13 @@ public class BigFraction * if the continued fraction failed to converge. */ private BigFraction(final double value, final double epsilon, -final int maxDenominator, int maxIterations) -throws FractionConversionException { +final int maxDenominator, int maxIterations) { long overflow = Integer.MAX_VALUE; double r0 = value; long a0 = (long) Math.floor(r0); if (Math.abs(a0) > overflow) { -throw new FractionConversionException(value, a0, 1l); +throw new FractionException(FractionException.ERROR_CONVERSION_OVERFLOW, value, a0, 1l); } // check for (almost) integer arguments, which should not go @@ -294,7 +292,7 @@ public class BigFraction if (epsilon == 0.0 && Math.abs(q1) < maxDenominator) { break; } -throw new FractionConversionException(value, p2, q2); +throw new FractionException(FractionException.ERROR_CONVERSION_OVERFLOW, value, p2, q2); } final double convergent = (double) p2 / (double) q2; @@ -313,7 +311,7 @@ public class BigFraction } while (!stop); if (n >= maxIterations) { -throw new FractionConversionException(value, maxIterations); +throw new FractionException(FractionException.ERROR_CONVERSION, value, maxIterations); } if (q2 < maxDenominator) { @@ -342,8 +340,7 @@ public class BigFraction * @throws FractionConversionException * if the continued fraction failed to converge. */ -public BigFraction(final double value, final int maxDenominator) -throws FractionConversionException { +public BigFraction(final double value, final int maxDe
[09/13] commons-numbers git commit: NUMBERS-6: Remove specialized exception from public API (contd). FractionParseException becomes package private and inherits from java.text.ParseException.
NUMBERS-6: Remove specialized exception from public API (contd). FractionParseException becomes package private and inherits from java.text.ParseException. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/ec826b0f Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/ec826b0f Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/ec826b0f Branch: refs/heads/master Commit: ec826b0fc1ae6d731d3b848cf9f60f676c4bc261 Parents: 41e2f65 Author: Ray DeCampo Authored: Tue Jan 31 20:26:59 2017 -0500 Committer: Ray DeCampo Committed: Tue Jan 31 20:26:59 2017 -0500 -- .../numbers/fraction/BigFractionFormat.java | 5 +++-- .../commons/numbers/fraction/Fraction.java | 4 ++-- .../numbers/fraction/FractionException.java | 17 - .../commons/numbers/fraction/FractionFormat.java | 5 +++-- .../numbers/fraction/FractionParseException.java | 2 +- .../numbers/fraction/BigFractionFormatTest.java | 17 + .../numbers/fraction/FractionFormatTest.java | 19 ++- 7 files changed, 44 insertions(+), 25 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java index aca674c..822e6a2 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionFormat.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.math.BigInteger; import java.text.FieldPosition; import java.text.NumberFormat; +import java.text.ParseException; import java.text.ParsePosition; import java.util.Locale; @@ -177,11 +178,11 @@ public class BigFractionFormat extends AbstractFormat implements Serializable { * Parses a string to produce a {@link BigFraction} object. * @param source the string to parse * @return the parsed {@link BigFraction} object. - * @exception FractionParseException if the beginning of the specified string + * @exception ParseException if the beginning of the specified string *cannot be parsed. */ @Override -public BigFraction parse(final String source) throws FractionParseException { +public BigFraction parse(final String source) throws ParseException { final ParsePosition parsePosition = new ParsePosition(0); final BigFraction result = parse(source, parsePosition); if (parsePosition.getIndex() == 0) { http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java index 31abd17..bfd7734 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java @@ -257,7 +257,7 @@ public class Fraction if (den < 0) { if (num == Integer.MIN_VALUE || den == Integer.MIN_VALUE) { -throw new FractionException("overflow in fraction {0}/{1}, cannot negate", num, den); +throw new FractionException(FractionException.ERROR_NEGATION_OVERFLOW, num, den); } num = -num; den = -den; @@ -617,7 +617,7 @@ public class Fraction if (denominator < 0) { if (numerator==Integer.MIN_VALUE || denominator==Integer.MIN_VALUE) { -throw new FractionException("overflow in fraction {0}/{1}, cannot negate", numerator, denominator); +throw new FractionException(FractionException.ERROR_NEGATION_OVERFLOW, numerator, denominator); } numerator = -numerator; denominator = -denominator; http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ec826b0f/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fracti
[12/13] commons-numbers git commit: NUMBERS-6: Fix checkstyle issues.
NUMBERS-6: Fix checkstyle issues. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/985d44fc Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/985d44fc Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/985d44fc Branch: refs/heads/master Commit: 985d44fca746154042730c3b2743678f5df934ae Parents: 1635231 Author: Ray DeCampo Authored: Thu Feb 2 18:58:44 2017 -0500 Committer: Ray DeCampo Committed: Thu Feb 2 18:58:44 2017 -0500 -- .../commons/numbers/fraction/BigFraction.java | 32 ++-- .../commons/numbers/fraction/Fraction.java | 13 +--- .../numbers/fraction/FractionException.java | 20 ++-- .../fraction/FractionParseException.java| 2 +- 4 files changed, 42 insertions(+), 25 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/985d44fc/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index eae82ea..eab9b7f 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -77,6 +77,12 @@ public class BigFraction /** BigInteger representation of 100. */ private static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100); +/** Parameter name for fraction (to satisfy checkstyle). */ +private static final String PARAM_NAME_FRACTION = "fraction"; + +/** Parameter name for BigIntegers (to satisfy checkstyle). */ +private static final String PARAM_NAME_BG = "bg"; + /** The numerator. */ private final BigInteger numerator; @@ -248,7 +254,7 @@ public class BigFraction *maximum denominator value allowed. * @param maxIterations *maximum number of convergents. - * @throws FractionConversionException + * @throws ArithmeticException * if the continued fraction failed to converge. */ private BigFraction(final double value, final double epsilon, @@ -446,8 +452,8 @@ public class BigFraction *the {@link BigInteger} to add, must'nt be null. * @return a BigFraction instance with the resulting values. */ -public BigFraction add(final BigInteger bg) throws NullPointerException { -checkNotNull(bg, "bg"); +public BigFraction add(final BigInteger bg) { +checkNotNull(bg, PARAM_NAME_BG); if (numerator.signum() == 0) { return new BigFraction(bg); @@ -498,7 +504,7 @@ public class BigFraction * @return a {@link BigFraction} instance with the resulting values. */ public BigFraction add(final BigFraction fraction) { -checkNotNull(fraction, "fraction"); +checkNotNull(fraction, PARAM_NAME_FRACTION); if (fraction.numerator.signum() == 0) { return this; } @@ -618,7 +624,7 @@ public class BigFraction * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigInteger bg) { -checkNotNull(bg, "bg"); +checkNotNull(bg, PARAM_NAME_BG); if (bg.signum() == 0) { throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR); } @@ -667,7 +673,7 @@ public class BigFraction * @throws ArithmeticException if the fraction to divide by is zero */ public BigFraction divide(final BigFraction fraction) { -checkNotNull(fraction, "fraction"); +checkNotNull(fraction, PARAM_NAME_FRACTION); if (fraction.numerator.signum() == 0) { throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR); } @@ -871,7 +877,7 @@ public class BigFraction * @return a {@code BigFraction} instance with the resulting values. */ public BigFraction multiply(final BigInteger bg) { -checkNotNull(bg, "bg"); +checkNotNull(bg, PARAM_NAME_BG); if (numerator.signum() == 0 || bg.signum() == 0) { return ZERO; } @@ -924,7 +930,7 @@ public class BigFraction * @return a {@link BigFraction} instance with the resulting values. */ public BigFraction multiply(final BigFraction fraction) { -checkNotNull(fraction, "fraction"); +checkNotNull(fraction, PARAM_NAME_FRACTION); if (numerator.signum() == 0 || fraction.numerator.signum() == 0) { return ZERO; @@ -
[11/13] commons-numbers git commit: NUMBERS-6: Remove Field classes and references to same
NUMBERS-6: Remove Field classes and references to same Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/16352312 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/16352312 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/16352312 Branch: refs/heads/master Commit: 16352312bac6661d4facd234f6d00dd4ed37ff58 Parents: ffe11d9 Author: Ray DeCampo Authored: Thu Feb 2 18:04:19 2017 -0500 Committer: Ray DeCampo Committed: Thu Feb 2 18:04:19 2017 -0500 -- .../commons/numbers/fraction/BigFraction.java | 6 +- .../numbers/fraction/BigFractionField.java | 82 .../commons/numbers/fraction/Fraction.java | 7 +- .../commons/numbers/fraction/FractionField.java | 81 --- .../numbers/fraction/BigFractionFieldTest.java | 43 -- .../numbers/fraction/FractionFieldTest.java | 43 -- 6 files changed, 2 insertions(+), 260 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/16352312/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java index 9d653b1..eae82ea 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java @@ -27,7 +27,7 @@ import org.apache.commons.numbers.core.ArithmeticUtils; */ public class BigFraction extends Number -implements /*FieldElement, */Comparable, Serializable { +implements Comparable, Serializable { /** A fraction representing "2 / 1". */ public static final BigFraction TWO = new BigFraction(2); @@ -1179,10 +1179,6 @@ public class BigFraction return str; } -public BigFractionField getField() { -return BigFractionField.getInstance(); -} - private static void checkNotNull(Object arg, String argName) { if (arg == null) { throw new NullPointerException(argName); http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/16352312/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java deleted file mode 100644 index 7430eaa..000 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFractionField.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.fraction; - -import java.io.Serializable; - - -/** - * Representation of the fractional numbers without any overflow field. - * - * This class is a singleton. - * - * @see Fraction - */ -public class BigFractionField implements /*Field, */Serializable { - -/** Serializable version identifier */ -private static final long serialVersionUID = -1699294557189741703L; - -/** Private constructor for the singleton. - */ -private BigFractionField() { -} - -/** Get the unique instance. - * @return the unique instance - */ -public static BigFractionField getInstance() { -return LazyHolder.INSTANCE; -} - -/** {@inheritDoc} */ -public BigFraction getOne() { -return BigFraction.ONE; -} - -/** {@inheritDoc} */ -public BigFraction getZero() { -return BigFraction.ZERO; -} - -/** {@inheritDoc} */ -/* -@Override -public Class> getRuntimeClass() { -return BigFraction.class; -} -*/ -// CHECKSTYLE: s
[04/13] commons-numbers git commit: NUMBERS-6: Create structure for fraction module within commons-numbers.
NUMBERS-6: Create structure for fraction module within commons-numbers. Add dependencyManagement to parent pom.xml for uniform dependency on numbers core. Remove version from references to numbers-core in child modules. Add test jar to numbers core pom.xml to allow for re-use of TestUtils. Add ArithmeticUtils from commons-math since Fraction, BigFraction heavily depends on it. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/ca71f355 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/ca71f355 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/ca71f355 Branch: refs/heads/master Commit: ca71f3559f3b51804dca33dc895c2b89b846f124 Parents: 4094c82 Author: Ray DeCampo Authored: Sun Jan 22 20:41:30 2017 -0500 Committer: Gilles Sadowski Committed: Sat Jan 28 16:09:10 2017 +0100 -- commons-numbers-complex/pom.xml |1 - commons-numbers-core/pom.xml| 15 + .../commons/numbers/core/ArithmeticUtils.java | 772 +++ .../core/NumbersArithmeticException.java| 54 + .../numbers/core/ArithmeticUtilsTest.java | 782 commons-numbers-fraction/LICENSE.txt| 201 +++ commons-numbers-fraction/NOTICE.txt |6 + commons-numbers-fraction/README.md | 98 ++ commons-numbers-fraction/pom.xml| 58 + .../numbers/fraction/AbstractFormat.java| 206 +++ .../commons/numbers/fraction/BigFraction.java | 1199 ++ .../numbers/fraction/BigFractionField.java | 83 ++ .../numbers/fraction/BigFractionFormat.java | 283 + .../commons/numbers/fraction/Fraction.java | 664 ++ .../fraction/FractionConversionException.java | 51 + .../numbers/fraction/FractionException.java | 44 + .../commons/numbers/fraction/FractionField.java | 82 ++ .../numbers/fraction/FractionFormat.java| 261 .../fraction/FractionOverflowException.java | 47 + .../fraction/FractionParseException.java| 38 + .../fraction/ProperBigFractionFormat.java | 235 .../numbers/fraction/ProperFractionFormat.java | 227 .../fraction/ZeroDenominatorException.java | 53 + .../commons/numbers/fraction/package-info.java | 22 + .../numbers/fraction/BigFractionFieldTest.java | 43 + .../numbers/fraction/BigFractionFormatTest.java | 330 + .../numbers/fraction/BigFractionTest.java | 635 ++ .../numbers/fraction/FractionFieldTest.java | 43 + .../numbers/fraction/FractionFormatTest.java| 349 + .../commons/numbers/fraction/FractionTest.java | 625 + commons-numbers-quaternion/pom.xml |1 - pom.xml | 20 +- 32 files changed, 7525 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ca71f355/commons-numbers-complex/pom.xml -- diff --git a/commons-numbers-complex/pom.xml b/commons-numbers-complex/pom.xml index 735348f..3fec4ba 100644 --- a/commons-numbers-complex/pom.xml +++ b/commons-numbers-complex/pom.xml @@ -46,7 +46,6 @@ org.apache.commons commons-numbers-core - 1.0-SNAPSHOT http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ca71f355/commons-numbers-core/pom.xml -- diff --git a/commons-numbers-core/pom.xml b/commons-numbers-core/pom.xml index 39dbdcb..76c2512 100644 --- a/commons-numbers-core/pom.xml +++ b/commons-numbers-core/pom.xml @@ -42,5 +42,20 @@ ${basedir}/.. + + + +org.apache.maven.plugins +maven-jar-plugin + + + + test-jar + + + + + + http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/ca71f355/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java -- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java new file mode 100644 index 000..343d24b --- /dev/null +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -0,0 +1,772 @@ +/* + * 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
[13/13] commons-numbers git commit: Merge branch 'fraction__NUMBERS-6' Copy fraction code from commons-math into commons-numbers
Merge branch 'fraction__NUMBERS-6' Copy fraction code from commons-math into commons-numbers Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/39b5119c Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/39b5119c Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/39b5119c Branch: refs/heads/master Commit: 39b5119cc153a910152c19addf6f2d750531da53 Parents: 2376972 985d44f Author: Ray DeCampo Authored: Mon Feb 6 07:47:12 2017 -0500 Committer: Ray DeCampo Committed: Mon Feb 6 07:47:12 2017 -0500 -- commons-numbers-complex/pom.xml |1 - commons-numbers-core/pom.xml| 15 + .../commons/numbers/core/ArithmeticUtils.java | 781 .../numbers/core/ArithmeticUtilsTest.java | 782 commons-numbers-fraction/LICENSE.txt| 201 +++ commons-numbers-fraction/NOTICE.txt |6 + commons-numbers-fraction/README.md | 98 ++ commons-numbers-fraction/pom.xml| 58 + .../numbers/fraction/AbstractFormat.java| 205 +++ .../commons/numbers/fraction/BigFraction.java | 1200 ++ .../numbers/fraction/BigFractionFormat.java | 282 .../commons/numbers/fraction/Fraction.java | 656 ++ .../numbers/fraction/FractionException.java | 59 + .../numbers/fraction/FractionFormat.java| 260 .../fraction/FractionParseException.java| 43 + .../fraction/ProperBigFractionFormat.java | 233 .../numbers/fraction/ProperFractionFormat.java | 225 .../commons/numbers/fraction/package-info.java | 22 + .../numbers/fraction/BigFractionFormatTest.java | 331 + .../numbers/fraction/BigFractionTest.java | 634 + .../numbers/fraction/FractionFormatTest.java| 350 + .../commons/numbers/fraction/FractionTest.java | 624 + commons-numbers-quaternion/pom.xml |1 - pom.xml | 20 +- 24 files changed, 7084 insertions(+), 3 deletions(-) --
[1/2] commons-numbers git commit: Establish baseline of files copied from commons-math. (Will not build.)
Repository: commons-numbers Updated Branches: refs/heads/feature-NUMBERS-12 [created] 44fa5ca2b Establish baseline of files copied from commons-math. (Will not build.) Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/c4cae1c2 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/c4cae1c2 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/c4cae1c2 Branch: refs/heads/feature-NUMBERS-12 Commit: c4cae1c29e8afe249896cc096f6977da0950e1c8 Parents: e2668df Author: Ray DeCampo Authored: Sat Apr 15 12:03:24 2017 -0400 Committer: Ray DeCampo Committed: Sat Apr 15 12:03:24 2017 -0400 -- .../numbers/fraction/ContinuedFraction.java | 181 +++ .../numbers/fraction/ContinuedFractionTest.java | 46 + 2 files changed, 227 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/c4cae1c2/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java new file mode 100644 index 000..56b7267 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -0,0 +1,181 @@ +/* + * 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.math4.util; + +import org.apache.commons.math4.exception.ConvergenceException; +import org.apache.commons.math4.exception.MaxCountExceededException; +import org.apache.commons.math4.exception.util.LocalizedFormats; + +/** + * Provides a generic means to evaluate continued fractions. Subclasses simply + * provided the a and b coefficients to evaluate the continued fraction. + * + * + * References: + * + * http://mathworld.wolfram.com/ContinuedFraction.html";> + * Continued Fraction + * + * + * + */ +public abstract class ContinuedFraction { +/** Maximum allowed numerical error. */ +private static final double DEFAULT_EPSILON = 10e-9; + +/** + * Default constructor. + */ +protected ContinuedFraction() { +super(); +} + +/** + * Access the n-th a coefficient of the continued fraction. Since a can be + * a function of the evaluation point, x, that is passed in as well. + * @param n the coefficient index to retrieve. + * @param x the evaluation point. + * @return the n-th a coefficient. + */ +protected abstract double getA(int n, double x); + +/** + * Access the n-th b coefficient of the continued fraction. Since b can be + * a function of the evaluation point, x, that is passed in as well. + * @param n the coefficient index to retrieve. + * @param x the evaluation point. + * @return the n-th b coefficient. + */ +protected abstract double getB(int n, double x); + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @return the value of the continued fraction evaluated at x. + * @throws ConvergenceException if the algorithm fails to converge. + */ +public double evaluate(double x) throws ConvergenceException { +return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE); +} + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @param epsilon maximum error allowed. + * @return the value of the continued fraction evaluated at x. + * @throws ConvergenceException if the algorithm fails to converge. + */ +public double evaluate(double x, double epsilon) throws ConvergenceException { +return evaluate(x, epsilon, Integer.MAX_VALUE); +} + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @param maxIterations maximum number of converge
[2/2] commons-numbers git commit: Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException.
Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/44fa5ca2 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/44fa5ca2 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/44fa5ca2 Branch: refs/heads/feature-NUMBERS-12 Commit: 44fa5ca2be1b213b91465cc36d3b803dc68fed83 Parents: c4cae1c Author: Ray DeCampo Authored: Sat Apr 15 12:26:48 2017 -0400 Committer: Ray DeCampo Committed: Sat Apr 15 12:26:48 2017 -0400 -- .../numbers/fraction/ContinuedFraction.java | 37 +--- .../numbers/fraction/ContinuedFractionTest.java | 3 +- 2 files changed, 17 insertions(+), 23 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/44fa5ca2/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java index 56b7267..7608c2a 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -14,11 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.util; +package org.apache.commons.numbers.fraction; -import org.apache.commons.math4.exception.ConvergenceException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.util.LocalizedFormats; +import org.apache.commons.numbers.core.Precision; /** * Provides a generic means to evaluate continued fractions. Subclasses simply @@ -66,9 +64,9 @@ public abstract class ContinuedFraction { * Evaluates the continued fraction at the value x. * @param x the evaluation point. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ -public double evaluate(double x) throws ConvergenceException { +public double evaluate(double x) { return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE); } @@ -77,9 +75,9 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param epsilon maximum error allowed. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ -public double evaluate(double x, double epsilon) throws ConvergenceException { +public double evaluate(double x, double epsilon) { return evaluate(x, epsilon, Integer.MAX_VALUE); } @@ -88,11 +86,10 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ -public double evaluate(double x, int maxIterations) -throws ConvergenceException, MaxCountExceededException { +public double evaluate(double x, int maxIterations) { return evaluate(x, DEFAULT_EPSILON, maxIterations); } @@ -116,11 +113,10 @@ public abstract class ContinuedFraction { * @param epsilon maximum error allowed. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ -public double evaluate(double x, double epsilon, int maxIterations) -throws ConvergenceException, MaxCountExceededException { +public double evaluate(double x, double epsilon, int maxIterations) { final double small = 1e-50; double hPrev = getA(0, x); @@ -152,15 +148,15 @@
[commons-numbers] Git Push Summary
Repository: commons-numbers Updated Branches: refs/heads/feature-NUMBERS-12 [deleted] 44fa5ca2b
[3/3] commons-numbers git commit: Remove unnecessary default constructor
Remove unnecessary default constructor Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/e3399d1b Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/e3399d1b Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/e3399d1b Branch: refs/heads/feature-NUMBERS-12 Commit: e3399d1bab7065bdad7ebac80db184b5ef758808 Parents: 9602e36 Author: Ray DeCampo Authored: Thu Apr 20 06:36:51 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 06:36:51 2017 -0400 -- .../apache/commons/numbers/fraction/ContinuedFraction.java| 7 --- 1 file changed, 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/e3399d1b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java index 7608c2a..a2e38a7 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -36,13 +36,6 @@ public abstract class ContinuedFraction { private static final double DEFAULT_EPSILON = 10e-9; /** - * Default constructor. - */ -protected ContinuedFraction() { -super(); -} - -/** * Access the n-th a coefficient of the continued fraction. Since a can be * a function of the evaluation point, x, that is passed in as well. * @param n the coefficient index to retrieve.
[2/3] commons-numbers git commit: Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException.
Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/9602e36b Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/9602e36b Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/9602e36b Branch: refs/heads/feature-NUMBERS-12 Commit: 9602e36b262f41036c3204b55f1addb91769573f Parents: 4e1339e Author: Ray DeCampo Authored: Thu Apr 20 06:34:15 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 06:34:15 2017 -0400 -- .../numbers/fraction/ContinuedFraction.java | 37 +--- .../numbers/fraction/ContinuedFractionTest.java | 3 +- 2 files changed, 17 insertions(+), 23 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/9602e36b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java index 56b7267..7608c2a 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -14,11 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.util; +package org.apache.commons.numbers.fraction; -import org.apache.commons.math4.exception.ConvergenceException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.util.LocalizedFormats; +import org.apache.commons.numbers.core.Precision; /** * Provides a generic means to evaluate continued fractions. Subclasses simply @@ -66,9 +64,9 @@ public abstract class ContinuedFraction { * Evaluates the continued fraction at the value x. * @param x the evaluation point. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ -public double evaluate(double x) throws ConvergenceException { +public double evaluate(double x) { return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE); } @@ -77,9 +75,9 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param epsilon maximum error allowed. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ -public double evaluate(double x, double epsilon) throws ConvergenceException { +public double evaluate(double x, double epsilon) { return evaluate(x, epsilon, Integer.MAX_VALUE); } @@ -88,11 +86,10 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ -public double evaluate(double x, int maxIterations) -throws ConvergenceException, MaxCountExceededException { +public double evaluate(double x, int maxIterations) { return evaluate(x, DEFAULT_EPSILON, maxIterations); } @@ -116,11 +113,10 @@ public abstract class ContinuedFraction { * @param epsilon maximum error allowed. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ -public double evaluate(double x, double epsilon, int maxIterations) -throws ConvergenceException, MaxCountExceededException { +public double evaluate(double x, double epsilon, int maxIterations) { final double small = 1e-50; double hPrev = getA(0, x); @@ -152,15 +148,15 @@
[1/3] commons-numbers git commit: Establish baseline of files copied from commons-math. (Will not build.)
Repository: commons-numbers Updated Branches: refs/heads/feature-NUMBERS-12 [created] e3399d1ba Establish baseline of files copied from commons-math. (Will not build.) Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/4e1339ee Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/4e1339ee Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/4e1339ee Branch: refs/heads/feature-NUMBERS-12 Commit: 4e1339eec8f100236f7aac310f797f87c986b47e Parents: b37c9f1 Author: Ray DeCampo Authored: Thu Apr 20 06:30:11 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 06:30:11 2017 -0400 -- .../numbers/fraction/ContinuedFraction.java | 181 +++ .../numbers/fraction/ContinuedFractionTest.java | 46 + 2 files changed, 227 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/4e1339ee/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java new file mode 100644 index 000..56b7267 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -0,0 +1,181 @@ +/* + * 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.math4.util; + +import org.apache.commons.math4.exception.ConvergenceException; +import org.apache.commons.math4.exception.MaxCountExceededException; +import org.apache.commons.math4.exception.util.LocalizedFormats; + +/** + * Provides a generic means to evaluate continued fractions. Subclasses simply + * provided the a and b coefficients to evaluate the continued fraction. + * + * + * References: + * + * http://mathworld.wolfram.com/ContinuedFraction.html";> + * Continued Fraction + * + * + * + */ +public abstract class ContinuedFraction { +/** Maximum allowed numerical error. */ +private static final double DEFAULT_EPSILON = 10e-9; + +/** + * Default constructor. + */ +protected ContinuedFraction() { +super(); +} + +/** + * Access the n-th a coefficient of the continued fraction. Since a can be + * a function of the evaluation point, x, that is passed in as well. + * @param n the coefficient index to retrieve. + * @param x the evaluation point. + * @return the n-th a coefficient. + */ +protected abstract double getA(int n, double x); + +/** + * Access the n-th b coefficient of the continued fraction. Since b can be + * a function of the evaluation point, x, that is passed in as well. + * @param n the coefficient index to retrieve. + * @param x the evaluation point. + * @return the n-th b coefficient. + */ +protected abstract double getB(int n, double x); + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @return the value of the continued fraction evaluated at x. + * @throws ConvergenceException if the algorithm fails to converge. + */ +public double evaluate(double x) throws ConvergenceException { +return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE); +} + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @param epsilon maximum error allowed. + * @return the value of the continued fraction evaluated at x. + * @throws ConvergenceException if the algorithm fails to converge. + */ +public double evaluate(double x, double epsilon) throws ConvergenceException { +return evaluate(x, epsilon, Integer.MAX_VALUE); +} + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @param maxIterations maximum number of converge
[3/4] commons-numbers git commit: Remove unnecessary default constructor
Remove unnecessary default constructor Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/e3399d1b Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/e3399d1b Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/e3399d1b Branch: refs/heads/master Commit: e3399d1bab7065bdad7ebac80db184b5ef758808 Parents: 9602e36 Author: Ray DeCampo Authored: Thu Apr 20 06:36:51 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 06:36:51 2017 -0400 -- .../apache/commons/numbers/fraction/ContinuedFraction.java| 7 --- 1 file changed, 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/e3399d1b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java index 7608c2a..a2e38a7 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -36,13 +36,6 @@ public abstract class ContinuedFraction { private static final double DEFAULT_EPSILON = 10e-9; /** - * Default constructor. - */ -protected ContinuedFraction() { -super(); -} - -/** * Access the n-th a coefficient of the continued fraction. Since a can be * a function of the evaluation point, x, that is passed in as well. * @param n the coefficient index to retrieve.
[4/4] commons-numbers git commit: NUMBERS-12: Merge branch 'feature-NUMBERS-12'
NUMBERS-12: Merge branch 'feature-NUMBERS-12' Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/48c9522d Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/48c9522d Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/48c9522d Branch: refs/heads/master Commit: 48c9522d8c835a4f6647c4bb044bb2bffc7986c3 Parents: b37c9f1 e3399d1 Author: Ray DeCampo Authored: Thu Apr 20 06:40:29 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 06:40:29 2017 -0400 -- .../numbers/fraction/ContinuedFraction.java | 169 +++ .../numbers/fraction/ContinuedFractionTest.java | 45 + 2 files changed, 214 insertions(+) --
[2/4] commons-numbers git commit: Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException.
Port ContinuedFraction from commons math. Converted exceptions to ArithmeticException. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/9602e36b Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/9602e36b Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/9602e36b Branch: refs/heads/master Commit: 9602e36b262f41036c3204b55f1addb91769573f Parents: 4e1339e Author: Ray DeCampo Authored: Thu Apr 20 06:34:15 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 06:34:15 2017 -0400 -- .../numbers/fraction/ContinuedFraction.java | 37 +--- .../numbers/fraction/ContinuedFractionTest.java | 3 +- 2 files changed, 17 insertions(+), 23 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/9602e36b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java index 56b7267..7608c2a 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -14,11 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.util; +package org.apache.commons.numbers.fraction; -import org.apache.commons.math4.exception.ConvergenceException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.util.LocalizedFormats; +import org.apache.commons.numbers.core.Precision; /** * Provides a generic means to evaluate continued fractions. Subclasses simply @@ -66,9 +64,9 @@ public abstract class ContinuedFraction { * Evaluates the continued fraction at the value x. * @param x the evaluation point. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ -public double evaluate(double x) throws ConvergenceException { +public double evaluate(double x) { return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE); } @@ -77,9 +75,9 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param epsilon maximum error allowed. * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. + * @throws ArithmeticException if the algorithm fails to converge. */ -public double evaluate(double x, double epsilon) throws ConvergenceException { +public double evaluate(double x, double epsilon) { return evaluate(x, epsilon, Integer.MAX_VALUE); } @@ -88,11 +86,10 @@ public abstract class ContinuedFraction { * @param x the evaluation point. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ -public double evaluate(double x, int maxIterations) -throws ConvergenceException, MaxCountExceededException { +public double evaluate(double x, int maxIterations) { return evaluate(x, DEFAULT_EPSILON, maxIterations); } @@ -116,11 +113,10 @@ public abstract class ContinuedFraction { * @param epsilon maximum error allowed. * @param maxIterations maximum number of convergents * @return the value of the continued fraction evaluated at x. - * @throws ConvergenceException if the algorithm fails to converge. - * @throws MaxCountExceededException if maximal number of iterations is reached + * @throws ArithmeticException if the algorithm fails to converge. + * @throws ArithmeticException if maximal number of iterations is reached */ -public double evaluate(double x, double epsilon, int maxIterations) -throws ConvergenceException, MaxCountExceededException { +public double evaluate(double x, double epsilon, int maxIterations) { final double small = 1e-50; double hPrev = getA(0, x); @@ -152,15 +148,15 @@ public abst
[1/4] commons-numbers git commit: Establish baseline of files copied from commons-math. (Will not build.)
Repository: commons-numbers Updated Branches: refs/heads/master b37c9f195 -> 48c9522d8 Establish baseline of files copied from commons-math. (Will not build.) Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/4e1339ee Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/4e1339ee Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/4e1339ee Branch: refs/heads/master Commit: 4e1339eec8f100236f7aac310f797f87c986b47e Parents: b37c9f1 Author: Ray DeCampo Authored: Thu Apr 20 06:30:11 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 06:30:11 2017 -0400 -- .../numbers/fraction/ContinuedFraction.java | 181 +++ .../numbers/fraction/ContinuedFractionTest.java | 46 + 2 files changed, 227 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/4e1339ee/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java -- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java new file mode 100644 index 000..56b7267 --- /dev/null +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ContinuedFraction.java @@ -0,0 +1,181 @@ +/* + * 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.math4.util; + +import org.apache.commons.math4.exception.ConvergenceException; +import org.apache.commons.math4.exception.MaxCountExceededException; +import org.apache.commons.math4.exception.util.LocalizedFormats; + +/** + * Provides a generic means to evaluate continued fractions. Subclasses simply + * provided the a and b coefficients to evaluate the continued fraction. + * + * + * References: + * + * http://mathworld.wolfram.com/ContinuedFraction.html";> + * Continued Fraction + * + * + * + */ +public abstract class ContinuedFraction { +/** Maximum allowed numerical error. */ +private static final double DEFAULT_EPSILON = 10e-9; + +/** + * Default constructor. + */ +protected ContinuedFraction() { +super(); +} + +/** + * Access the n-th a coefficient of the continued fraction. Since a can be + * a function of the evaluation point, x, that is passed in as well. + * @param n the coefficient index to retrieve. + * @param x the evaluation point. + * @return the n-th a coefficient. + */ +protected abstract double getA(int n, double x); + +/** + * Access the n-th b coefficient of the continued fraction. Since b can be + * a function of the evaluation point, x, that is passed in as well. + * @param n the coefficient index to retrieve. + * @param x the evaluation point. + * @return the n-th b coefficient. + */ +protected abstract double getB(int n, double x); + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @return the value of the continued fraction evaluated at x. + * @throws ConvergenceException if the algorithm fails to converge. + */ +public double evaluate(double x) throws ConvergenceException { +return evaluate(x, DEFAULT_EPSILON, Integer.MAX_VALUE); +} + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @param epsilon maximum error allowed. + * @return the value of the continued fraction evaluated at x. + * @throws ConvergenceException if the algorithm fails to converge. + */ +public double evaluate(double x, double epsilon) throws ConvergenceException { +return evaluate(x, epsilon, Integer.MAX_VALUE); +} + +/** + * Evaluates the continued fraction at the value x. + * @param x the evaluation point. + * @param maxIterations maximum number of convergents + * @return t
[commons-numbers] Git Push Summary
Repository: commons-numbers Updated Branches: refs/heads/feature-NUMBERS-12 [deleted] e3399d1ba
[commons-numbers] Git Push Summary
Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 [deleted] 985d44fca
[2/3] commons-numbers git commit: NUMBERS-20: Port classes to new package. Replace [math] exceptions with IllegalArgumentException. Simplify exception detection in unit tests.
NUMBERS-20: Port classes to new package. Replace [math] exceptions with IllegalArgumentException. Simplify exception detection in unit tests. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/09dc0163 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/09dc0163 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/09dc0163 Branch: refs/heads/feature-NUMBERS-20 Commit: 09dc0163ea14b0bb247d8a4fd0ea17dac9938fa2 Parents: 996a3a4 Author: Ray DeCampo Authored: Sun Apr 16 13:33:16 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 18:24:13 2017 -0400 -- commons-numbers-primes/pom.xml | 45 .../apache/commons/numbers/primes/Primes.java | 21 + .../commons/numbers/primes/SmallPrimes.java | 8 ++-- .../commons/numbers/primes/package-info.java| 2 +- .../commons/numbers/primes/PrimesTest.java | 35 ++- pom.xml | 1 + 6 files changed, 75 insertions(+), 37 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/09dc0163/commons-numbers-primes/pom.xml -- diff --git a/commons-numbers-primes/pom.xml b/commons-numbers-primes/pom.xml new file mode 100644 index 000..758afa3 --- /dev/null +++ b/commons-numbers-primes/pom.xml @@ -0,0 +1,45 @@ + + +http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"; + xmlns="http://maven.apache.org/POM/4.0.0"; + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";> + 4.0.0 + + +org.apache.commons +commons-numbers-parent +1.0-SNAPSHOT + + + org.apache.commons + commons-numbers-primes + 1.0-SNAPSHOT + Apache Commons Numbers Primes + + Utilities related to prime numbers. + + + + org.apache.commons.numbers.primes + + org.apache.commons.numbers.primes + +${basedir}/.. + + + http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/09dc0163/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java -- diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java index db75ccc..b47461e 100644 --- a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java +++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java @@ -14,11 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.primes; - -import org.apache.commons.math4.exception.MathIllegalArgumentException; -import org.apache.commons.math4.exception.util.LocalizedFormats; +package org.apache.commons.numbers.primes; +import java.text.MessageFormat; import java.util.List; @@ -30,10 +28,13 @@ import java.util.List; * factorization * * - * @since 3.2 + * @since 1.0 */ public class Primes { +/** Exception message format when an argument is too small. */ +static final String NUMBER_TOO_SMALL = "{0} is smaller than the minimum ({1})"; + /** * Hide utility class. */ @@ -68,11 +69,12 @@ public class Primes { * * @param n a positive number. * @return the smallest prime greater than or equal to n. - * @throws MathIllegalArgumentException if n < 0. + * @throws IllegalArgumentException if n < 0. */ public static int nextPrime(int n) { if (n < 0) { -throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 0); +throw new IllegalArgumentException( +MessageFormat.format(NUMBER_TOO_SMALL, n, 0)); } if (n == 2) { return 2; @@ -112,12 +114,13 @@ public class Primes { * * @param n number to factorize: must be ≥ 2 * @return list of prime factors of n - * @throws MathIllegalArgumentException if n < 2. + * @throws IllegalArgumentException if n < 2. */ public static List primeFactors(int n) { if (n < 2) { -throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2); +throw new IllegalArgumentException( +MessageFormat.format(NUMBER_TOO_SMALL, n, 2)); } return SmallPrimes.trialDivision(n); http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/09dc0163/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java -- diff --git a/commons-numbers-p
[1/3] commons-numbers git commit: NUMBERS-20: Establish baseline of files copied from [math].
Repository: commons-numbers Updated Branches: refs/heads/feature-NUMBERS-20 [created] 9e54e498d NUMBERS-20: Establish baseline of files copied from [math]. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/996a3a45 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/996a3a45 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/996a3a45 Branch: refs/heads/feature-NUMBERS-20 Commit: 996a3a45d5dc92383064594a950b23667df56f21 Parents: b37c9f1 Author: Ray DeCampo Authored: Sun Apr 16 13:04:34 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 18:23:48 2017 -0400 -- .../apache/commons/numbers/primes/Primes.java | 126 + .../commons/numbers/primes/SmallPrimes.java | 188 +++ .../commons/numbers/primes/package-info.java| 20 ++ .../commons/numbers/primes/PrimesTest.java | 174 + 4 files changed, 508 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/996a3a45/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java -- diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java new file mode 100644 index 000..db75ccc --- /dev/null +++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java @@ -0,0 +1,126 @@ +/* + * 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.math4.primes; + +import org.apache.commons.math4.exception.MathIllegalArgumentException; +import org.apache.commons.math4.exception.util.LocalizedFormats; + +import java.util.List; + + +/** + * Methods related to prime numbers in the range of int: + * + * primality test + * prime number generation + * factorization + * + * + * @since 3.2 + */ +public class Primes { + +/** + * Hide utility class. + */ +private Primes() { +} + +/** + * Primality test: tells if the argument is a (provable) prime or not. + * + * It uses the Miller-Rabin probabilistic test in such a way that a result is guaranteed: + * it uses the firsts prime numbers as successive base (see Handbook of applied cryptography + * by Menezes, table 4.1). + * + * @param n number to test. + * @return true if n is prime. (All numbers < 2 return false). + */ +public static boolean isPrime(int n) { +if (n < 2) { +return false; +} + +for (int p : SmallPrimes.PRIMES) { +if (0 == (n % p)) { +return n == p; +} +} +return SmallPrimes.millerRabinPrimeTest(n); +} + +/** + * Return the smallest prime greater than or equal to n. + * + * @param n a positive number. + * @return the smallest prime greater than or equal to n. + * @throws MathIllegalArgumentException if n < 0. + */ +public static int nextPrime(int n) { +if (n < 0) { +throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 0); +} +if (n == 2) { +return 2; +} +n |= 1;//make sure n is odd +if (n == 1) { +return 2; +} + +if (isPrime(n)) { +return n; +} + +// prepare entry in the +2, +4 loop: +// n should not be a multiple of 3 +final int rem = n % 3; +if (0 == rem) { // if n % 3 == 0 +n += 2; // n % 3 == 2 +} else if (1 == rem) { // if n % 3 == 1 +// if (isPrime(n)) return n; +n += 4; // n % 3 == 2 +} +while (true) { // this loop skips all multiple of 3 +if (isPrime(n)) { +return n; +} +n += 2; // n % 3 == 1 +if (isPrime(n)) { +return n; +} +n += 4; // n % 3 =
[3/3] commons-numbers git commit: NUMBERS-20: Add unit tests for SmallPrimes.
NUMBERS-20: Add unit tests for SmallPrimes. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/9e54e498 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/9e54e498 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/9e54e498 Branch: refs/heads/feature-NUMBERS-20 Commit: 9e54e498d16400fdfcf7930ea4f60c42a9f10c85 Parents: 09dc016 Author: Ray DeCampo Authored: Thu Apr 20 18:25:10 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 18:25:10 2017 -0400 -- .../commons/numbers/primes/SmallPrimesTest.java | 143 +++ 1 file changed, 143 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/9e54e498/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java -- diff --git a/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java b/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java new file mode 100644 index 000..4aa784b --- /dev/null +++ b/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java @@ -0,0 +1,143 @@ +/* + * 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.primes; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class SmallPrimesTest { + +// Primes larger than the small PRIMES array in SmallPrimes +private static final int[] LARGE_PRIME = {3673, 3677}; + +@Test +public void smallTrialDivision_smallComposite() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(3*7*23, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Arrays.asList(3, 7, 23), factors); +} + +@Test +public void smallTrialDivision_repeatedFactors() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(2*2*3*3*3, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Arrays.asList(2, 2, 3, 3, 3), factors); +} + +@Test +public void smallTrialDivision_oneFactor() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(59, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Collections.singletonList(59), factors); +} + +@Test +public void smallTrialDivision_BoundaryPrimes() { +final List factors = new ArrayList(); +final int penultimatePrime = SmallPrimes.PRIMES[SmallPrimes.PRIMES.length-2]; +final int result = SmallPrimes.smallTrialDivision(penultimatePrime*SmallPrimes.PRIMES_LAST, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Arrays.asList(penultimatePrime, SmallPrimes.PRIMES_LAST), factors); +} + +@Test +public void smallTrialDivision_largeComposite() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(2*5*LARGE_PRIME[0], factors); +Assert.assertEquals(LARGE_PRIME[0], result); +Assert.assertEquals(Arrays.asList(2, 5), factors); +} + +@Test +public void smallTrialDivision_noSmallPrimeFactors() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(LARGE_PRIME[0]*LARGE_PRIME[1], factors); +Assert.assertEquals(LARGE_PRIME[0]*LARGE_PRIME[1], result); +Assert.assertEquals(Collections.emptyList(), factors); +} + +@Test +public void boundedTrialDivision_twoDifferentFactors() { +final List factors = new ArrayList(); +final int result = SmallPrimes.boundedTrialDivision(LARGE_PRIME[0]*LARGE_PRIME[1], Integer.MAX_VALUE, factors); +Assert.assertEquals(LARGE_PRIME[1], result); +
[2/4] commons-numbers git commit: NUMBERS-20: Port classes to new package. Replace [math] exceptions with IllegalArgumentException. Simplify exception detection in unit tests.
NUMBERS-20: Port classes to new package. Replace [math] exceptions with IllegalArgumentException. Simplify exception detection in unit tests. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/09dc0163 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/09dc0163 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/09dc0163 Branch: refs/heads/master Commit: 09dc0163ea14b0bb247d8a4fd0ea17dac9938fa2 Parents: 996a3a4 Author: Ray DeCampo Authored: Sun Apr 16 13:33:16 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 18:24:13 2017 -0400 -- commons-numbers-primes/pom.xml | 45 .../apache/commons/numbers/primes/Primes.java | 21 + .../commons/numbers/primes/SmallPrimes.java | 8 ++-- .../commons/numbers/primes/package-info.java| 2 +- .../commons/numbers/primes/PrimesTest.java | 35 ++- pom.xml | 1 + 6 files changed, 75 insertions(+), 37 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/09dc0163/commons-numbers-primes/pom.xml -- diff --git a/commons-numbers-primes/pom.xml b/commons-numbers-primes/pom.xml new file mode 100644 index 000..758afa3 --- /dev/null +++ b/commons-numbers-primes/pom.xml @@ -0,0 +1,45 @@ + + +http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"; + xmlns="http://maven.apache.org/POM/4.0.0"; + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";> + 4.0.0 + + +org.apache.commons +commons-numbers-parent +1.0-SNAPSHOT + + + org.apache.commons + commons-numbers-primes + 1.0-SNAPSHOT + Apache Commons Numbers Primes + + Utilities related to prime numbers. + + + + org.apache.commons.numbers.primes + + org.apache.commons.numbers.primes + +${basedir}/.. + + + http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/09dc0163/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java -- diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java index db75ccc..b47461e 100644 --- a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java +++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java @@ -14,11 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.math4.primes; - -import org.apache.commons.math4.exception.MathIllegalArgumentException; -import org.apache.commons.math4.exception.util.LocalizedFormats; +package org.apache.commons.numbers.primes; +import java.text.MessageFormat; import java.util.List; @@ -30,10 +28,13 @@ import java.util.List; * factorization * * - * @since 3.2 + * @since 1.0 */ public class Primes { +/** Exception message format when an argument is too small. */ +static final String NUMBER_TOO_SMALL = "{0} is smaller than the minimum ({1})"; + /** * Hide utility class. */ @@ -68,11 +69,12 @@ public class Primes { * * @param n a positive number. * @return the smallest prime greater than or equal to n. - * @throws MathIllegalArgumentException if n < 0. + * @throws IllegalArgumentException if n < 0. */ public static int nextPrime(int n) { if (n < 0) { -throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 0); +throw new IllegalArgumentException( +MessageFormat.format(NUMBER_TOO_SMALL, n, 0)); } if (n == 2) { return 2; @@ -112,12 +114,13 @@ public class Primes { * * @param n number to factorize: must be ≥ 2 * @return list of prime factors of n - * @throws MathIllegalArgumentException if n < 2. + * @throws IllegalArgumentException if n < 2. */ public static List primeFactors(int n) { if (n < 2) { -throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2); +throw new IllegalArgumentException( +MessageFormat.format(NUMBER_TOO_SMALL, n, 2)); } return SmallPrimes.trialDivision(n); http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/09dc0163/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/SmallPrimes.java -- diff --git a/commons-numbers-primes/src/ma
[3/4] commons-numbers git commit: NUMBERS-20: Add unit tests for SmallPrimes.
NUMBERS-20: Add unit tests for SmallPrimes. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/9e54e498 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/9e54e498 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/9e54e498 Branch: refs/heads/master Commit: 9e54e498d16400fdfcf7930ea4f60c42a9f10c85 Parents: 09dc016 Author: Ray DeCampo Authored: Thu Apr 20 18:25:10 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 18:25:10 2017 -0400 -- .../commons/numbers/primes/SmallPrimesTest.java | 143 +++ 1 file changed, 143 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/9e54e498/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java -- diff --git a/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java b/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java new file mode 100644 index 000..4aa784b --- /dev/null +++ b/commons-numbers-primes/src/test/java/org/apache/commons/numbers/primes/SmallPrimesTest.java @@ -0,0 +1,143 @@ +/* + * 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.primes; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class SmallPrimesTest { + +// Primes larger than the small PRIMES array in SmallPrimes +private static final int[] LARGE_PRIME = {3673, 3677}; + +@Test +public void smallTrialDivision_smallComposite() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(3*7*23, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Arrays.asList(3, 7, 23), factors); +} + +@Test +public void smallTrialDivision_repeatedFactors() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(2*2*3*3*3, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Arrays.asList(2, 2, 3, 3, 3), factors); +} + +@Test +public void smallTrialDivision_oneFactor() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(59, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Collections.singletonList(59), factors); +} + +@Test +public void smallTrialDivision_BoundaryPrimes() { +final List factors = new ArrayList(); +final int penultimatePrime = SmallPrimes.PRIMES[SmallPrimes.PRIMES.length-2]; +final int result = SmallPrimes.smallTrialDivision(penultimatePrime*SmallPrimes.PRIMES_LAST, factors); +Assert.assertEquals(1, result); +Assert.assertEquals(Arrays.asList(penultimatePrime, SmallPrimes.PRIMES_LAST), factors); +} + +@Test +public void smallTrialDivision_largeComposite() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(2*5*LARGE_PRIME[0], factors); +Assert.assertEquals(LARGE_PRIME[0], result); +Assert.assertEquals(Arrays.asList(2, 5), factors); +} + +@Test +public void smallTrialDivision_noSmallPrimeFactors() { +final List factors = new ArrayList(); +final int result = SmallPrimes.smallTrialDivision(LARGE_PRIME[0]*LARGE_PRIME[1], factors); +Assert.assertEquals(LARGE_PRIME[0]*LARGE_PRIME[1], result); +Assert.assertEquals(Collections.emptyList(), factors); +} + +@Test +public void boundedTrialDivision_twoDifferentFactors() { +final List factors = new ArrayList(); +final int result = SmallPrimes.boundedTrialDivision(LARGE_PRIME[0]*LARGE_PRIME[1], Integer.MAX_VALUE, factors); +Assert.assertEquals(LARGE_PRIME[1], result); +Asser
[1/4] commons-numbers git commit: NUMBERS-20: Establish baseline of files copied from [math].
Repository: commons-numbers Updated Branches: refs/heads/master eed94bfe8 -> 1eaba643f NUMBERS-20: Establish baseline of files copied from [math]. Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/996a3a45 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/996a3a45 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/996a3a45 Branch: refs/heads/master Commit: 996a3a45d5dc92383064594a950b23667df56f21 Parents: b37c9f1 Author: Ray DeCampo Authored: Sun Apr 16 13:04:34 2017 -0400 Committer: Ray DeCampo Committed: Thu Apr 20 18:23:48 2017 -0400 -- .../apache/commons/numbers/primes/Primes.java | 126 + .../commons/numbers/primes/SmallPrimes.java | 188 +++ .../commons/numbers/primes/package-info.java| 20 ++ .../commons/numbers/primes/PrimesTest.java | 174 + 4 files changed, 508 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/996a3a45/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java -- diff --git a/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java new file mode 100644 index 000..db75ccc --- /dev/null +++ b/commons-numbers-primes/src/main/java/org/apache/commons/numbers/primes/Primes.java @@ -0,0 +1,126 @@ +/* + * 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.math4.primes; + +import org.apache.commons.math4.exception.MathIllegalArgumentException; +import org.apache.commons.math4.exception.util.LocalizedFormats; + +import java.util.List; + + +/** + * Methods related to prime numbers in the range of int: + * + * primality test + * prime number generation + * factorization + * + * + * @since 3.2 + */ +public class Primes { + +/** + * Hide utility class. + */ +private Primes() { +} + +/** + * Primality test: tells if the argument is a (provable) prime or not. + * + * It uses the Miller-Rabin probabilistic test in such a way that a result is guaranteed: + * it uses the firsts prime numbers as successive base (see Handbook of applied cryptography + * by Menezes, table 4.1). + * + * @param n number to test. + * @return true if n is prime. (All numbers < 2 return false). + */ +public static boolean isPrime(int n) { +if (n < 2) { +return false; +} + +for (int p : SmallPrimes.PRIMES) { +if (0 == (n % p)) { +return n == p; +} +} +return SmallPrimes.millerRabinPrimeTest(n); +} + +/** + * Return the smallest prime greater than or equal to n. + * + * @param n a positive number. + * @return the smallest prime greater than or equal to n. + * @throws MathIllegalArgumentException if n < 0. + */ +public static int nextPrime(int n) { +if (n < 0) { +throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 0); +} +if (n == 2) { +return 2; +} +n |= 1;//make sure n is odd +if (n == 1) { +return 2; +} + +if (isPrime(n)) { +return n; +} + +// prepare entry in the +2, +4 loop: +// n should not be a multiple of 3 +final int rem = n % 3; +if (0 == rem) { // if n % 3 == 0 +n += 2; // n % 3 == 2 +} else if (1 == rem) { // if n % 3 == 1 +// if (isPrime(n)) return n; +n += 4; // n % 3 == 2 +} +while (true) { // this loop skips all multiple of 3 +if (isPrime(n)) { +return n; +} +n += 2; // n % 3 == 1 +if (isPrime(n)) { +return n; +} +n += 4; // n % 3 == 2 +} +}
[4/4] commons-numbers git commit: NUMBERS-20: Merge branch 'feature-NUMBERS-20'
NUMBERS-20: Merge branch 'feature-NUMBERS-20' Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/1eaba643 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/1eaba643 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/1eaba643 Branch: refs/heads/master Commit: 1eaba643f59be9ebd2907c670f6f6cd07bbfd3f9 Parents: eed94bf 9e54e49 Author: Ray DeCampo Authored: Sun Apr 23 10:57:58 2017 -0400 Committer: Ray DeCampo Committed: Sun Apr 23 10:57:58 2017 -0400 -- commons-numbers-primes/pom.xml | 45 + .../apache/commons/numbers/primes/Primes.java | 129 + .../commons/numbers/primes/SmallPrimes.java | 186 +++ .../commons/numbers/primes/package-info.java| 20 ++ .../commons/numbers/primes/PrimesTest.java | 165 .../commons/numbers/primes/SmallPrimesTest.java | 143 ++ pom.xml | 1 + 7 files changed, 689 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/1eaba643/pom.xml --
[commons-numbers] Git Push Summary
Repository: commons-numbers Updated Branches: refs/heads/feature-NUMBERS-20 [deleted] 9e54e498d
[02/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java index 6c2ea15..41f9d77 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; -import org.apache.commons.math4.geometry.euclidean.twod.Vector2D; +import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; import org.apache.commons.math4.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -27,20 +27,20 @@ public class SegmentTest { @Test public void testDistance() { -Vector2D start = new Vector2D(2, 2); -Vector2D end = new Vector2D(-2, -2); +Coordinates2D start = new Coordinates2D(2, 2); +Coordinates2D end = new Coordinates2D(-2, -2); Segment segment = new Segment(start, end, new Line(start, end, 1.0e-10)); // distance to center of segment -Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Vector2D(1, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Coordinates2D(1, -1)), 1.0e-10); // distance a point on segment -Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Vector2D(0, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Coordinates2D(0, -1)), 1.0e-10); // distance to end point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, 4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, 4)), 1.0e-10); // distance to start point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, -4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, -4)), 1.0e-10); } } http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java index 249c5d7..c59ab8c 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Vector2D; +import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; import org.apache.commons.math4.geometry.partitioning.RegionFactory; import org.junit.Assert; import org.junit.Test; @@ -32,19 +32,19 @@ public class SubLineTest { @Test public void testEndPoints() { -Vector2D p1 = new Vector2D(-1, -7); -Vector2D p2 = new Vector2D(7, -1); +Coordinates2D p1 = new Coordinates2D(-1, -7); +Coordinates2D p2 = new Coordinates2D(7, -1); Segment segment = new Segment(p1, p2, new Line(p1, p2, 1.0e-10)); SubLine sub = new SubLine(segment); List segments = sub.getSegments(); Assert.assertEquals(1, segments.size()); -Assert.assertEquals(0.0, new Vector2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); -Assert.assertEquals(0.0, new Vector2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); +Assert.assertEquals(0.0, new Coordinates2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); +Assert.assertEquals(0.0, new Coordinates2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); } @Test public void testNoEndPoints() { -SubLine wholeLine = new Line(new Vector2D(-1, 7), new Vector2D(7, 1), 1.0e-10).wholeHyperplane(); +SubLine wholeLine = new Line(new Coordinates2D(-1, 7), new Coordinates2D(7, 1), 1.0e-10).wholeHyperplane(); List segments = wholeLine.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getX()) && @@ -59,7 +59,7 @@ public class SubLineTest {
[01/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
Repository: commons-math Updated Branches: refs/heads/feature-MATH-1284 [created] b815d2af5 http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java index 92ca21a..22fb232 100644 --- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java @@ -21,7 +21,7 @@ import java.util.List; import org.apache.commons.math4.geometry.enclosing.EnclosingBall; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.geometry.partitioning.RegionFactory; import org.apache.commons.math4.geometry.partitioning.SubHyperplane; import org.apache.commons.math4.geometry.partitioning.Region.Location; @@ -50,7 +50,7 @@ public class SphericalPolygonsSetTest { new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x852fd2a0ed8d2f6dl)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); Assert.assertEquals(Location.INSIDE, full.checkPoint(new S2Point(v))); } Assert.assertEquals(4 * FastMath.PI, new SphericalPolygonsSet(0.01, new S2Point[0]).getSize(), 1.0e-10); @@ -68,7 +68,7 @@ public class SphericalPolygonsSetTest { new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x76d9205d6167b6ddl)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v))); } Assert.assertEquals(0, empty.getSize(), 1.0e-10); @@ -82,12 +82,12 @@ public class SphericalPolygonsSetTest { public void testSouthHemisphere() { double tol = 0.01; double sinTol = FastMath.sin(tol); -SphericalPolygonsSet south = new SphericalPolygonsSet(Vector3D.MINUS_K, tol); +SphericalPolygonsSet south = new SphericalPolygonsSet(Coordinates3D.MINUS_K, tol); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x6b9d4a6ad90d7b0bl)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); if (v.getZ() < -sinTol) { Assert.assertEquals(Location.INSIDE, south.checkPoint(new S2Point(v))); } else if (v.getZ() > sinTol) { @@ -114,16 +114,16 @@ public class SphericalPolygonsSetTest { double tol = 0.01; double sinTol = FastMath.sin(tol); RegionFactory factory = new RegionFactory<>(); -SphericalPolygonsSet plusX = new SphericalPolygonsSet(Vector3D.PLUS_I, tol); -SphericalPolygonsSet plusY = new SphericalPolygonsSet(Vector3D.PLUS_J, tol); -SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Vector3D.PLUS_K, tol); +SphericalPolygonsSet plusX = new SphericalPolygonsSet(Coordinates3D.PLUS_I, tol); +SphericalPolygonsSet plusY = new SphericalPolygonsSet(Coordinates3D.PLUS_J, tol); +SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Coordinates3D.PLUS_K, tol); SphericalPolygonsSet octant = (SphericalPolygonsSet) factory.intersection(factory.intersection(plusX, plusY), plusZ); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x9c9802fde3cbcf25l)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v))); } else if ((v.getX() <
[04/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java index dbf1b3e..296ade8 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.geometry.Space; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.util.FastMath; @@ -39,27 +39,27 @@ public class Vector3DTest { @Test public void testConstructors() throws DimensionMismatchException { double r = FastMath.sqrt(2) /2; -checkVector(new Vector3D(2, new Vector3D(FastMath.PI / 3, -FastMath.PI / 4)), +checkVector(new Coordinates3D(2, new Coordinates3D(FastMath.PI / 3, -FastMath.PI / 4)), r, r * FastMath.sqrt(3), -2 * r); -checkVector(new Vector3D(2, Vector3D.PLUS_I, - -3, Vector3D.MINUS_K), +checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, + -3, Coordinates3D.MINUS_K), 2, 0, 3); -checkVector(new Vector3D(2, Vector3D.PLUS_I, - 5, Vector3D.PLUS_J, - -3, Vector3D.MINUS_K), +checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, + 5, Coordinates3D.PLUS_J, + -3, Coordinates3D.MINUS_K), 2, 5, 3); -checkVector(new Vector3D(2, Vector3D.PLUS_I, - 5, Vector3D.PLUS_J, - 5, Vector3D.MINUS_J, - -3, Vector3D.MINUS_K), +checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, + 5, Coordinates3D.PLUS_J, + 5, Coordinates3D.MINUS_J, + -3, Coordinates3D.MINUS_K), 2, 0, 3); -checkVector(new Vector3D(new double[] { 2, 5, -3 }), +checkVector(new Coordinates3D(new double[] { 2, 5, -3 }), 2, 5, -3); } @Test public void testSpace() { -Space space = new Vector3D(1, 2, 2).getSpace(); +Space space = new Coordinates3D(1, 2, 2).getSpace(); Assert.assertEquals(3, space.getDimension()); Assert.assertEquals(2, space.getSubSpace().getDimension()); Space deserialized = (Space) TestUtils.serializeAndRecover(space); @@ -68,63 +68,63 @@ public class Vector3DTest { @Test public void testZero() { -Assert.assertEquals(0, new Vector3D(1, 2, 2).getZero().getNorm(), 1.0e-15); +Assert.assertEquals(0, new Coordinates3D(1, 2, 2).getZero().getNorm(), 1.0e-15); } @Test public void testEquals() { -Vector3D u1 = new Vector3D(1, 2, 3); -Vector3D u2 = new Vector3D(1, 2, 3); +Coordinates3D u1 = new Coordinates3D(1, 2, 3); +Coordinates3D u2 = new Coordinates3D(1, 2, 3); Assert.assertTrue(u1.equals(u1)); Assert.assertTrue(u1.equals(u2)); Assert.assertFalse(u1.equals(new Rotation(1, 0, 0, 0, false))); -Assert.assertFalse(u1.equals(new Vector3D(1, 2, 3 + 10 * Precision.EPSILON))); -Assert.assertFalse(u1.equals(new Vector3D(1, 2 + 10 * Precision.EPSILON, 3))); -Assert.assertFalse(u1.equals(new Vector3D(1 + 10 * Precision.EPSILON, 2, 3))); -Assert.assertTrue(new Vector3D(0, Double.NaN, 0).equals(new Vector3D(0, 0, Double.NaN))); +Assert.assertFalse(u1.equals(new Coordinates3D(1, 2, 3 + 10 * Precision.EPSILON))); +Assert.assertFalse(u1.equals(new Coordinates3D(1, 2 + 10 * Precision.EPSILON, 3))); +Assert.assertFalse(u1.equals(new Coordinates3D(1 + 10 * Precision.EPSILON, 2, 3))); +Assert.assertTrue(new Coordinates3D(0, Double.NaN, 0).equals(new Coordinates3D(0, 0, Double.NaN))); } @Test public void testHash() { -Assert.assertEquals(new Vector3D(0, Double.NaN, 0).hashCode(), new Vector3D(0, 0, Double.NaN).hashCode()); -Vector3D u = new Vector3D(1, 2, 3); -Vector3D v = new Vector3D(1, 2, 3 + 10 * Precision.EPSILO
[11/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of the same method which would confuse the compiler, prefer the one which matches the documentation of the method. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/b815d2af Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/b815d2af Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/b815d2af Branch: refs/heads/feature-MATH-1284 Commit: b815d2af5a15901dcfd90cd76f0b6f431b0f0048 Parents: b645f5d Author: Ray DeCampo Authored: Tue Apr 25 18:55:22 2017 -0400 Committer: Ray DeCampo Committed: Tue Apr 25 18:55:22 2017 -0400 -- .../apache/commons/math4/geometry/Vector.java | 19 +- .../geometry/euclidean/oned/Coordinates1D.java | 386 ++ .../geometry/euclidean/oned/IntervalsSet.java | 18 +- .../geometry/euclidean/oned/OrientedPoint.java |8 +- .../math4/geometry/euclidean/oned/Vector1D.java | 369 - .../geometry/euclidean/oned/Vector1DFormat.java | 12 +- .../euclidean/threed/Coordinates3D.java | 621 + .../euclidean/threed/FieldRotation.java | 52 +- .../euclidean/threed/FieldVector3D.java | 78 +- .../math4/geometry/euclidean/threed/Line.java | 60 +- .../euclidean/threed/OutlineExtractor.java | 46 +- .../math4/geometry/euclidean/threed/Plane.java | 109 +- .../euclidean/threed/PolyhedronsSet.java| 96 +- .../geometry/euclidean/threed/Rotation.java | 136 +- .../euclidean/threed/RotationOrder.java | 38 +- .../geometry/euclidean/threed/Segment.java | 10 +- .../euclidean/threed/SphereGenerator.java | 22 +- .../euclidean/threed/SphericalCoordinates.java | 10 +- .../geometry/euclidean/threed/SubLine.java | 14 +- .../geometry/euclidean/threed/SubPlane.java | 12 +- .../geometry/euclidean/threed/Vector3D.java | 604 - .../euclidean/threed/Vector3DFormat.java| 22 +- .../geometry/euclidean/twod/Coordinates2D.java | 492 +++ .../geometry/euclidean/twod/DiskGenerator.java | 16 +- .../math4/geometry/euclidean/twod/Line.java | 67 +- .../geometry/euclidean/twod/NestedLoops.java| 12 +- .../geometry/euclidean/twod/PolygonsSet.java| 74 +- .../math4/geometry/euclidean/twod/Segment.java | 14 +- .../math4/geometry/euclidean/twod/SubLine.java | 22 +- .../math4/geometry/euclidean/twod/Vector2D.java | 475 --- .../geometry/euclidean/twod/Vector2DFormat.java | 12 +- .../hull/AbstractConvexHullGenerator2D.java | 10 +- .../twod/hull/AklToussaintHeuristic.java| 34 +- .../euclidean/twod/hull/ConvexHull2D.java | 32 +- .../twod/hull/ConvexHullGenerator2D.java|6 +- .../euclidean/twod/hull/MonotoneChain.java | 28 +- .../geometry/partitioning/AbstractRegion.java |6 +- .../math4/geometry/spherical/oned/S1Point.java | 14 +- .../math4/geometry/spherical/twod/Circle.java | 34 +- .../math4/geometry/spherical/twod/Edge.java |4 +- .../geometry/spherical/twod/EdgesBuilder.java | 10 +- .../spherical/twod/PropertiesComputer.java | 30 +- .../math4/geometry/spherical/twod/S2Point.java | 32 +- .../spherical/twod/SphericalPolygonsSet.java| 26 +- .../geometry/spherical/twod/SubCircle.java |4 +- .../commons/math4/complex/QuaternionTest.java | 30 +- ...stractLeastSquaresOptimizerAbstractTest.java |6 +- .../fitting/leastsquares/CircleVectorial.java | 18 +- .../GaussNewtonOptimizerWithSVDTest.java|6 +- .../LevenbergMarquardtOptimizerTest.java|6 +- .../RandomCirclePointGenerator.java | 10 +- .../geometry/enclosing/WelzlEncloser2DTest.java | 56 +- .../geometry/enclosing/WelzlEncloser3DTest.java | 110 +- .../euclidean/oned/IntervalsSetTest.java| 42 +- .../oned/Vector1DFormatAbstractTest.java| 70 +- .../geometry/euclidean/oned/Vector1DTest.java | 130 +- .../euclidean/threed/FieldRotationDSTest.java | 20 +- .../euclidean/threed/FieldRotationDfpTest.java |6 +- .../euclidean/threed/FieldVector3DTest.java | 70 +- .../geometry/euclidean/threed/LineTest.java | 76 +- .../geometry/euclidean/threed/PLYParser.java|8 +- .../geometry/euclidean/threed/PlaneTest.java| 88 +- .../euclidean/threed/PolyhedronsSetTest.java| 146 +- .../geometry/euclidean/threed/RotationTest.java | 250 ++-- .../euclidean/threed/SphereGeneratorTest.java | 114 +- .../threed/SphericalCoordinatesTest.java| 30 +- .../geometry/euclidean/threed/SubLineTest.java | 60 +- .../threed/Vector3DFormatAbstractTest.java | 74 +- .../geometry/euclidean/threed/Vector3DTest.java | 246 ++-- .../
[09/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java index 5de70a5..ff8f17e 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java @@ -48,8 +48,8 @@ import org.apache.commons.math4.util.MathArrays; * Focus is oriented on what a rotation do rather than on its * underlying representation. Once it has been built, and regardless of its * internal representation, a rotation is an operator which basically - * transforms three dimensional {@link Vector3D vectors} into other three - * dimensional {@link Vector3D vectors}. Depending on the application, the + * transforms three dimensional {@link Coordinates3D vectors} into other three + * dimensional {@link Coordinates3D vectors}. Depending on the application, the * meaning of these vectors may vary and the semantics of the rotation also. * For example in an spacecraft attitude simulation tool, users will often * consider the vectors are fixed (say the Earth direction for example) and the @@ -88,7 +88,7 @@ import org.apache.commons.math4.util.MathArrays; * * Rotations are guaranteed to be immutable objects. * - * @see Vector3D + * @see Coordinates3D * @see RotationOrder * @since 1.2 */ @@ -162,7 +162,7 @@ public class Rotation implements Serializable { * @deprecated as of 3.6, replaced with {@link #Rotation(Vector3D, double, RotationConvention)} */ @Deprecated - public Rotation(Vector3D axis, double angle) throws MathIllegalArgumentException { + public Rotation(Coordinates3D axis, double angle) throws MathIllegalArgumentException { this(axis, angle, RotationConvention.VECTOR_OPERATOR); } @@ -173,7 +173,7 @@ public class Rotation implements Serializable { * @exception MathIllegalArgumentException if the axis norm is zero * @since 3.6 */ - public Rotation(final Vector3D axis, final double angle, final RotationConvention convention) + public Rotation(final Coordinates3D axis, final double angle, final RotationConvention convention) throws MathIllegalArgumentException { double norm = axis.getNorm(); @@ -272,18 +272,18 @@ public class Rotation implements Serializable { * @exception MathArithmeticException if the norm of one of the vectors is zero, * or if one of the pair is degenerated (i.e. the vectors of the pair are collinear) */ - public Rotation(Vector3D u1, Vector3D u2, Vector3D v1, Vector3D v2) + public Rotation(Coordinates3D u1, Coordinates3D u2, Coordinates3D v1, Coordinates3D v2) throws MathArithmeticException { // build orthonormalized base from u1, u2 // this fails when vectors are null or collinear, which is forbidden to define a rotation - final Vector3D u3 = u1.crossProduct(u2).normalize(); + final Coordinates3D u3 = u1.crossProduct(u2).normalize(); u2 = u3.crossProduct(u1).normalize(); u1 = u1.normalize(); // build an orthonormalized base from v1, v2 // this fails when vectors are null or collinear, which is forbidden to define a rotation - final Vector3D v3 = v1.crossProduct(v2).normalize(); + final Coordinates3D v3 = v1.crossProduct(v2).normalize(); v2 = v3.crossProduct(v1).normalize(); v1 = v1.normalize(); @@ -327,7 +327,7 @@ public class Rotation implements Serializable { * @param v desired image of u by the rotation * @exception MathArithmeticException if the norm of one of the vectors is zero */ - public Rotation(Vector3D u, Vector3D v) throws MathArithmeticException { + public Rotation(Coordinates3D u, Coordinates3D v) throws MathArithmeticException { double normProduct = u.getNorm() * v.getNorm(); if (normProduct == 0) { @@ -339,7 +339,7 @@ public class Rotation implements Serializable { if (dot < ((2.0e-15 - 1.0) * normProduct)) { // special case u = -v: we select a PI angle rotation around // an arbitrary vector orthogonal to u - Vector3D w = u.orthogonal(); + Coordinates3D w = u.orthogonal(); q0 = 0.0; q1 = -w.getX(); q2 = -w.getY(); @@ -349,7 +349,7 @@ public class Rotation implements Serializable { // the shortest possible rotation: axis orthogonal to this plane q0 = FastMath.sqrt(0.5 * (1.0 + dot / normProduct)); double coeff = 1.0 / (2.0 * q0 * normProduct); - Vector3D q = v.crossProduct(u); + Coordinates3D q = v.crossProduct(u); q1 = coeff * q.getX(); q2 = coeff * q.getY(); q3 = coeff * q.getZ(); @@ -522,7 +522,7 @@ public class Rotation implements Serializable { *
[05/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java index 5f57326..a2ebce8 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.CardanEulerSingularity import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.util.FastMath; import org.apache.commons.math4.util.MathUtils; import org.junit.Assert; @@ -36,21 +36,21 @@ public class RotationTest { public void testIdentity() { Rotation r = Rotation.IDENTITY; -checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_I); -checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_J); -checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_K); +checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); +checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); +checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); checkAngle(r.getAngle(), 0); r = new Rotation(-1, 0, 0, 0, false); -checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_I); -checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_J); -checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_K); +checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); +checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); +checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); checkAngle(r.getAngle(), 0); r = new Rotation(42, 0, 0, 0, true); -checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_I); -checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_J); -checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_K); +checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); +checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); +checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); checkAngle(r.getAngle(), 0); } @@ -59,95 +59,95 @@ public class RotationTest { @Deprecated public void testAxisAngleDeprecated() throws MathIllegalArgumentException { -Rotation r = new Rotation(new Vector3D(10, 10, 10), 2 * FastMath.PI / 3); -checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_J); -checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_K); -checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_I); +Rotation r = new Rotation(new Coordinates3D(10, 10, 10), 2 * FastMath.PI / 3); +checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_J); +checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_K); +checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_I); double s = 1 / FastMath.sqrt(3); -checkVector(r.getAxis(), new Vector3D(s, s, s)); +checkVector(r.getAxis(), new Coordinates3D(s, s, s)); checkAngle(r.getAngle(), 2 * FastMath.PI / 3); try { - new Rotation(new Vector3D(0, 0, 0), 2 * FastMath.PI / 3); + new Rotation(new Coordinates3D(0, 0, 0), 2 * FastMath.PI / 3); Assert.fail("an exception should have been thrown"); } catch (MathIllegalArgumentException e) { } -r = new Rotation(Vector3D.PLUS_K, 1.5 * FastMath.PI); -checkVector(r.getAxis(), new Vector3D(0, 0, -1)); +r = new Rotation(Coordinates3D.PLUS_K, 1.5 * FastMath.PI); +checkVector(r.getAxis(), new Coordinates3D(0, 0, -1)); checkAngle(r.getAngle(), 0.5 * FastMath.PI); -r = new Rotation(Vector3D.PLUS_J, FastMath.PI); -checkVector(r.getAxis(), Vector3D.PLUS_J); +r = new Rotation(Coordinates3D.PLUS_J, FastMath.PI); +checkVector(r.getAxis(), Coordinates3D.PLUS_J); checkAngle(r.getAngle(), FastMath.PI); -checkVector(Rotation.IDENTITY.getAxis(), Vector3D.PLUS_I); +checkVector(Rotation.IDENTITY.getAxis(), Coordinates3D.PLUS_I); } @Test public void testAxisAngleVectorOperator() throws MathIllegalArgumentException { -Rotation r = new Rotation(new Vector3D(10, 10, 10), 2 * FastMath.PI / 3, RotationConvention.VECTOR_OPERATOR); -checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_J); -checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_K); -checkVector(r.applyTo(Vector3D
[10/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java index bec2d74..dc538a5 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.util.FastMath; import org.apache.commons.math4.util.MathArrays; /** - * This class is a re-implementation of {@link Vector3D} using {@link RealFieldElement}. + * This class is a re-implementation of {@link Coordinates3D} using {@link RealFieldElement}. * Instance of this class are guaranteed to be immutable. * @param the type of the field elements * @since 3.2 @@ -110,7 +110,7 @@ public class FieldVector3D> implements Serializabl * @param a scale factor * @param u base (unscaled) vector */ -public FieldVector3D(final T a, final Vector3D u) { +public FieldVector3D(final T a, final Coordinates3D u) { this.x = a.multiply(u.getX()); this.y = a.multiply(u.getY()); this.z = a.multiply(u.getZ()); @@ -152,8 +152,8 @@ public class FieldVector3D> implements Serializabl * @param a2 second scale factor * @param u2 second base (unscaled) vector */ -public FieldVector3D(final T a1, final Vector3D u1, - final T a2, final Vector3D u2) { +public FieldVector3D(final T a1, final Coordinates3D u1, + final T a2, final Coordinates3D u2) { final T prototype = a1; this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2); this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2); @@ -205,9 +205,9 @@ public class FieldVector3D> implements Serializabl * @param a3 third scale factor * @param u3 third base (unscaled) vector */ -public FieldVector3D(final T a1, final Vector3D u1, - final T a2, final Vector3D u2, - final T a3, final Vector3D u3) { +public FieldVector3D(final T a1, final Coordinates3D u1, + final T a2, final Coordinates3D u2, + final T a3, final Coordinates3D u3) { final T prototype = a1; this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2, u3.getX(), a3); this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2, u3.getY(), a3); @@ -267,10 +267,10 @@ public class FieldVector3D> implements Serializabl * @param a4 fourth scale factor * @param u4 fourth base (unscaled) vector */ -public FieldVector3D(final T a1, final Vector3D u1, - final T a2, final Vector3D u2, - final T a3, final Vector3D u3, - final T a4, final Vector3D u4) { +public FieldVector3D(final T a1, final Coordinates3D u1, + final T a2, final Coordinates3D u2, + final T a3, final Coordinates3D u3, + final T a4, final Coordinates3D u4) { final T prototype = a1; this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2, u3.getX(), a3, u4.getX(), a4); this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2, u3.getY(), a3, u4.getY(), a4); @@ -338,8 +338,8 @@ public class FieldVector3D> implements Serializabl /** Convert to a constant vector without derivatives. * @return a constant vector */ -public Vector3D toVector3D() { -return new Vector3D(x.getReal(), y.getReal(), z.getReal()); +public Coordinates3D toVector3D() { +return new Coordinates3D(x.getReal(), y.getReal(), z.getReal()); } /** Get the L1 norm for the vector. @@ -415,7 +415,7 @@ public class FieldVector3D> implements Serializabl * @param v vector to add * @return a new vector */ -public FieldVector3D add(final Vector3D v) { +public FieldVector3D add(final Coordinates3D v) { return new FieldVector3D<>(x.add(v.getX()), y.add(v.getY()), z.add(v.getZ())); } @@ -433,7 +433,7 @@ public class FieldVector3D> implements Serializabl * @param v vector to add * @return a new vector */ -public FieldVector3D add(final T factor, final Vector3D v) { +public FieldVector3D add(final T factor, final Coordinates3D v) { return new FieldVector3D<>(x.add(factor.multiply(v.getX())), y.add(factor.multiply(v.getY())), z.add(factor.multiply(v.getZ(; @@ -453,7 +453,7 @@ public class FieldVector3D
[07/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/spherical/twod/PropertiesComputer.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/PropertiesComputer.java b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/PropertiesComputer.java index b7bcbf0..4d61de1 100644 --- a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/PropertiesComputer.java +++ b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/PropertiesComputer.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.math4.exception.MathInternalError; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.geometry.partitioning.BSPTree; import org.apache.commons.math4.geometry.partitioning.BSPTreeVisitor; import org.apache.commons.math4.util.FastMath; @@ -38,10 +38,10 @@ class PropertiesComputer implements BSPTreeVisitor { private double summedArea; /** Summed barycenter. */ -private Vector3D summedBarycenter; +private Coordinates3D summedBarycenter; /** List of points strictly inside convex cells. */ -private final List convexCellsInsidePoints; +private final List convexCellsInsidePoints; /** Simple constructor. * @param tolerance below which points are consider to be identical @@ -49,7 +49,7 @@ class PropertiesComputer implements BSPTreeVisitor { PropertiesComputer(final double tolerance) { this.tolerance = tolerance; this.summedArea = 0; -this.summedBarycenter = Vector3D.ZERO; +this.summedBarycenter = Coordinates3D.ZERO; this.convexCellsInsidePoints = new ArrayList<>(); } @@ -86,12 +86,12 @@ class PropertiesComputer implements BSPTreeVisitor { // compute the geometrical properties of the convex cell final double area = convexCellArea(boundary.get(0)); -final Vector3D barycenter = convexCellBarycenter(boundary.get(0)); +final Coordinates3D barycenter = convexCellBarycenter(boundary.get(0)); convexCellsInsidePoints.add(barycenter); // add the cell contribution to the global properties summedArea += area; -summedBarycenter = new Vector3D(1, summedBarycenter, area, barycenter); +summedBarycenter = new Coordinates3D(1, summedBarycenter, area, barycenter); } } @@ -109,11 +109,11 @@ class PropertiesComputer implements BSPTreeVisitor { for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) { // find path interior angle at vertex -final Vector3D previousPole = e.getCircle().getPole(); -final Vector3D nextPole = e.getEnd().getOutgoing().getCircle().getPole(); -final Vector3D point= e.getEnd().getLocation().getVector(); -double alpha = FastMath.atan2(Vector3D.dotProduct(nextPole, Vector3D.crossProduct(point, previousPole)), - -Vector3D.dotProduct(nextPole, previousPole)); +final Coordinates3D previousPole = e.getCircle().getPole(); +final Coordinates3D nextPole = e.getEnd().getOutgoing().getCircle().getPole(); +final Coordinates3D point= e.getEnd().getLocation().getVector(); +double alpha = FastMath.atan2(Coordinates3D.dotProduct(nextPole, Coordinates3D.crossProduct(point, previousPole)), + -Coordinates3D.dotProduct(nextPole, previousPole)); if (alpha < 0) { alpha += MathUtils.TWO_PI; } @@ -133,14 +133,14 @@ class PropertiesComputer implements BSPTreeVisitor { * @param start start vertex of the convex cell boundary * @return barycenter */ -private Vector3D convexCellBarycenter(final Vertex start) { +private Coordinates3D convexCellBarycenter(final Vertex start) { int n = 0; -Vector3D sumB = Vector3D.ZERO; +Coordinates3D sumB = Coordinates3D.ZERO; // loop around the cell for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) { -sumB = new Vector3D(1, sumB, e.getLength(), e.getCircle().getPole()); +sumB = new Coordinates3D(1, sumB, e.getLength(), e.getCircle().getPole()); n++; } @@ -169,7 +169,7 @@ class PropertiesComputer implements BSPTreeVisitor { /** Get the points strictly inside convex cells. * @return points strictly inside convex cells */ -public List getConvexCellsInsidePoints() { +public List getC
[03/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java index 08ffdcd..01bfdb3 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java @@ -22,12 +22,12 @@ import java.util.List; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.geometry.euclidean.oned.Interval; import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; -import org.apache.commons.math4.geometry.euclidean.oned.Vector1D; +import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D; import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.PolygonsSet; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Vector2D; +import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; import org.apache.commons.math4.geometry.partitioning.BSPTree; import org.apache.commons.math4.geometry.partitioning.BSPTreeVisitor; import org.apache.commons.math4.geometry.partitioning.BoundaryProjection; @@ -44,41 +44,41 @@ public class PolygonsSetTest { @Test public void testSimplyConnected() { -Vector2D[][] vertices = new Vector2D[][] { -new Vector2D[] { -new Vector2D(36.0, 22.0), -new Vector2D(39.0, 32.0), -new Vector2D(19.0, 32.0), -new Vector2D( 6.0, 16.0), -new Vector2D(31.0, 10.0), -new Vector2D(42.0, 16.0), -new Vector2D(34.0, 20.0), -new Vector2D(29.0, 19.0), -new Vector2D(23.0, 22.0), -new Vector2D(33.0, 25.0) +Coordinates2D[][] vertices = new Coordinates2D[][] { +new Coordinates2D[] { +new Coordinates2D(36.0, 22.0), +new Coordinates2D(39.0, 32.0), +new Coordinates2D(19.0, 32.0), +new Coordinates2D( 6.0, 16.0), +new Coordinates2D(31.0, 10.0), +new Coordinates2D(42.0, 16.0), +new Coordinates2D(34.0, 20.0), +new Coordinates2D(29.0, 19.0), +new Coordinates2D(23.0, 22.0), +new Coordinates2D(33.0, 25.0) } }; PolygonsSet set = buildSet(vertices); -Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector2D(50.0, 30.0))); -checkPoints(Region.Location.INSIDE, set, new Vector2D[] { -new Vector2D(30.0, 15.0), -new Vector2D(15.0, 20.0), -new Vector2D(24.0, 25.0), -new Vector2D(35.0, 30.0), -new Vector2D(19.0, 17.0) +Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Coordinates2D(50.0, 30.0))); +checkPoints(Region.Location.INSIDE, set, new Coordinates2D[] { +new Coordinates2D(30.0, 15.0), +new Coordinates2D(15.0, 20.0), +new Coordinates2D(24.0, 25.0), +new Coordinates2D(35.0, 30.0), +new Coordinates2D(19.0, 17.0) }); -checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] { -new Vector2D(50.0, 30.0), -new Vector2D(30.0, 35.0), -new Vector2D(10.0, 25.0), -new Vector2D(10.0, 10.0), -new Vector2D(40.0, 10.0), -new Vector2D(50.0, 15.0), -new Vector2D(30.0, 22.0) +checkPoints(Region.Location.OUTSIDE, set, new Coordinates2D[] { +new Coordinates2D(50.0, 30.0), +new Coordinates2D(30.0, 35.0), +new Coordinates2D(10.0, 25.0), +new Coordinates2D(10.0, 10.0), +new Coordinates2D(40.0, 10.0), +new Coordinates2D(50.0, 15.0), +new Coordinates2D(30.0, 22.0) }); -checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] { -new Vector2D(30.0, 32.0), -new Vector2D(34.0, 20.0) +checkPoints(Region.Location.BOUNDARY, set, new Coordinates2D[] { +new Coordinates2D(30.0, 32.0), +new Coordinates2D(34.0, 20.0) }); checkVertices(set.getVertices(), vertices); } @@ -98,18 +98,18 @@ public class PolygonsSetTest { @Test public void testStair() { -Vector2D[][] vertices = new Vector2D[][] { -new Vector2D[] { -new Vector2D( 0.0, 0.0), -
[08/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java index a19a876..7ac90d4 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java @@ -26,26 +26,26 @@ import org.apache.commons.math4.util.FastMath; /** Class generating an enclosing ball from its support points. * @since 3.3 */ -public class DiskGenerator implements SupportBallGenerator { +public class DiskGenerator implements SupportBallGenerator { /** {@inheritDoc} */ @Override -public EnclosingBall ballOnSupport(final List support) { +public EnclosingBall ballOnSupport(final List support) { if (support.size() < 1) { -return new EnclosingBall<>(Vector2D.ZERO, Double.NEGATIVE_INFINITY); +return new EnclosingBall<>(Coordinates2D.ZERO, Double.NEGATIVE_INFINITY); } else { -final Vector2D vA = support.get(0); +final Coordinates2D vA = support.get(0); if (support.size() < 2) { return new EnclosingBall<>(vA, 0, vA); } else { -final Vector2D vB = support.get(1); +final Coordinates2D vB = support.get(1); if (support.size() < 3) { -return new EnclosingBall<>(new Vector2D(0.5, vA, 0.5, vB), +return new EnclosingBall<>(new Coordinates2D(0.5, vA, 0.5, vB), 0.5 * vA.distance(vB), vA, vB); } else { -final Vector2D vC = support.get(2); +final Coordinates2D vC = support.get(2); // a disk is 2D can be defined as: // (1) (x - x_0)^2 + (y - y_0)^2 = r^2 // which can be written: @@ -86,7 +86,7 @@ public class DiskGenerator implements SupportBallGenerator(new Vector2D(centerX.doubleValue(), +return new EnclosingBall<>(new Coordinates2D(centerX.doubleValue(), centerY.doubleValue()), FastMath.sqrt(r2.doubleValue()), vA, vB, vC); http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java index dd89296..7df7277 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java @@ -19,11 +19,10 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.exception.util.LocalizedFormats; import org.apache.commons.math4.geometry.Point; -import org.apache.commons.math4.geometry.Vector; import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.oned.OrientedPoint; -import org.apache.commons.math4.geometry.euclidean.oned.Vector1D; +import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D; import org.apache.commons.math4.geometry.partitioning.Embedding; import org.apache.commons.math4.geometry.partitioning.Hyperplane; import org.apache.commons.math4.geometry.partitioning.SubHyperplane; @@ -85,7 +84,7 @@ public class Line implements Hyperplane, Embedding, Embedding, Embedding, Embedding, Embedding vector) { -return toSubSpace((Point) vector); -} +//public Coordinates1D toSubSpace(Vector vector) { +//return toSubSpace((Point) vector); +//} /** Transform a sub-space point into a space point. * @param vector (n-1)-dimension point of the sub-space * @return n-dimension point of the space corresponding to the * specified sub-space point */ -public Vector2D toSpace(Vector vector) { -return toSpace((Point) vector); -} +//public Coordinates2D toSpace(Vector vector) { +//return toSpace((Point) vector); +//} /** {@inheritDoc} */ @Override -
[06/11] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java index 4c87742..65f45a3 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D; import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.linear.MatrixUtils; import org.apache.commons.math4.linear.RealMatrix; import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator; @@ -975,7 +975,7 @@ public class FieldRotationDSTest { FieldVector3D uds = createVector(x, y, z); FieldVector3D ruds = r.applyTo(uds); FieldVector3D rIuds = r.applyInverseTo(uds); -Vector3D u = new Vector3D(x, y, z); +Coordinates3D u = new Coordinates3D(x, y, z); FieldVector3D ru= r.applyTo(u); FieldVector3D rIu = r.applyInverseTo(u); DerivativeStructure[] ruArray = new DerivativeStructure[3]; @@ -1000,7 +1000,7 @@ public class FieldRotationDSTest { UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random); for (int i = 0; i < 10; ++i) { double[] unit1 = g.nextVector(); -Rotation r1 = new Rotation(new Vector3D(unit1[0], unit1[1], unit1[2]), +Rotation r1 = new Rotation(new Coordinates3D(unit1[0], unit1[1], unit1[2]), random.nextDouble(), RotationConvention.VECTOR_OPERATOR); FieldRotation r1Prime = new FieldRotation<>(new DerivativeStructure(4, 1, 0, r1.getQ0()), new DerivativeStructure(4, 1, 1, r1.getQ1()), @@ -1051,7 +1051,7 @@ public class FieldRotationDSTest { FieldRotation r= new FieldRotation<>(createAxis(kx, ky, kz), createAngle(theta), RotationConvention.VECTOR_OPERATOR); -Vector3D a = new Vector3D(kx / n, ky / n, kz / n); +Coordinates3D a = new Coordinates3D(kx / n, ky / n, kz / n); // Jacobian of the normalized rotation axis a with respect to the Cartesian vector k RealMatrix dadk = MatrixUtils.createRealMatrix(new double[][] { @@ -1063,15 +1063,15 @@ public class FieldRotationDSTest { for (double x = -0.9; x < 0.9; x += 0.2) { for (double y = -0.9; y < 0.9; y += 0.2) { for (double z = -0.9; z < 0.9; z += 0.2) { -Vector3D u = new Vector3D(x, y, z); +Coordinates3D u = new Coordinates3D(x, y, z); FieldVector3D v = r.applyTo(createVector(x, y, z)); // explicit formula for rotation of vector u around axis a with angle theta -double dot = Vector3D.dotProduct(u, a); -Vector3D cross = Vector3D.crossProduct(a, u); +double dot = Coordinates3D.dotProduct(u, a); +Coordinates3D cross = Coordinates3D.crossProduct(a, u); double c1 = 1 - cosTheta; double c2 = c1 * dot; -Vector3D rt= new Vector3D(cosTheta, u, c2, a, sinTheta, cross); +Coordinates3D rt= new Coordinates3D(cosTheta, u, c2, a, sinTheta, cross); Assert.assertEquals(rt.getX(), v.getX().getReal(), eps); Assert.assertEquals(rt.getY(), v.getY().getReal(), eps); Assert.assertEquals(rt.getZ(), v.getZ().getReal(), eps); @@ -1100,8 +1100,8 @@ public class FieldRotationDSTest { // derivative with respect to rotation angle // (analytical differentiation of the explicit formula) -Vector3D dvdTheta = -new Vector3D(-sinTheta, u, sinTheta * dot, a, cosTheta, cross); +Co
[15/19] [math] MATH-1284: Replace uses of "Vector1D" in comments and supporting files with "Cartesian1D".
MATH-1284: Replace uses of "Vector1D" in comments and supporting files with "Cartesian1D". Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a27ca511 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a27ca511 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a27ca511 Branch: refs/heads/feature-MATH-1284 Commit: a27ca511a591caf813c26862a888e90e54af19a9 Parents: e508ad0 Author: Ray DeCampo Authored: Thu May 4 07:30:27 2017 -0400 Committer: Ray DeCampo Committed: Thu May 4 07:30:27 2017 -0400 -- .../geometry/euclidean/oned/Cartesian1D.java| 6 +- .../math4/geometry/partitioning/Embedding.java | 2 +- src/site/xdoc/userguide/geometry.xml| 4 +- .../euclidean/oned/Cartesian1DTest.java | 219 +++ .../geometry/euclidean/oned/Vector1DTest.java | 219 --- 5 files changed, 225 insertions(+), 225 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java index 0a248a1..f406125 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java @@ -126,7 +126,7 @@ public class Cartesian1D implements Point, Vector { /** Get the abscissa of the vector. * @return abscissa of the vector - * @see #Vector1D(double) + * @see #Cartesian1D(double) */ public double getX() { return x; @@ -332,8 +332,8 @@ public class Cartesian1D implements Point, Vector { * * @param other Object to test for equality to this * @return true if two 1D vector objects are equal, false if - * object is null, not an instance of Vector1D, or - * not equal to this Vector1D instance + * object is null, not an instance of Cartesian1D, or + * not equal to this Cartesian1D instance * */ @Override http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java b/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java index ae48f11..9e78d90 100644 --- a/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java +++ b/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.geometry.Space; * org.apache.commons.math4.geometry.euclidean.threed.Line Line} in 3D * implements Embedding<{@link * org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D Cartesian3D}, {link - * org.apache.commons.math4.geometry.euclidean.oned.Vector1D Vector1D}, i.e. it + * org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D Cartesian1D}, i.e. it * maps directly dimensions 3 and 1. * In the 3D euclidean space, hyperplanes are 2D planes, and the 1D http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/site/xdoc/userguide/geometry.xml -- diff --git a/src/site/xdoc/userguide/geometry.xml b/src/site/xdoc/userguide/geometry.xml index 6c76e3b..4242c96 100644 --- a/src/site/xdoc/userguide/geometry.xml +++ b/src/site/xdoc/userguide/geometry.xml @@ -76,8 +76,8 @@ - - Vector1D, + + Cartesian1D, Cartesian2D and Cartesian3D provide simple vector types. One important feature is that instances of these classes are guaranteed http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java new file mode 100644 index 000..2b60c3d --- /dev/null +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java @@ -0,0 +1,219 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for addition
[01/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
Repository: commons-math Updated Branches: refs/heads/feature-MATH-1284 b815d2af5 -> c9e49faac http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java index 22fb232..4096a59 100644 --- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java @@ -21,7 +21,7 @@ import java.util.List; import org.apache.commons.math4.geometry.enclosing.EnclosingBall; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.math4.geometry.partitioning.RegionFactory; import org.apache.commons.math4.geometry.partitioning.SubHyperplane; import org.apache.commons.math4.geometry.partitioning.Region.Location; @@ -50,7 +50,7 @@ public class SphericalPolygonsSetTest { new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x852fd2a0ed8d2f6dl)); for (int i = 0; i < 1000; ++i) { -Coordinates3D v = new Coordinates3D(random.nextVector()); +Cartesian3D v = new Cartesian3D(random.nextVector()); Assert.assertEquals(Location.INSIDE, full.checkPoint(new S2Point(v))); } Assert.assertEquals(4 * FastMath.PI, new SphericalPolygonsSet(0.01, new S2Point[0]).getSize(), 1.0e-10); @@ -68,7 +68,7 @@ public class SphericalPolygonsSetTest { new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x76d9205d6167b6ddl)); for (int i = 0; i < 1000; ++i) { -Coordinates3D v = new Coordinates3D(random.nextVector()); +Cartesian3D v = new Cartesian3D(random.nextVector()); Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v))); } Assert.assertEquals(0, empty.getSize(), 1.0e-10); @@ -82,12 +82,12 @@ public class SphericalPolygonsSetTest { public void testSouthHemisphere() { double tol = 0.01; double sinTol = FastMath.sin(tol); -SphericalPolygonsSet south = new SphericalPolygonsSet(Coordinates3D.MINUS_K, tol); +SphericalPolygonsSet south = new SphericalPolygonsSet(Cartesian3D.MINUS_K, tol); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x6b9d4a6ad90d7b0bl)); for (int i = 0; i < 1000; ++i) { -Coordinates3D v = new Coordinates3D(random.nextVector()); +Cartesian3D v = new Cartesian3D(random.nextVector()); if (v.getZ() < -sinTol) { Assert.assertEquals(Location.INSIDE, south.checkPoint(new S2Point(v))); } else if (v.getZ() > sinTol) { @@ -114,16 +114,16 @@ public class SphericalPolygonsSetTest { double tol = 0.01; double sinTol = FastMath.sin(tol); RegionFactory factory = new RegionFactory<>(); -SphericalPolygonsSet plusX = new SphericalPolygonsSet(Coordinates3D.PLUS_I, tol); -SphericalPolygonsSet plusY = new SphericalPolygonsSet(Coordinates3D.PLUS_J, tol); -SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Coordinates3D.PLUS_K, tol); +SphericalPolygonsSet plusX = new SphericalPolygonsSet(Cartesian3D.PLUS_I, tol); +SphericalPolygonsSet plusY = new SphericalPolygonsSet(Cartesian3D.PLUS_J, tol); +SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Cartesian3D.PLUS_K, tol); SphericalPolygonsSet octant = (SphericalPolygonsSet) factory.intersection(factory.intersection(plusX, plusY), plusZ); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x9c9802fde3cbcf25l)); for (int i = 0; i < 1000; ++i) { -Coordinates3D v = new Coordinates3D(random.nextVector()); +Cartesian3D v = new Cartesian3D(random.nextVector()); if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point
[19/19] [math] MATH-1284: Fix javadoc references
MATH-1284: Fix javadoc references Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/c9e49faa Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/c9e49faa Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/c9e49faa Branch: refs/heads/feature-MATH-1284 Commit: c9e49faac27b1d79f266712ddee7207625b3b0ae Parents: 05edf06 Author: Ray DeCampo Authored: Sat May 6 11:03:18 2017 -0400 Committer: Ray DeCampo Committed: Sat May 6 11:03:18 2017 -0400 -- .../apache/commons/math4/geometry/euclidean/oned/Vector1D.java | 2 +- .../apache/commons/math4/geometry/euclidean/twod/Vector2D.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/c9e49faa/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java index f35c81f..ceeea08 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java @@ -26,7 +26,7 @@ public abstract class Vector1D implements Vector { /** Get the abscissa of the vector. * @return abscissa of the vector - * @see #Vector1D(double) + * @see #Cartesian1D(double) */ public abstract double getX(); http://git-wip-us.apache.org/repos/asf/commons-math/blob/c9e49faa/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java index 4a2a398..a43c8a0 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java @@ -25,13 +25,13 @@ public abstract class Vector2D implements Vector { /** Get the abscissa of the vector. * @return abscissa of the vector - * @see #Vector2D(double, double) + * @see #Cartesian2D(double, double) */ public abstract double getX(); /** Get the ordinate of the vector. * @return ordinate of the vector - * @see #Vector2D(double, double) + * @see #Cartesian2D(double, double) */ public abstract double getY();
[07/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/spherical/twod/SubCircle.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/SubCircle.java b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/SubCircle.java index 1e09a2d..8710e47 100644 --- a/src/main/java/org/apache/commons/math4/geometry/spherical/twod/SubCircle.java +++ b/src/main/java/org/apache/commons/math4/geometry/spherical/twod/SubCircle.java @@ -16,7 +16,7 @@ */ package org.apache.commons.math4.geometry.spherical.twod; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.math4.geometry.partitioning.AbstractSubHyperplane; import org.apache.commons.math4.geometry.partitioning.Hyperplane; import org.apache.commons.math4.geometry.partitioning.Region; @@ -52,7 +52,7 @@ public class SubCircle extends AbstractSubHyperplane { final Circle thisCircle = (Circle) getHyperplane(); final Circle otherCircle = (Circle) hyperplane; -final double angle = Coordinates3D.angle(thisCircle.getPole(), otherCircle.getPole()); +final double angle = Cartesian3D.angle(thisCircle.getPole(), otherCircle.getPole()); if (angle < thisCircle.getTolerance() || angle > FastMath.PI - thisCircle.getTolerance()) { // the two circles are aligned or opposite http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/complex/QuaternionTest.java -- diff --git a/src/test/java/org/apache/commons/math4/complex/QuaternionTest.java b/src/test/java/org/apache/commons/math4/complex/QuaternionTest.java index 16159ec..06feaa5 100644 --- a/src/test/java/org/apache/commons/math4/complex/QuaternionTest.java +++ b/src/test/java/org/apache/commons/math4/complex/QuaternionTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.ZeroException; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.RotationConvention; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.math4.util.FastMath; import org.junit.Test; import org.junit.Assert; @@ -121,16 +121,16 @@ public class QuaternionTest { // qResult = (scalarA * scalarB - vectorA . vectorB) + (scalarA * vectorB + scalarB * vectorA + vectorA ^ // vectorB) -final Coordinates3D vectorA = new Coordinates3D(qA.getVectorPart()); -final Coordinates3D vectorB = new Coordinates3D(qB.getVectorPart()); -final Coordinates3D vectorResult = new Coordinates3D(qResult.getVectorPart()); +final Cartesian3D vectorA = new Cartesian3D(qA.getVectorPart()); +final Cartesian3D vectorB = new Cartesian3D(qB.getVectorPart()); +final Cartesian3D vectorResult = new Cartesian3D(qResult.getVectorPart()); -final double scalarPartRef = qA.getScalarPart() * qB.getScalarPart() - Coordinates3D.dotProduct(vectorA, vectorB); +final double scalarPartRef = qA.getScalarPart() * qB.getScalarPart() - Cartesian3D.dotProduct(vectorA, vectorB); Assert.assertEquals(scalarPartRef, qResult.getScalarPart(), EPS); -final Coordinates3D vectorPartRef = ((vectorA.scalarMultiply(qB.getScalarPart())).add(vectorB.scalarMultiply(qA -.getScalarPart(.add(Coordinates3D.crossProduct(vectorA, vectorB)); +final Cartesian3D vectorPartRef = ((vectorA.scalarMultiply(qB.getScalarPart())).add(vectorB.scalarMultiply(qA +.getScalarPart(.add(Cartesian3D.crossProduct(vectorA, vectorB)); final double norm = (vectorResult.subtract(vectorPartRef)).getNorm(); Assert.assertEquals(0, norm, EPS); @@ -167,12 +167,12 @@ public class QuaternionTest { final double[] vectorQ = quaternion.getVectorPart(); final double[] vectorResultQxV = qResultQxV.getVectorPart(); -final double scalarPartRefQxV = -Coordinates3D.dotProduct(new Coordinates3D(vectorQ), new Coordinates3D(vector)); +final double scalarPartRefQxV = -Cartesian3D.dotProduct(new Cartesian3D(vectorQ), new Cartesian3D(vector)); Assert.assertEquals(scalarPartRefQxV, qResultQxV.getScalarPart(), EPS); -final Coordinates3D vectorPartRefQxV = (new Coordinates3D(vector).scalarMultiply(quaternion.getScalarPart())).add(Coordinates3D -.crossProduct(new Coordinates3D(vectorQ), new Coordinates3D(vector))); -final double normQxV = (new Coordinates3D(vectorResultQxV).subtra
[18/19] [math] MATH-1284: Restore Vector3D class as an abstract implementation of Vector and now Cartesian3D extends Vector3D. Restore the public interface of Vector3DFormat to act on Vec
MATH-1284: Restore Vector3D class as an abstract implementation of Vector and now Cartesian3D extends Vector3D. Restore the public interface of Vector3DFormat to act on Vector3D. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/05edf063 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/05edf063 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/05edf063 Branch: refs/heads/feature-MATH-1284 Commit: 05edf06360cc8a1a61fbd1ce5f9abf5d83f9d3f9 Parents: 09c55eb Author: Ray DeCampo Authored: Sat May 6 10:59:17 2017 -0400 Committer: Ray DeCampo Committed: Sat May 6 10:59:17 2017 -0400 -- .../geometry/euclidean/threed/Cartesian3D.java | 2 +- .../geometry/euclidean/threed/Vector3D.java | 46 .../euclidean/threed/Vector3DFormat.java| 20 - .../threed/Vector3DFormatAbstractTest.java | 42 +- 4 files changed, 78 insertions(+), 32 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java index 5dc04c5..3880edf 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java @@ -39,7 +39,7 @@ import org.apache.commons.math4.util.MathUtils; * Instance of this class are guaranteed to be immutable. * @since 4.0 */ -public class Cartesian3D implements Serializable, Point, Vector { +public class Cartesian3D extends Vector3D implements Serializable, Point { /** Null vector (coordinates: 0, 0, 0). */ public static final Cartesian3D ZERO = new Cartesian3D(0, 0, 0); http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java new file mode 100644 index 000..23d644a --- /dev/null +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java @@ -0,0 +1,46 @@ +/* + * 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.math4.geometry.euclidean.threed; + +import org.apache.commons.math4.geometry.Vector; + +/** + * This class implements vectors in a three-dimensional space. + * @since 1.2 + */ +public abstract class Vector3D implements Vector { + +/** Get the abscissa of the vector. + * @return abscissa of the vector + * @see #Cartesian3D(double, double, double) + */ +public abstract double getX(); + +/** Get the ordinate of the vector. + * @return ordinate of the vector + * @see #Cartesian3D(double, double, double) + */ +public abstract double getY(); + +/** Get the height of the vector. + * @return height of the vector + * @see #Cartesian3D(double, double, double) + */ +public abstract double getZ(); + +} http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java index dc2c0f9..1991c53 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java @@ -104,7 +104,7 @@ public
[17/19] [math] MATH-1284: Restore Vector2D class as an abstract implementation of Vector and now Cartesian2D extends Vector2D. Restore the public interface of Vector2DFormat to act on Vec
MATH-1284: Restore Vector2D class as an abstract implementation of Vector and now Cartesian2D extends Vector2D. Restore the public interface of Vector2DFormat to act on Vector2D. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/09c55eb8 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/09c55eb8 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/09c55eb8 Branch: refs/heads/feature-MATH-1284 Commit: 09c55eb8120da36aef1807628f87bde83749428b Parents: 9be91f3 Author: Ray DeCampo Authored: Sat May 6 10:51:16 2017 -0400 Committer: Ray DeCampo Committed: Sat May 6 10:51:16 2017 -0400 -- .../geometry/euclidean/twod/Cartesian2D.java| 2 +- .../math4/geometry/euclidean/twod/Vector2D.java | 38 ++ .../geometry/euclidean/twod/Vector2DFormat.java | 10 ++--- .../twod/Vector2DFormatAbstractTest.java| 42 ++-- 4 files changed, 65 insertions(+), 27 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/09c55eb8/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java index 51109d0..7e68362 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java @@ -36,7 +36,7 @@ import org.apache.commons.math4.util.MathUtils; * Instances of this class are guaranteed to be immutable. * @since 4.0 */ -public class Cartesian2D implements Point, Vector { +public class Cartesian2D extends Vector2D implements Point { /** Origin (coordinates: 0, 0). */ public static final Cartesian2D ZERO = new Cartesian2D(0, 0); http://git-wip-us.apache.org/repos/asf/commons-math/blob/09c55eb8/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java new file mode 100644 index 000..4a2a398 --- /dev/null +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java @@ -0,0 +1,38 @@ +/* + * 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.math4.geometry.euclidean.twod; + +import org.apache.commons.math4.geometry.Vector; + +/** This class represents a 2D vector. + * @since 3.0 + */ +public abstract class Vector2D implements Vector { + +/** Get the abscissa of the vector. + * @return abscissa of the vector + * @see #Vector2D(double, double) + */ +public abstract double getX(); + +/** Get the ordinate of the vector. + * @return ordinate of the vector + * @see #Vector2D(double, double) + */ +public abstract double getY(); + +} http://git-wip-us.apache.org/repos/asf/commons-math/blob/09c55eb8/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java index 936450a..cb76596 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java @@ -108,26 +108,26 @@ public class Vector2DFormat extends VectorFormat { @Override public StringBuffer format(final Vector vector, final StringBuffer toAppendTo, final FieldPosition pos) { -final Cartesian2D p2 = (Cartesian2D) vector; +final Vector2D p2 = (Vector2D) v
[13/19] [math] MATH-1284: Replace uses of "Vector2D" in comments and supporting files with "Cartesian2D".
MATH-1284: Replace uses of "Vector2D" in comments and supporting files with "Cartesian2D". Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/c7d20472 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/c7d20472 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/c7d20472 Branch: refs/heads/feature-MATH-1284 Commit: c7d20472de0dad34bce9483557f43c524e4f3e16 Parents: a398481 Author: Ray DeCampo Authored: Thu May 4 07:25:15 2017 -0400 Committer: Ray DeCampo Committed: Thu May 4 07:25:15 2017 -0400 -- .../geometry/euclidean/twod/Cartesian2D.java| 6 +- .../math4/geometry/euclidean/twod/Line.java | 4 +- .../geometry/euclidean/twod/NestedLoops.java| 2 +- src/site/design/twoD.puml | 4 +- src/site/xdoc/userguide/geometry.xml| 4 +- src/site/xdoc/userguide/leastsquares.xml| 20 +- .../euclidean/twod/Cartesian2DTest.java | 235 +++ .../geometry/euclidean/twod/Vector2DTest.java | 235 --- .../userguide/ClusterAlgorithmComparison.java | 40 ++-- .../LowDiscrepancyGeneratorComparison.java | 43 ++-- .../userguide/geometry/GeometryExample.java | 36 +-- 11 files changed, 314 insertions(+), 315 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/c7d20472/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java index 0272322..51109d0 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java @@ -149,7 +149,7 @@ public class Cartesian2D implements Point, Vector { /** Get the abscissa of the vector. * @return abscissa of the vector - * @see #Vector2D(double, double) + * @see #Cartesian2D(double, double) */ public double getX() { return x; @@ -157,7 +157,7 @@ public class Cartesian2D implements Point, Vector { /** Get the ordinate of the vector. * @return ordinate of the vector - * @see #Vector2D(double, double) + * @see #Cartesian2D(double, double) */ public double getY() { return y; @@ -165,7 +165,7 @@ public class Cartesian2D implements Point, Vector { /** Get the vector coordinates as a dimension 2 array. * @return vector coordinates - * @see #Vector2D(double[]) + * @see #Cartesian2D(double[]) */ public double[] toArray() { return new double[] { x, y }; http://git-wip-us.apache.org/repos/asf/commons-math/blob/c7d20472/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java index 36f0998..561cdc7 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java @@ -202,8 +202,8 @@ public class Line implements Hyperplane, Embedding * * As long as neither the instance nor its reverse are modified - * (i.e. as long as none of the {@link #reset(Vector2D, Vector2D)}, - * {@link #reset(Vector2D, double)}, {@link #revertSelf()}, + * (i.e. as long as none of the {@link #reset(Cartesian2D, Cartesian2D)}, + * {@link #reset(Cartesian2D, double)}, {@link #revertSelf()}, * {@link #setAngle(double)} or {@link #setOriginOffset(double)} * methods are called), then the line and its reverse remain linked * together so that {@code line.getReverse().getReverse() == line}. http://git-wip-us.apache.org/repos/asf/commons-math/blob/c7d20472/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java index 3a5038e..dcfc76a 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java @@ -165,7 +165,7 @@ class NestedLoops { /** Correct the orientation of the loops contained in the tree. * This is this method that really inverts the loops that where - * provided
[09/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java index ff8f17e..63e7017 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java @@ -48,8 +48,8 @@ import org.apache.commons.math4.util.MathArrays; * Focus is oriented on what a rotation do rather than on its * underlying representation. Once it has been built, and regardless of its * internal representation, a rotation is an operator which basically - * transforms three dimensional {@link Coordinates3D vectors} into other three - * dimensional {@link Coordinates3D vectors}. Depending on the application, the + * transforms three dimensional {@link Cartesian3D vectors} into other three + * dimensional {@link Cartesian3D vectors}. Depending on the application, the * meaning of these vectors may vary and the semantics of the rotation also. * For example in an spacecraft attitude simulation tool, users will often * consider the vectors are fixed (say the Earth direction for example) and the @@ -88,7 +88,7 @@ import org.apache.commons.math4.util.MathArrays; * * Rotations are guaranteed to be immutable objects. * - * @see Coordinates3D + * @see Cartesian3D * @see RotationOrder * @since 1.2 */ @@ -162,7 +162,7 @@ public class Rotation implements Serializable { * @deprecated as of 3.6, replaced with {@link #Rotation(Vector3D, double, RotationConvention)} */ @Deprecated - public Rotation(Coordinates3D axis, double angle) throws MathIllegalArgumentException { + public Rotation(Cartesian3D axis, double angle) throws MathIllegalArgumentException { this(axis, angle, RotationConvention.VECTOR_OPERATOR); } @@ -173,7 +173,7 @@ public class Rotation implements Serializable { * @exception MathIllegalArgumentException if the axis norm is zero * @since 3.6 */ - public Rotation(final Coordinates3D axis, final double angle, final RotationConvention convention) + public Rotation(final Cartesian3D axis, final double angle, final RotationConvention convention) throws MathIllegalArgumentException { double norm = axis.getNorm(); @@ -272,18 +272,18 @@ public class Rotation implements Serializable { * @exception MathArithmeticException if the norm of one of the vectors is zero, * or if one of the pair is degenerated (i.e. the vectors of the pair are collinear) */ - public Rotation(Coordinates3D u1, Coordinates3D u2, Coordinates3D v1, Coordinates3D v2) + public Rotation(Cartesian3D u1, Cartesian3D u2, Cartesian3D v1, Cartesian3D v2) throws MathArithmeticException { // build orthonormalized base from u1, u2 // this fails when vectors are null or collinear, which is forbidden to define a rotation - final Coordinates3D u3 = u1.crossProduct(u2).normalize(); + final Cartesian3D u3 = u1.crossProduct(u2).normalize(); u2 = u3.crossProduct(u1).normalize(); u1 = u1.normalize(); // build an orthonormalized base from v1, v2 // this fails when vectors are null or collinear, which is forbidden to define a rotation - final Coordinates3D v3 = v1.crossProduct(v2).normalize(); + final Cartesian3D v3 = v1.crossProduct(v2).normalize(); v2 = v3.crossProduct(v1).normalize(); v1 = v1.normalize(); @@ -327,7 +327,7 @@ public class Rotation implements Serializable { * @param v desired image of u by the rotation * @exception MathArithmeticException if the norm of one of the vectors is zero */ - public Rotation(Coordinates3D u, Coordinates3D v) throws MathArithmeticException { + public Rotation(Cartesian3D u, Cartesian3D v) throws MathArithmeticException { double normProduct = u.getNorm() * v.getNorm(); if (normProduct == 0) { @@ -339,7 +339,7 @@ public class Rotation implements Serializable { if (dot < ((2.0e-15 - 1.0) * normProduct)) { // special case u = -v: we select a PI angle rotation around // an arbitrary vector orthogonal to u - Coordinates3D w = u.orthogonal(); + Cartesian3D w = u.orthogonal(); q0 = 0.0; q1 = -w.getX(); q2 = -w.getY(); @@ -349,7 +349,7 @@ public class Rotation implements Serializable { // the shortest possible rotation: axis orthogonal to this plane q0 = FastMath.sqrt(0.5 * (1.0 + dot / normProduct)); double coeff = 1.0 / (2.0 * q0 * normProduct); - Coordinates3D q = v.crossProduct(u); + Cartesian3D q = v.crossProduct(u); q1 = coeff * q.getX(); q2 = coeff * q.getY(); q3 = coeff * q.getZ(); @@ -522,7 +522,7 @@ public
[14/19] [math] MATH-1284: Replace uses of Vector3D in user guide with Cartesian2D.
MATH-1284: Replace uses of Vector3D in user guide with Cartesian2D. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/e508ad09 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/e508ad09 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/e508ad09 Branch: refs/heads/feature-MATH-1284 Commit: e508ad09d79302d3cc6b86077d4a6ddb0679a0f5 Parents: c7d2047 Author: Ray DeCampo Authored: Thu May 4 07:27:37 2017 -0400 Committer: Ray DeCampo Committed: Thu May 4 07:27:37 2017 -0400 -- .../math4/userguide/sofm/ChineseRings.java | 20 ++-- .../userguide/sofm/ChineseRingsClassifier.java | 10 +- 2 files changed, 15 insertions(+), 15 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/e508ad09/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java -- diff --git a/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java b/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java index 57393a6..a497da6 100644 --- a/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java +++ b/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.userguide.sofm; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator; import org.apache.commons.math4.distribution.RealDistribution; @@ -32,7 +32,7 @@ import org.apache.commons.math4.distribution.UniformRealDistribution; */ public class ChineseRings { /** Points in the two rings. */ -private final Vector3D[] points; +private final Cartesian3D[] points; /** * @param orientationRing1 Vector othogonal to the plane containing the @@ -44,7 +44,7 @@ public class ChineseRings { * @param numPointsRing1 Number of points in the first ring. * @param numPointsRing2 Number of points in the second ring. */ -public ChineseRings(Vector3D orientationRing1, +public ChineseRings(Cartesian3D orientationRing1, double radiusRing1, double halfWidthRing1, double radiusRing2, @@ -52,9 +52,9 @@ public class ChineseRings { int numPointsRing1, int numPointsRing2) { // First ring (centered at the origin). -final Vector3D[] firstRing = new Vector3D[numPointsRing1]; +final Cartesian3D[] firstRing = new Cartesian3D[numPointsRing1]; // Second ring (centered around the first ring). -final Vector3D[] secondRing = new Vector3D[numPointsRing2]; +final Cartesian3D[] secondRing = new Cartesian3D[numPointsRing2]; // Create two rings lying in xy-plane. final UnitSphereRandomVectorGenerator unit @@ -72,7 +72,7 @@ public class ChineseRings { final double[] v = unit.nextVector(); final double r = radius1.sample(); // First ring is in the xy-plane, centered at (0, 0, 0). -firstRing[i] = new Vector3D(v[0] * r, +firstRing[i] = new Cartesian3D(v[0] * r, v[1] * r, widthRing1.sample()); } @@ -87,16 +87,16 @@ public class ChineseRings { final double[] v = unit.nextVector(); final double r = radius2.sample(); // Second ring is in the xz-plane, centered at (radiusRing1, 0, 0). -secondRing[i] = new Vector3D(radiusRing1 + v[0] * r, +secondRing[i] = new Cartesian3D(radiusRing1 + v[0] * r, widthRing2.sample(), v[1] * r); } // Move first and second rings into position. -final Rotation rot = new Rotation(Vector3D.PLUS_K, +final Rotation rot = new Rotation(Cartesian3D.PLUS_K, orientationRing1.normalize()); int count = 0; -points = new Vector3D[numPointsRing1 + numPointsRing2]; +points = new Cartesian3D[numPointsRing1 + numPointsRing2]; for (int i = 0; i < numPointsRing1; i++) { points[count++] = rot.applyTo(firstRing[i]); } @@ -108,7 +108,7 @@ public class ChineseRings { /** * Gets all the points. */ -public Vecto
[10/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java index a05ab8e..6392e3f 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java @@ -820,8 +820,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusK) coordinates are : // sin (theta), -sin (phi) cos (theta), cos (phi) cos (theta) // and we can choose to have theta in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_I); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_K); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_I); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_K); if ((v2.getX().getReal() < -0.99) || (v2.getX().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -836,8 +836,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusJ) coordinates are : // -sin (psi), cos (phi) cos (psi), sin (phi) cos (psi) // and we can choose to have psi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_I); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_J); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_I); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_J); if ((v2.getX().getReal() < -0.99) || (v2.getX().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -852,8 +852,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusK) coordinates are : // sin (theta) cos (phi), -sin (phi), cos (theta) cos (phi) // and we can choose to have phi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_J); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_K); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_J); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_K); if ((v2.getY().getReal() < -0.99) || (v2.getY().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -868,8 +868,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusI) coordinates are : // cos (theta) cos (psi), sin (psi), -sin (theta) cos (psi) // and we can choose to have psi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_J); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_I); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_J); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_I); if ((v2.getY().getReal() < -0.99) || (v2.getY().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -884,8 +884,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusJ) coordinates are : // -sin (psi) cos (phi), cos (psi) cos (phi), sin (phi) // and we can choose to have phi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_K); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_J); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_K); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_J); if ((v2.getZ().getReal() < -0.99) || (v2.getZ().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -900,8 +900,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusI) coordinates are : // cos (psi) cos (theta), sin (psi) cos (theta), -sin (theta) // and we can choose to have theta in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_K); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_I); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_K); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
[04/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java index 296ade8..a0e9f59 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.geometry.Space; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.util.FastMath; @@ -39,27 +39,27 @@ public class Vector3DTest { @Test public void testConstructors() throws DimensionMismatchException { double r = FastMath.sqrt(2) /2; -checkVector(new Coordinates3D(2, new Coordinates3D(FastMath.PI / 3, -FastMath.PI / 4)), +checkVector(new Cartesian3D(2, new Cartesian3D(FastMath.PI / 3, -FastMath.PI / 4)), r, r * FastMath.sqrt(3), -2 * r); -checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, - -3, Coordinates3D.MINUS_K), +checkVector(new Cartesian3D(2, Cartesian3D.PLUS_I, + -3, Cartesian3D.MINUS_K), 2, 0, 3); -checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, - 5, Coordinates3D.PLUS_J, - -3, Coordinates3D.MINUS_K), +checkVector(new Cartesian3D(2, Cartesian3D.PLUS_I, + 5, Cartesian3D.PLUS_J, + -3, Cartesian3D.MINUS_K), 2, 5, 3); -checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, - 5, Coordinates3D.PLUS_J, - 5, Coordinates3D.MINUS_J, - -3, Coordinates3D.MINUS_K), +checkVector(new Cartesian3D(2, Cartesian3D.PLUS_I, + 5, Cartesian3D.PLUS_J, + 5, Cartesian3D.MINUS_J, + -3, Cartesian3D.MINUS_K), 2, 0, 3); -checkVector(new Coordinates3D(new double[] { 2, 5, -3 }), +checkVector(new Cartesian3D(new double[] { 2, 5, -3 }), 2, 5, -3); } @Test public void testSpace() { -Space space = new Coordinates3D(1, 2, 2).getSpace(); +Space space = new Cartesian3D(1, 2, 2).getSpace(); Assert.assertEquals(3, space.getDimension()); Assert.assertEquals(2, space.getSubSpace().getDimension()); Space deserialized = (Space) TestUtils.serializeAndRecover(space); @@ -68,63 +68,63 @@ public class Vector3DTest { @Test public void testZero() { -Assert.assertEquals(0, new Coordinates3D(1, 2, 2).getZero().getNorm(), 1.0e-15); +Assert.assertEquals(0, new Cartesian3D(1, 2, 2).getZero().getNorm(), 1.0e-15); } @Test public void testEquals() { -Coordinates3D u1 = new Coordinates3D(1, 2, 3); -Coordinates3D u2 = new Coordinates3D(1, 2, 3); +Cartesian3D u1 = new Cartesian3D(1, 2, 3); +Cartesian3D u2 = new Cartesian3D(1, 2, 3); Assert.assertTrue(u1.equals(u1)); Assert.assertTrue(u1.equals(u2)); Assert.assertFalse(u1.equals(new Rotation(1, 0, 0, 0, false))); -Assert.assertFalse(u1.equals(new Coordinates3D(1, 2, 3 + 10 * Precision.EPSILON))); -Assert.assertFalse(u1.equals(new Coordinates3D(1, 2 + 10 * Precision.EPSILON, 3))); -Assert.assertFalse(u1.equals(new Coordinates3D(1 + 10 * Precision.EPSILON, 2, 3))); -Assert.assertTrue(new Coordinates3D(0, Double.NaN, 0).equals(new Coordinates3D(0, 0, Double.NaN))); +Assert.assertFalse(u1.equals(new Cartesian3D(1, 2, 3 + 10 * Precision.EPSILON))); +Assert.assertFalse(u1.equals(new Cartesian3D(1, 2 + 10 * Precision.EPSILON, 3))); +Assert.assertFalse(u1.equals(new Cartesian3D(1 + 10 * Precision.EPSILON, 2, 3))); +Assert.assertTrue(new Cartesian3D(0, Double.NaN, 0).equals(new Cartesian3D(0, 0, Double.NaN))); } @Test public void testHash() { -Assert.assertEquals(new Coordinates3D(0, Double.NaN, 0).hashCode(), new Coordinates3D(0, 0, Double.NaN).hashCode()); -Coordinates
[06/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java index 7728b96..02c059e 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.util.FastMath; @@ -59,7 +59,7 @@ public class FieldVector3DTest { createVector(1, 0, 0, 4)), 2, 0, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, 0, 2, 0); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0)), + new Cartesian3D(1, 0, 0)), 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -71,9 +71,9 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 0, 3, -1, 0, 0, 1, 0, -1, 0, 0, 0, 0, -1, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0), + new Cartesian3D(1, 0, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Coordinates3D(0, 0, -1)), + new Cartesian3D(0, 0, -1)), 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -88,11 +88,11 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 5, 3, 4, 0, 0, 1, 0, 4, 0, 1, 0, 0, 4, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0), + new Cartesian3D(1, 0, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Coordinates3D(0, 1, 0), + new Cartesian3D(0, 1, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Coordinates3D(0, 0, -1)), + new Cartesian3D(0, 0, -1)), 2, 5, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -1); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -110,13 +110,13 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 0, 3, 9, 0, 0, 1, 0, 9, 0, 0, 0, 0, 9, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0), + new Cartesian3D(1, 0, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Coordinates3D(0, 1, 0), + new Cartesian3D(0, 1, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Coordinates3D(0, -1, 0), + new Cartesian3D(0, -1, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Coordinates3D(0, 0, -1)), + new Cartesian3D(0, 0, -1)), 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1); checkVector(new FieldVector3D<>(new DerivativeStructure[] { @@ -270,12 +270,12 @@ public class FieldVector3DTest { Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals(0,
[16/19] [math] MATH-1284: Restore Vector1D class as an abstract implementation of Vector and now Cartesian1D extends Vector1D. Restore the public interface of Vector1DFormat to act on Vec
MATH-1284: Restore Vector1D class as an abstract implementation of Vector and now Cartesian1D extends Vector1D. Restore the public interface of Vector1DFormat to act on Vector1D. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/9be91f38 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/9be91f38 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/9be91f38 Branch: refs/heads/feature-MATH-1284 Commit: 9be91f380c209f895da36d13c40b99687bb4c8c1 Parents: a27ca51 Author: Ray DeCampo Authored: Sat May 6 10:45:00 2017 -0400 Committer: Ray DeCampo Committed: Sat May 6 10:45:00 2017 -0400 -- .../geometry/euclidean/oned/Cartesian1D.java| 3 +- .../math4/geometry/euclidean/oned/Vector1D.java | 33 +++ .../geometry/euclidean/oned/Vector1DFormat.java | 10 ++--- .../oned/Vector1DFormatAbstractTest.java| 44 ++-- 4 files changed, 62 insertions(+), 28 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/9be91f38/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java index f406125..de3f7d2 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java @@ -34,7 +34,7 @@ import org.apache.commons.math4.util.MathUtils; * Instances of this class are guaranteed to be immutable. * @since 4.0 */ -public class Cartesian1D implements Point, Vector { +public class Cartesian1D extends Vector1D implements Point { /** Origin (coordinates: 0). */ public static final Cartesian1D ZERO = new Cartesian1D(0.0); @@ -128,6 +128,7 @@ public class Cartesian1D implements Point, Vector { * @return abscissa of the vector * @see #Cartesian1D(double) */ +@Override public double getX() { return x; } http://git-wip-us.apache.org/repos/asf/commons-math/blob/9be91f38/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java new file mode 100644 index 000..f35c81f --- /dev/null +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1D.java @@ -0,0 +1,33 @@ +/* + * 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.math4.geometry.euclidean.oned; + +import org.apache.commons.math4.geometry.Vector; + +/** This class represents a 1D vector. + * + * @since 3.0 + */ +public abstract class Vector1D implements Vector { + +/** Get the abscissa of the vector. + * @return abscissa of the vector + * @see #Vector1D(double) + */ +public abstract double getX(); + +} http://git-wip-us.apache.org/repos/asf/commons-math/blob/9be91f38/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java index c5cead3..911d6f4 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Vector1DFormat.java @@ -105,26 +105,26 @@ public class Vector1DFormat extends VectorFormat { @Override public StringBuffer format(final Vector vector, final StringBuffer toAppendTo, final FieldPosition pos) { -final Cartesian1D p1 = (Cartesian1D) vec
[03/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java index 01bfdb3..0419585 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java @@ -22,12 +22,12 @@ import java.util.List; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.geometry.euclidean.oned.Interval; import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; -import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D; +import org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D; import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.PolygonsSet; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; +import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D; import org.apache.commons.math4.geometry.partitioning.BSPTree; import org.apache.commons.math4.geometry.partitioning.BSPTreeVisitor; import org.apache.commons.math4.geometry.partitioning.BoundaryProjection; @@ -44,41 +44,41 @@ public class PolygonsSetTest { @Test public void testSimplyConnected() { -Coordinates2D[][] vertices = new Coordinates2D[][] { -new Coordinates2D[] { -new Coordinates2D(36.0, 22.0), -new Coordinates2D(39.0, 32.0), -new Coordinates2D(19.0, 32.0), -new Coordinates2D( 6.0, 16.0), -new Coordinates2D(31.0, 10.0), -new Coordinates2D(42.0, 16.0), -new Coordinates2D(34.0, 20.0), -new Coordinates2D(29.0, 19.0), -new Coordinates2D(23.0, 22.0), -new Coordinates2D(33.0, 25.0) +Cartesian2D[][] vertices = new Cartesian2D[][] { +new Cartesian2D[] { +new Cartesian2D(36.0, 22.0), +new Cartesian2D(39.0, 32.0), +new Cartesian2D(19.0, 32.0), +new Cartesian2D( 6.0, 16.0), +new Cartesian2D(31.0, 10.0), +new Cartesian2D(42.0, 16.0), +new Cartesian2D(34.0, 20.0), +new Cartesian2D(29.0, 19.0), +new Cartesian2D(23.0, 22.0), +new Cartesian2D(33.0, 25.0) } }; PolygonsSet set = buildSet(vertices); -Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Coordinates2D(50.0, 30.0))); -checkPoints(Region.Location.INSIDE, set, new Coordinates2D[] { -new Coordinates2D(30.0, 15.0), -new Coordinates2D(15.0, 20.0), -new Coordinates2D(24.0, 25.0), -new Coordinates2D(35.0, 30.0), -new Coordinates2D(19.0, 17.0) +Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Cartesian2D(50.0, 30.0))); +checkPoints(Region.Location.INSIDE, set, new Cartesian2D[] { +new Cartesian2D(30.0, 15.0), +new Cartesian2D(15.0, 20.0), +new Cartesian2D(24.0, 25.0), +new Cartesian2D(35.0, 30.0), +new Cartesian2D(19.0, 17.0) }); -checkPoints(Region.Location.OUTSIDE, set, new Coordinates2D[] { -new Coordinates2D(50.0, 30.0), -new Coordinates2D(30.0, 35.0), -new Coordinates2D(10.0, 25.0), -new Coordinates2D(10.0, 10.0), -new Coordinates2D(40.0, 10.0), -new Coordinates2D(50.0, 15.0), -new Coordinates2D(30.0, 22.0) +checkPoints(Region.Location.OUTSIDE, set, new Cartesian2D[] { +new Cartesian2D(50.0, 30.0), +new Cartesian2D(30.0, 35.0), +new Cartesian2D(10.0, 25.0), +new Cartesian2D(10.0, 10.0), +new Cartesian2D(40.0, 10.0), +new Cartesian2D(50.0, 15.0), +new Cartesian2D(30.0, 22.0) }); -checkPoints(Region.Location.BOUNDARY, set, new Coordinates2D[] { -new Coordinates2D(30.0, 32.0), -new Coordinates2D(34.0, 20.0) +checkPoints(Region.Location.BOUNDARY, set, new Cartesian2D[] { +new Cartesian2D(30.0, 32.0), +new Cartesian2D(34.0, 20.0) }); checkVertices(set.getVertices(), vertices); } @@ -98,18 +98,18 @@ public class PolygonsSetTest { @Test public void testStair() { -Coordinates2D[][] ver
[08/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java index 7df7277..36f0998 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java @@ -19,10 +19,11 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.exception.util.LocalizedFormats; import org.apache.commons.math4.geometry.Point; +import org.apache.commons.math4.geometry.Vector; import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.oned.OrientedPoint; -import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D; +import org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D; import org.apache.commons.math4.geometry.partitioning.Embedding; import org.apache.commons.math4.geometry.partitioning.Hyperplane; import org.apache.commons.math4.geometry.partitioning.SubHyperplane; @@ -84,7 +85,7 @@ public class Line implements Hyperplane, Embedding, Embedding, Embedding, Embedding, Embedding vector) { -//return toSubSpace((Point) vector); -//} +public Cartesian1D toSubSpace(Vector vector) { +return toSubSpace((Cartesian2D) vector); +} /** Transform a sub-space point into a space point. * @param vector (n-1)-dimension point of the sub-space * @return n-dimension point of the space corresponding to the * specified sub-space point */ -//public Coordinates2D toSpace(Vector vector) { -//return toSpace((Point) vector); -//} +public Cartesian2D toSpace(Vector vector) { +return toSpace((Cartesian1D) vector); +} /** {@inheritDoc} */ @Override -public Coordinates1D toSubSpace(final Point point) { -Coordinates2D p2 = (Coordinates2D) point; -return new Coordinates1D(MathArrays.linearCombination(cos, p2.getX(), sin, p2.getY())); +public Cartesian1D toSubSpace(final Point point) { +return toSubSpace((Cartesian2D) point); } /** {@inheritDoc} */ @Override -public Coordinates2D toSpace(final Point point) { -final double abscissa = ((Coordinates1D) point).getX(); -return new Coordinates2D(MathArrays.linearCombination(abscissa, cos, -originOffset, sin), +public Cartesian2D toSpace(final Point point) { +return toSpace((Cartesian1D) point); +} + +/** Transform a space point into a sub-space point. + * @param cartesian n-dimension point of the space + * @return (n-1)-dimension point of the sub-space corresponding to + * the specified space point + */ +public Cartesian1D toSubSpace(final Cartesian2D cartesian) { +return new Cartesian1D(MathArrays.linearCombination(cos, cartesian.getX(), sin, cartesian.getY())); +} + +/** Transform a sub-space point into a space point. + * @param cartesian (n-1)-dimension point of the sub-space + * @return n-dimension point of the space corresponding to the + * specified sub-space point + */ +public Cartesian2D toSpace(Cartesian1D cartesian) { +final double abscissa = cartesian.getX(); +return new Cartesian2D(MathArrays.linearCombination(abscissa, cos, -originOffset, sin), MathArrays.linearCombination(abscissa, sin, originOffset, cos)); } @@ -258,12 +276,12 @@ public class Line implements Hyperplane, Embedding, Embedding vector) { -//return getOffset((Point) vector); -//} +public double getOffset(Vector vector) { +return getOffset((Cartesian2D) vector); +} /** {@inheritDoc} */ @Override public double getOffset(final Point point) { -Coordinates2D p2 = (Coordinates2D) point; -return MathArrays.linearCombination(sin, p2.getX(), -cos, p2.getY(), 1.0, originOffset); +return getOffset((Cartesian2D) point); +} + +/** Get the offset (oriented distance) of a point. + * @param cartesian point to check + * @return offset of the point + */ +public double getOffset(Cartesian2D cartesian) { +return MathArrays.linearCombination(sin, cartesian.getX(), -cos, cartesian.getY(), 1.0, originOffset); } /** {@inheritDoc} */ @@ -341,10 +366,10 @@ public class Line implements Hyperplane, Embedding, Embedding, Embedding, Embedding, Embedding, Embedding point) { -final Coordinates2D p2D = (Coordinates2D) point; +public Cartesian2D apply(final Poin
[12/19] [math] MATH-1284: Replace uses of "Vector3D" in comments and supporting files with "Cartesian3D".
MATH-1284: Replace uses of "Vector3D" in comments and supporting files with "Cartesian3D". Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a3984815 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a3984815 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a3984815 Branch: refs/heads/feature-MATH-1284 Commit: a3984815ebf24df07c2add09fbf0069f54666a20 Parents: e21d4d4 Author: Ray DeCampo Authored: Sun Apr 30 08:26:36 2017 -0400 Committer: Ray DeCampo Committed: Sun Apr 30 08:26:36 2017 -0400 -- findbugs-exclude-filter.xml | 6 +- .../geometry/euclidean/threed/Cartesian3D.java | 24 ++-- .../euclidean/threed/FieldRotation.java | 48 .../euclidean/threed/FieldVector3D.java | 14 +-- .../geometry/euclidean/threed/Rotation.java | 110 +-- .../euclidean/threed/RotationConvention.java| 16 +-- .../math4/geometry/partitioning/Embedding.java | 2 +- .../math4/geometry/spherical/twod/Circle.java | 4 +- .../spherical/twod/SphericalPolygonsSet.java| 2 +- src/site/design/threeD.puml | 4 +- src/site/xdoc/userguide/geometry.xml| 12 +- 11 files changed, 121 insertions(+), 121 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3984815/findbugs-exclude-filter.xml -- diff --git a/findbugs-exclude-filter.xml b/findbugs-exclude-filter.xml index 86d0087..7a90945 100644 --- a/findbugs-exclude-filter.xml +++ b/findbugs-exclude-filter.xml @@ -81,9 +81,9 @@ - - - + + + http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3984815/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java index 85696f6..5dc04c5 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java @@ -196,7 +196,7 @@ public class Cartesian3D implements Serializable, Point, Vector, Vector, Vector, Vector, Vector, Vector, Vector - * Vector3D k = u.normalize(); - * Vector3D i = k.orthogonal(); - * Vector3D j = Vector3D.crossProduct(k, i); + * Cartesian3D k = u.normalize(); + * Cartesian3D i = k.orthogonal(); + * Cartesian3D j = Cartesian3D.crossProduct(k, i); * * @return a new normalized vector orthogonal to the instance * @exception MathArithmeticException if the norm of the instance is null @@ -423,8 +423,8 @@ public class Cartesian3D implements Serializable, Point, Vector, Vector v) { final Cartesian3D v3 = (Cartesian3D) v; http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3984815/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java index 6392e3f..d3853c0 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java @@ -815,9 +815,9 @@ public class FieldRotation> implements Serializabl } else { if (order == RotationOrder.XYZ) { -// r (Vector3D.plusI) coordinates are : +// r (Cartesian3D.plusI) coordinates are : // cos (theta) cos (psi), -cos (theta) sin (psi), sin (theta) -// (-r) (Vector3D.plusK) coordinates are : +// (-r) (Cartesian3D.plusK) coordinates are : // sin (theta), -sin (phi) cos (theta), cos (phi) cos (theta) // and we can choose to have theta in the interval [-PI/2 ; +PI/2] FieldVector3D v1 = applyTo(Cartesian3D.PLUS_I); @@ -831,9 +831,9 @@ public class FieldRotation> implements Serializabl } else if (order == RotationOrder.XZY) { -// r (Vector3D.plusI) coordinates are : +// r (Cartesian3D.plusI) coordinates are : // cos (psi) cos (theta), -sin (psi), cos (psi) sin (theta) -// (-r) (Vector3D.plusJ) coordinates are : +// (-r) (Cartesian3D.plusJ) coordinates are : // -
[02/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java index 41f9d77..cbbd003 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; -import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; +import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D; import org.apache.commons.math4.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -27,20 +27,20 @@ public class SegmentTest { @Test public void testDistance() { -Coordinates2D start = new Coordinates2D(2, 2); -Coordinates2D end = new Coordinates2D(-2, -2); +Cartesian2D start = new Cartesian2D(2, 2); +Cartesian2D end = new Cartesian2D(-2, -2); Segment segment = new Segment(start, end, new Line(start, end, 1.0e-10)); // distance to center of segment -Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Coordinates2D(1, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Cartesian2D(1, -1)), 1.0e-10); // distance a point on segment -Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Coordinates2D(0, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Cartesian2D(0, -1)), 1.0e-10); // distance to end point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, 4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Cartesian2D(0, 4)), 1.0e-10); // distance to start point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, -4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Cartesian2D(0, -4)), 1.0e-10); } } http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java index c59ab8c..cdfc2c0 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; +import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D; import org.apache.commons.math4.geometry.partitioning.RegionFactory; import org.junit.Assert; import org.junit.Test; @@ -32,19 +32,19 @@ public class SubLineTest { @Test public void testEndPoints() { -Coordinates2D p1 = new Coordinates2D(-1, -7); -Coordinates2D p2 = new Coordinates2D(7, -1); +Cartesian2D p1 = new Cartesian2D(-1, -7); +Cartesian2D p2 = new Cartesian2D(7, -1); Segment segment = new Segment(p1, p2, new Line(p1, p2, 1.0e-10)); SubLine sub = new SubLine(segment); List segments = sub.getSegments(); Assert.assertEquals(1, segments.size()); -Assert.assertEquals(0.0, new Coordinates2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); -Assert.assertEquals(0.0, new Coordinates2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); +Assert.assertEquals(0.0, new Cartesian2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); +Assert.assertEquals(0.0, new Cartesian2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); } @Test public void testNoEndPoints() { -SubLine wholeLine = new Line(new Coordinates2D(-1, 7), new Coordinates2D(7, 1), 1.0e-10).wholeHyperplane(); +SubLine wholeLine = new Line(new Cartesian2D(-1, 7), new Cartesian2D(7, 1), 1.0e-10).wholeHyperplane(); List segments = wholeLine.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getX())
[05/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java index a2ebce8..a02ac26 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.CardanEulerSingularity import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.math4.util.FastMath; import org.apache.commons.math4.util.MathUtils; import org.junit.Assert; @@ -36,21 +36,21 @@ public class RotationTest { public void testIdentity() { Rotation r = Rotation.IDENTITY; -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_I); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_K); checkAngle(r.getAngle(), 0); r = new Rotation(-1, 0, 0, 0, false); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_I); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_K); checkAngle(r.getAngle(), 0); r = new Rotation(42, 0, 0, 0, true); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_I); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_K); checkAngle(r.getAngle(), 0); } @@ -59,95 +59,95 @@ public class RotationTest { @Deprecated public void testAxisAngleDeprecated() throws MathIllegalArgumentException { -Rotation r = new Rotation(new Coordinates3D(10, 10, 10), 2 * FastMath.PI / 3); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_K); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_I); +Rotation r = new Rotation(new Cartesian3D(10, 10, 10), 2 * FastMath.PI / 3); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_I); double s = 1 / FastMath.sqrt(3); -checkVector(r.getAxis(), new Coordinates3D(s, s, s)); +checkVector(r.getAxis(), new Cartesian3D(s, s, s)); checkAngle(r.getAngle(), 2 * FastMath.PI / 3); try { - new Rotation(new Coordinates3D(0, 0, 0), 2 * FastMath.PI / 3); + new Rotation(new Cartesian3D(0, 0, 0), 2 * FastMath.PI / 3); Assert.fail("an exception should have been thrown"); } catch (MathIllegalArgumentException e) { } -r = new Rotation(Coordinates3D.PLUS_K, 1.5 * FastMath.PI); -checkVector(r.getAxis(), new Coordinates3D(0, 0, -1)); +r = new Rotation(Cartesian3D.PLUS_K, 1.5 * FastMath.PI); +checkVector(r.getAxis(), new Cartesian3D(0, 0, -1)); checkAngle(r.getAngle(), 0.5 * FastMath.PI); -r = new Rotation(Coordinates3D.PLUS_J, FastMath.PI); -checkVector(r.getAxis(), Coordinates3D.PLUS_J); +r = new Rotation(Cartesian3D.PLUS_J, FastMath.PI); +checkVector(r.getAxis(), Cartesian3D.PLUS_J); checkAngle(r.getAngle(), FastMath.PI); -checkVector(Rotation.IDENTITY.getAxis(), Coordinates3D.PLUS_I); +checkVector(Rotation.IDENTITY.getAxis(), Cartesian3D.PLUS_I); } @Test public void testAxisAngleVectorOperator() throws MathIllegalArgumentException { -Rotation r = new Rotation(new Coordinates3D(10, 10, 10), 2 * FastMath.PI / 3, RotationConvention.VECTOR_OPERATOR); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordi
[11/19] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Point, add a disambiguating method accepting a Cartesian?D. Eliminate casts where possible. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/e21d4d43 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/e21d4d43 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/e21d4d43 Branch: refs/heads/feature-MATH-1284 Commit: e21d4d436b51d88f9554751982cd7b8552854c49 Parents: b815d2a Author: Ray DeCampo Authored: Sat Apr 29 20:29:29 2017 -0400 Committer: Ray DeCampo Committed: Sat Apr 29 20:29:29 2017 -0400 -- .../geometry/euclidean/oned/Cartesian1D.java| 386 ++ .../geometry/euclidean/oned/Coordinates1D.java | 386 -- .../geometry/euclidean/oned/IntervalsSet.java | 18 +- .../geometry/euclidean/oned/OrientedPoint.java |8 +- .../geometry/euclidean/oned/Vector1DFormat.java | 12 +- .../geometry/euclidean/threed/Cartesian3D.java | 621 + .../euclidean/threed/Coordinates3D.java | 621 - .../euclidean/threed/FieldRotation.java | 52 +- .../euclidean/threed/FieldVector3D.java | 78 +- .../math4/geometry/euclidean/threed/Line.java | 80 +- .../euclidean/threed/OutlineExtractor.java | 46 +- .../math4/geometry/euclidean/threed/Plane.java | 131 +- .../euclidean/threed/PolyhedronsSet.java| 96 +- .../geometry/euclidean/threed/Rotation.java | 136 +- .../euclidean/threed/RotationOrder.java | 38 +- .../geometry/euclidean/threed/Segment.java | 10 +- .../euclidean/threed/SphereGenerator.java | 22 +- .../euclidean/threed/SphericalCoordinates.java | 10 +- .../geometry/euclidean/threed/SubLine.java | 14 +- .../geometry/euclidean/threed/SubPlane.java | 14 +- .../euclidean/threed/Vector3DFormat.java| 22 +- .../geometry/euclidean/twod/Cartesian2D.java| 492 +++ .../geometry/euclidean/twod/Coordinates2D.java | 492 --- .../geometry/euclidean/twod/DiskGenerator.java | 16 +- .../math4/geometry/euclidean/twod/Line.java | 93 +- .../geometry/euclidean/twod/NestedLoops.java| 12 +- .../geometry/euclidean/twod/PolygonsSet.java| 78 +- .../math4/geometry/euclidean/twod/Segment.java | 14 +- .../math4/geometry/euclidean/twod/SubLine.java | 18 +- .../geometry/euclidean/twod/Vector2DFormat.java | 12 +- .../hull/AbstractConvexHullGenerator2D.java | 10 +- .../twod/hull/AklToussaintHeuristic.java| 34 +- .../euclidean/twod/hull/ConvexHull2D.java | 32 +- .../twod/hull/ConvexHullGenerator2D.java|6 +- .../euclidean/twod/hull/MonotoneChain.java | 28 +- .../math4/geometry/spherical/oned/S1Point.java | 14 +- .../math4/geometry/spherical/twod/Circle.java | 34 +- .../math4/geometry/spherical/twod/Edge.java |4 +- .../geometry/spherical/twod/EdgesBuilder.java | 10 +- .../spherical/twod/PropertiesComputer.java | 30 +- .../math4/geometry/spherical/twod/S2Point.java | 32 +- .../spherical/twod/SphericalPolygonsSet.java| 26 +- .../geometry/spherical/twod/SubCircle.java |4 +- .../commons/math4/complex/QuaternionTest.java | 30 +- ...stractLeastSquaresOptimizerAbstractTest.java |6 +- .../fitting/leastsquares/CircleVectorial.java | 18 +- .../GaussNewtonOptimizerWithSVDTest.java|6 +- .../LevenbergMarquardtOptimizerTest.java|6 +- .../RandomCirclePointGenerator.java | 10 +- .../geometry/enclosing/WelzlEncloser2DTest.java | 56 +- .../geometry/enclosing/WelzlEncloser3DTest.java | 110 +- .../euclidean/oned/IntervalsSetTest.java| 44 +- .../oned/Vector1DFormatAbstractTest.java| 69 +- .../geometry/euclidean/oned/Vector1DTest.java | 129 +- .../euclidean/threed/FieldRotationDSTest.java | 20 +- .../euclidean/threed/FieldRotationDfpTest.java |6 +- .../euclidean/threed/FieldVector3DTest.java | 70 +- .../geometry/euclidean/threed/LineTest.java | 76 +- .../geometry/euclidean/threed/PLYParser.java|8 +- .../geometry/euclidean/threed/PlaneTest.java| 88 +- .../euclidean/threed/PolyhedronsSetTest.java| 146 +- .../geometry/euclidean/threed/RotationTest.java | 250 ++-- .../euclidean/threed/SphereGeneratorTest.java | 114 +- .../threed/SphericalCoordinatesTest.java| 30 +- .../geometry/euclidean/threed/SubLineTest.java | 60 +- .../threed/Vector3DFormatAbstractTest.java | 74 +- .../geometry/euclidean/threed/Vector3DTest.java | 246 ++-- .../euclidean/twod/DiskGeneratorTest.java | 58 +- .../math4/geometry/euclidean/twod/LineTest.java | 65 +- .../euclidean/twod/NestedLoopsTest.jav
[2/5] [math] Fix some javadoc issues.
http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/stat/inference/InferenceTestUtils.java -- diff --git a/src/main/java/org/apache/commons/math4/stat/inference/InferenceTestUtils.java b/src/main/java/org/apache/commons/math4/stat/inference/InferenceTestUtils.java index a0da22f..a06e3d1 100644 --- a/src/main/java/org/apache/commons/math4/stat/inference/InferenceTestUtils.java +++ b/src/main/java/org/apache/commons/math4/stat/inference/InferenceTestUtils.java @@ -65,6 +65,9 @@ public class InferenceTestUtils { // CHECKSTYLE: stop JavadocMethodCheck /** + * @param sample1 array of sample data values + * @param sample2 array of sample data values + * @return t statistic * @see org.apache.commons.math4.stat.inference.TTest#homoscedasticT(double[], double[]) */ public static double homoscedasticT(final double[] sample1, final double[] sample2) @@ -73,6 +76,9 @@ public class InferenceTestUtils { } /** + * @param sampleStats1 StatisticalSummary describing data from the first sample + * @param sampleStats2 StatisticalSummary describing data from the second sample + * @return t statistic * @see org.apache.commons.math4.stat.inference.TTest#homoscedasticT(org.apache.commons.math4.stat.descriptive.StatisticalSummary, org.apache.commons.math4.stat.descriptive.StatisticalSummary) */ public static double homoscedasticT(final StatisticalSummary sampleStats1, @@ -82,6 +88,11 @@ public class InferenceTestUtils { } /** + * @param sample1 array of sample data values + * @param sample2 array of sample data values + * @param alpha significance level of the test + * @return true if the null hypothesis can be rejected with + * confidence 1 - alpha * @see org.apache.commons.math4.stat.inference.TTest#homoscedasticTTest(double[], double[], double) */ public static boolean homoscedasticTTest(final double[] sample1, final double[] sample2, @@ -92,6 +103,9 @@ public class InferenceTestUtils { } /** + * @param sample1 array of sample data values + * @param sample2 array of sample data values + * @return p-value for t-test * @see org.apache.commons.math4.stat.inference.TTest#homoscedasticTTest(double[], double[]) */ public static double homoscedasticTTest(final double[] sample1, final double[] sample2) @@ -100,6 +114,9 @@ public class InferenceTestUtils { } /** + * @param sampleStats1 StatisticalSummary describing data from the first sample + * @param sampleStats2 StatisticalSummary describing data from the second sample + * @return p-value for t-test * @see org.apache.commons.math4.stat.inference.TTest#homoscedasticTTest(org.apache.commons.math4.stat.descriptive.StatisticalSummary, org.apache.commons.math4.stat.descriptive.StatisticalSummary) */ public static double homoscedasticTTest(final StatisticalSummary sampleStats1, @@ -109,6 +126,9 @@ public class InferenceTestUtils { } /** + * @param sample1 array of sample data values + * @param sample2 array of sample data values + * @return t statistic * @see org.apache.commons.math4.stat.inference.TTest#pairedT(double[], double[]) */ public static double pairedT(final double[] sample1, final double[] sample2) @@ -118,6 +138,11 @@ public class InferenceTestUtils { } /** + * @param sample1 array of sample data values + * @param sample2 array of sample data values + * @param alpha significance level of the test + * @return true if the null hypothesis can be rejected with + * confidence 1 - alpha * @see org.apache.commons.math4.stat.inference.TTest#pairedTTest(double[], double[], double) */ public static boolean pairedTTest(final double[] sample1, final double[] sample2, @@ -128,6 +153,9 @@ public class InferenceTestUtils { } /** + * @param sample1 array of sample data values + * @param sample2 array of sample data values + * @return p-value for t-test * @see org.apache.commons.math4.stat.inference.TTest#pairedTTest(double[], double[]) */ public static double pairedTTest(final double[] sample1, final double[] sample2) @@ -137,6 +165,9 @@ public class InferenceTestUtils { } /** + * @param mu comparison constant + * @param observed array of values + * @return t statistic * @see org.apache.commons.math4.stat.inference.TTest#t(double, double[]) */ public static double t(final double mu, final double[] observed) @@ -145,6 +176,9 @@ public class InferenceTestUtils { } /** + * @param mu comparison constant + * @param sampleStats DescriptiveStatistics holding sample summary statitstics + * @return t statistic * @see org.apache.commons.math4.sta
[5/5] [math] Fix some javadoc issues.
Fix some javadoc issues. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/53ec46ba Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/53ec46ba Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/53ec46ba Branch: refs/heads/master Commit: 53ec46ba272e23c0c96ada42f26f4e70e96f3115 Parents: cdf22ce Author: Ray DeCampo Authored: Sun May 7 12:35:54 2017 -0400 Committer: Ray DeCampo Committed: Sun May 7 12:35:54 2017 -0400 -- .../interpolation/SplineInterpolator.java | 2 +- .../commons/math4/complex/Quaternion.java | 2 +- .../commons/math4/complex/RootsOfUnity.java | 2 +- .../java/org/apache/commons/math4/dfp/Dfp.java | 8 +- .../apache/commons/math4/dfp/package-info.java | 4 +- .../distribution/EmpiricalDistribution.java | 24 +-- .../EnumeratedIntegerDistribution.java | 2 +- .../math4/distribution/GammaDistribution.java | 1 - .../math4/distribution/ParetoDistribution.java | 1 - .../math4/distribution/PascalDistribution.java | 10 +- .../math4/distribution/ZipfDistribution.java| 1 - ...ateNormalMixtureExpectationMaximization.java | 2 +- .../math4/fitting/AbstractCurveFitter.java | 4 +- .../math4/fitting/GaussianCurveFitter.java | 2 +- .../math4/fitting/HarmonicCurveFitter.java | 2 +- .../math4/fitting/PolynomialCurveFitter.java| 2 +- .../leastsquares/AbstractEvaluation.java| 2 +- .../leastsquares/GaussNewtonOptimizer.java | 10 +- .../leastsquares/LeastSquaresAdapter.java | 2 +- .../leastsquares/LeastSquaresBuilder.java | 2 +- .../leastsquares/LeastSquaresProblem.java | 2 +- .../LevenbergMarquardtOptimizer.java| 6 +- .../fitting/leastsquares/package-info.java | 4 +- .../commons/math4/fraction/BigFraction.java | 2 - .../apache/commons/math4/fraction/Fraction.java | 2 - .../math4/genetics/GeneticAlgorithm.java| 1 - .../euclidean/threed/FieldVector3D.java | 2 +- .../geometry/euclidean/threed/Vector3D.java | 2 +- .../math4/linear/AbstractFieldMatrix.java | 2 +- .../math4/linear/Array2DRowFieldMatrix.java | 4 +- .../commons/math4/linear/BlockFieldMatrix.java | 5 +- .../commons/math4/linear/BlockRealMatrix.java | 1 - .../commons/math4/linear/ConjugateGradient.java | 7 +- .../commons/math4/linear/DiagonalMatrix.java| 4 +- .../commons/math4/linear/FieldMatrix.java | 3 +- .../commons/math4/linear/MatrixUtils.java | 2 - .../PreconditionedIterativeLinearSolver.java| 2 +- .../commons/math4/linear/RRQRDecomposition.java | 2 +- .../math4/linear/RealLinearOperator.java| 2 +- .../apache/commons/math4/linear/RealMatrix.java | 2 +- .../apache/commons/math4/linear/RealVector.java | 4 +- .../RectangularCholeskyDecomposition.java | 2 +- .../commons/math4/linear/SparseFieldMatrix.java | 2 +- .../org/apache/commons/math4/linear/SymmLQ.java | 8 +- .../ml/clustering/FuzzyKMeansClusterer.java | 4 +- .../commons/math4/ml/neuralnet/Neuron.java | 4 +- .../math4/ml/neuralnet/SquareNeighbourhood.java | 4 +- .../math4/ml/neuralnet/oned/NeuronString.java | 4 +- .../ml/neuralnet/sofm/KohonenUpdateAction.java | 6 +- .../sofm/util/ExponentialDecayFunction.java | 2 +- .../sofm/util/QuasiSigmoidDecayFunction.java| 2 +- .../ml/neuralnet/twod/NeuronSquareMesh2D.java | 6 +- .../twod/util/SmoothedDataHistogram.java| 4 +- .../commons/math4/ode/JacobianMatrices.java | 1 - .../math4/ode/MultistepFieldIntegrator.java | 10 +- .../commons/math4/ode/MultistepIntegrator.java | 10 +- .../commons/math4/ode/events/EventHandler.java | 2 +- .../math4/ode/events/FieldEventHandler.java | 2 +- .../nonstiff/AdamsBashforthFieldIntegrator.java | 29 ++- .../ode/nonstiff/AdamsBashforthIntegrator.java | 29 ++- .../ode/nonstiff/AdamsFieldIntegrator.java | 12 +- .../math4/ode/nonstiff/AdamsIntegrator.java | 12 +- .../nonstiff/AdamsMoultonFieldIntegrator.java | 29 ++- .../ode/nonstiff/AdamsMoultonIntegrator.java| 29 ++- .../AdamsNordsieckFieldTransformer.java | 43 ++-- .../ode/nonstiff/AdamsNordsieckTransformer.java | 43 ++-- .../AdaptiveStepsizeFieldIntegrator.java| 6 +- .../nonstiff/AdaptiveStepsizeIntegrator.java| 6 +- .../ClassicalRungeKuttaFieldIntegrator.java | 1 - ...lassicalRungeKuttaFieldStepInterpolator.java | 1 - .../nonstiff/ClassicalRungeKuttaIntegrator.java | 1 - .../ClassicalRungeKuttaStepInterpolator.java| 1 - .../DormandPrince54FieldIntegrator.java | 2 +- .../ode/nonstiff/DormandPrince54Integrator.java | 2 +- .../EmbeddedRungeKuttaFieldIntegrator.java | 1 - .../nonstiff/EmbeddedRungeKuttaIntegrator.java |
[3/5] [math] Fix some javadoc issues.
http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizer.java -- diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizer.java b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizer.java index 75dd024..2bd188e 100644 --- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizer.java +++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizer.java @@ -31,11 +31,11 @@ import org.apache.commons.math4.optim.nonlinear.scalar.LineSearch; /** * Non-linear conjugate gradient optimizer. - * + * * This class supports both the Fletcher-Reeves and the Polak-Ribière * update formulas for the conjugate search directions. * It also supports optional preconditioning. - * + * * Constraints are not supported: the call to * {@link #optimize(OptimizationData[]) optimize} will throw * {@link MathUnsupportedOperationException} if bounds are passed to it. http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/AbstractSimplex.java -- diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/AbstractSimplex.java b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/AbstractSimplex.java index 45da036..4ddfaed 100644 --- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/AbstractSimplex.java +++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/AbstractSimplex.java @@ -34,12 +34,12 @@ import org.apache.commons.math4.optim.PointValuePair; /** * This class implements the simplex concept. * It is intended to be used in conjunction with {@link SimplexOptimizer}. - * + * * The initial configuration of the simplex is set by the constructors * {@link #AbstractSimplex(double[])} or {@link #AbstractSimplex(double[][])}. * The other {@link #AbstractSimplex(int) constructor} will set all steps * to 1, thus building a default configuration from a unit hypercube. - * + * * Users must call the {@link #build(double[]) build} method in order * to create the data structure that will be acted on by the other methods of * this class. http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java -- diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java index 74bf89d..4366b15 100644 --- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java +++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java @@ -35,7 +35,7 @@ import org.apache.commons.math4.util.FastMath; * http://plato.asu.edu/ftp/other_software/bobyqa.zip";>here. * See http://www.optimization-online.org/DB_HTML/2010/05/2616.html";> * this paper for an introduction. - * + * * BOBYQA is particularly well suited for high dimensional problems * where derivatives are not available. In most cases it outperforms the * {@link PowellOptimizer} significantly. Stochastic algorithms like @@ -148,9 +148,9 @@ public class BOBYQAOptimizer /** * Differences {@link #getLowerBound()} - {@link #originShift}. * All the components of every {@link #trustRegionCenterOffset} are going - * to satisfy the bounds + * to satisfy the bounds * {@link #getLowerBound() lowerBound}i ≤ - * {@link #trustRegionCenterOffset}i, + * {@link #trustRegionCenterOffset}i, * with appropriate equalities when {@link #trustRegionCenterOffset} is * on a constraint boundary. * XXX "sl" in the original code. @@ -159,9 +159,9 @@ public class BOBYQAOptimizer /** * Differences {@link #getUpperBound()} - {@link #originShift} * All the components of every {@link #trustRegionCenterOffset} are going - * to satisfy the bounds + * to satisfy the bounds * {@link #trustRegionCenterOffset}i ≤ - * {@link #getUpperBound() upperBound}i, + * {@link #getUpperBound() upperBound}i, * with appropriate equalities when {@link #trustRegionCenterOffset} is * on a constraint boundary. * XXX "su" in the original code. http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java --
[1/5] [math] Fix some javadoc issues.
Repository: commons-math Updated Branches: refs/heads/master cdf22ce63 -> 53ec46ba2 http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/util/MathArrays.java -- diff --git a/src/main/java/org/apache/commons/math4/util/MathArrays.java b/src/main/java/org/apache/commons/math4/util/MathArrays.java index 8d1236c..768afd1 100644 --- a/src/main/java/org/apache/commons/math4/util/MathArrays.java +++ b/src/main/java/org/apache/commons/math4/util/MathArrays.java @@ -601,7 +601,7 @@ public class MathArrays { } /** - * Check that all entries of the input array are >= 0. + * Check that all entries of the input array are >= 0. * * @param in Array to be tested * @throws NotPositiveException if any array entries are less than 0. @@ -617,7 +617,7 @@ public class MathArrays { } /** - * Check all entries of the input array are >= 0. + * Check all entries of the input array are >= 0. * * @param in Array to be tested * @throws NotPositiveException if any array entries are less than 0. @@ -637,12 +637,12 @@ public class MathArrays { /** * Returns the Cartesian norm (2-norm), handling both overflow and underflow. * Translation of the minpack enorm subroutine. - * + * * The redistribution policy for MINPACK is available * http://www.netlib.org/minpack/disclaimer";>here, for * convenience, it is reproduced below. * - * + * * *Minpack Copyright Notice (1999) University of Chicago. *All rights reserved @@ -687,7 +687,7 @@ public class MathArrays { * (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, * EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE * POSSIBILITY OF SUCH LOSS OR DAMAGES. - * + * * * * @param v Vector of doubles. @@ -963,7 +963,7 @@ public class MathArrays { * ai bi to high accuracy. * It does so by using specific multiplication and addition algorithms to * preserve accuracy and reduce cancellation effects. - * + * * It is based on the 2005 paper * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.2.1547";> * Accurate Sum and Dot Product by Takeshi Ogita, Siegfried M. Rump, @@ -1411,7 +1411,7 @@ public class MathArrays { * Normalizes an array to make it sum to a specified value. * Returns the result of the transformation * - *x |-> x * normalizedSum / sum + *x |-> x * normalizedSum / sum * * applied to each non-NaN element x of the input array, where sum is the * sum of the non-NaN entries in the input array. @@ -1595,15 +1595,14 @@ public class MathArrays { /** * This method is used * to verify that the input parameters designate a subarray of positive length. - * * * returns true iff the parameters designate a subarray of * positive length * throws MathIllegalArgumentException if the array is null or * or the indices are invalid - * returns false if the array is non-null, but - * length is 0. - * + * returns false if the array is non-null, but + * length is 0. + * * * @param values the input array * @param begin index of the first array element to include @@ -1620,15 +1619,14 @@ public class MathArrays { /** * This method is used * to verify that the input parameters designate a subarray of positive length. - * * * returns true iff the parameters designate a subarray of * non-negative length * throws IllegalArgumentException if the array is null or * or the indices are invalid - * returns false if the array is non-null, but - * length is 0 unless allowEmpty is true - * + * returns false if the array is non-null, but + * length is 0 unless allowEmpty is true + * * * @param values the input array * @param begin index of the first array element to include @@ -1670,7 +1668,6 @@ public class MathArrays { * This method is used * to verify that the begin and length parameters designate a subarray of positive length * and the weights are all non-negative, non-NaN, finite, and not all zero. - * * * returns true iff the parameters designate a subarray of * positive length and the weights array contains legitimate values. @@ -1683,9 +1680,9 @@ public class MathArrays { * the weights array contains negative values * the start and length arguments do not determine a valid array * - * returns false if the array is non-null, but - * length is 0. - * + * returns false if the array is non-null, but + * length is 0. + * * * @param values the input array * @param weights
[4/5] [math] Fix some javadoc issues.
http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegrator.java -- diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegrator.java index cd84f18..5321750 100644 --- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegrator.java +++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegrator.java @@ -54,19 +54,19 @@ import org.apache.commons.math4.util.FastMath; * Implementation details * * We define scaled derivatives si(n) at step n as: - * + * * s1(n) = h y'n for first derivative * s2(n) = h2/2 y''n for second derivative * s3(n) = h3/6 y'''n for third derivative * ... * sk(n) = hk/k! y(k)n for kth derivative - * + * * * The definitions above use the classical representation with several previous first * derivatives. Lets define - * + * * qn = [ s1(n-1) s1(n-2) ... s1(n-(k-1)) ]T - * + * * (we omit the k index in the notation for clarity). With these definitions, * Adams-Bashforth methods can be written: * @@ -75,30 +75,29 @@ import org.apache.commons.math4.util.FastMath; * k = 3: yn+1 = yn + 23/12 s1(n) + [ -16/12 5/12 ] qn * k = 4: yn+1 = yn + 55/24 s1(n) + [ -59/24 37/24 -9/24 ] qn * ... - * + * * * Instead of using the classical representation with first derivatives only (yn, * s1(n) and qn), our implementation uses the Nordsieck vector with * higher degrees scaled derivatives all taken at the same step (yn, s1(n) * and rn) where rn is defined as: - * + * * rn = [ s2(n), s3(n) ... sk(n) ]T - * + * * (here again we omit the k index in the notation for clarity) - * * * Taylor series formulas show that for any index offset i, s1(n-i) can be * computed from s1(n), s2(n) ... sk(n), the formula being exact * for degree k polynomials. - * + * * s1(n-i) = s1(n) + ∑j>0 (j+1) (-i)j sj+1(n) - * + * * The previous formula can be used with several values for i to compute the transform between * classical representation and Nordsieck vector. The transform between rn * and qn resulting from the Taylor series formulas above is: - * + * * qn = s1(n) u + P rn - * + * * where u is the [ 1 1 ... 1 ]T vector and P is the (k-1)×(k-1) matrix built * with the (j+1) (-i)j terms with i being the row number starting from 1 and j being * the column number starting from 1: @@ -108,7 +107,7 @@ import org.apache.commons.math4.util.FastMath; * P = [ -6 27 -108 405 ... ] *[ -8 48 -256 1280 ... ] *[ ... ] - * + * * * Using the Nordsieck vector has several advantages: * @@ -117,7 +116,7 @@ import org.apache.commons.math4.util.FastMath; * it simplifies step changes that occur when discrete events that truncate * the step are triggered, * it allows to extend the methods in order to support adaptive stepsize. - * + * * * The Nordsieck vector at step n+1 is computed from the Nordsieck vector at step n as follows: * @@ -134,7 +133,7 @@ import org.apache.commons.math4.util.FastMath; *[ ... | 0 ] *[ 0 0 ... 1 0 | 0 ] *[ 0 0 ... 0 1 | 0 ] - * + * * * The P-1u vector and the P-1 A P matrix do not depend on the state, * they only depend on k and therefore are precomputed once for all. http://git-wip-us.apache.org/repos/asf/commons-math/blob/53ec46ba/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java -- diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java index cb2061b..700739d 100644 --- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java +++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java @@ -112,10 +112,10 @@ public abstract class AdamsFieldIntegrator> extend /** Update the high order scaled derivatives for Adams integrators (phase 1). * The complete update of high order derivatives has a form similar to: - * + * * rn+1 = (s1(n) - s1(n+1)) P-1 u + P-1 A P rn - * - * this method computes the P-1 A P rn part. + * + * this method computes the P-1 A P rn part. * @param highOrder high order scaled derivatives * (h2/2 y'', ... hk/k! y(k)) * @return updated high order derivatives @@ -127,10 +127,10 @@ public abstract class AdamsFieldIntegrator> extend /** Update the high order scaled derivatives Adams integrators (phase 2). * The complete update of high order derivatives has a form similar to: - * + * * rn+1 = (s1(n) - s
[01/31] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
Repository: commons-math Updated Branches: refs/heads/master bf9158489 -> 7a59c0af2 http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java index 92ca21a..22fb232 100644 --- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java @@ -21,7 +21,7 @@ import java.util.List; import org.apache.commons.math4.geometry.enclosing.EnclosingBall; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.math4.geometry.partitioning.RegionFactory; import org.apache.commons.math4.geometry.partitioning.SubHyperplane; import org.apache.commons.math4.geometry.partitioning.Region.Location; @@ -50,7 +50,7 @@ public class SphericalPolygonsSetTest { new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x852fd2a0ed8d2f6dl)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); Assert.assertEquals(Location.INSIDE, full.checkPoint(new S2Point(v))); } Assert.assertEquals(4 * FastMath.PI, new SphericalPolygonsSet(0.01, new S2Point[0]).getSize(), 1.0e-10); @@ -68,7 +68,7 @@ public class SphericalPolygonsSetTest { new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x76d9205d6167b6ddl)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v))); } Assert.assertEquals(0, empty.getSize(), 1.0e-10); @@ -82,12 +82,12 @@ public class SphericalPolygonsSetTest { public void testSouthHemisphere() { double tol = 0.01; double sinTol = FastMath.sin(tol); -SphericalPolygonsSet south = new SphericalPolygonsSet(Vector3D.MINUS_K, tol); +SphericalPolygonsSet south = new SphericalPolygonsSet(Coordinates3D.MINUS_K, tol); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x6b9d4a6ad90d7b0bl)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); if (v.getZ() < -sinTol) { Assert.assertEquals(Location.INSIDE, south.checkPoint(new S2Point(v))); } else if (v.getZ() > sinTol) { @@ -114,16 +114,16 @@ public class SphericalPolygonsSetTest { double tol = 0.01; double sinTol = FastMath.sin(tol); RegionFactory factory = new RegionFactory<>(); -SphericalPolygonsSet plusX = new SphericalPolygonsSet(Vector3D.PLUS_I, tol); -SphericalPolygonsSet plusY = new SphericalPolygonsSet(Vector3D.PLUS_J, tol); -SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Vector3D.PLUS_K, tol); +SphericalPolygonsSet plusX = new SphericalPolygonsSet(Coordinates3D.PLUS_I, tol); +SphericalPolygonsSet plusY = new SphericalPolygonsSet(Coordinates3D.PLUS_J, tol); +SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Coordinates3D.PLUS_K, tol); SphericalPolygonsSet octant = (SphericalPolygonsSet) factory.intersection(factory.intersection(plusX, plusY), plusZ); UnitSphereRandomVectorGenerator random = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A, 0x9c9802fde3cbcf25l)); for (int i = 0; i < 1000; ++i) { -Vector3D v = new Vector3D(random.nextVector()); +Coordinates3D v = new Coordinates3D(random.nextVector()); if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) { Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v))); } else if ((v.getX() < -sinTol
[04/31] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java index dbf1b3e..296ade8 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.geometry.Space; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.util.FastMath; @@ -39,27 +39,27 @@ public class Vector3DTest { @Test public void testConstructors() throws DimensionMismatchException { double r = FastMath.sqrt(2) /2; -checkVector(new Vector3D(2, new Vector3D(FastMath.PI / 3, -FastMath.PI / 4)), +checkVector(new Coordinates3D(2, new Coordinates3D(FastMath.PI / 3, -FastMath.PI / 4)), r, r * FastMath.sqrt(3), -2 * r); -checkVector(new Vector3D(2, Vector3D.PLUS_I, - -3, Vector3D.MINUS_K), +checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, + -3, Coordinates3D.MINUS_K), 2, 0, 3); -checkVector(new Vector3D(2, Vector3D.PLUS_I, - 5, Vector3D.PLUS_J, - -3, Vector3D.MINUS_K), +checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, + 5, Coordinates3D.PLUS_J, + -3, Coordinates3D.MINUS_K), 2, 5, 3); -checkVector(new Vector3D(2, Vector3D.PLUS_I, - 5, Vector3D.PLUS_J, - 5, Vector3D.MINUS_J, - -3, Vector3D.MINUS_K), +checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, + 5, Coordinates3D.PLUS_J, + 5, Coordinates3D.MINUS_J, + -3, Coordinates3D.MINUS_K), 2, 0, 3); -checkVector(new Vector3D(new double[] { 2, 5, -3 }), +checkVector(new Coordinates3D(new double[] { 2, 5, -3 }), 2, 5, -3); } @Test public void testSpace() { -Space space = new Vector3D(1, 2, 2).getSpace(); +Space space = new Coordinates3D(1, 2, 2).getSpace(); Assert.assertEquals(3, space.getDimension()); Assert.assertEquals(2, space.getSubSpace().getDimension()); Space deserialized = (Space) TestUtils.serializeAndRecover(space); @@ -68,63 +68,63 @@ public class Vector3DTest { @Test public void testZero() { -Assert.assertEquals(0, new Vector3D(1, 2, 2).getZero().getNorm(), 1.0e-15); +Assert.assertEquals(0, new Coordinates3D(1, 2, 2).getZero().getNorm(), 1.0e-15); } @Test public void testEquals() { -Vector3D u1 = new Vector3D(1, 2, 3); -Vector3D u2 = new Vector3D(1, 2, 3); +Coordinates3D u1 = new Coordinates3D(1, 2, 3); +Coordinates3D u2 = new Coordinates3D(1, 2, 3); Assert.assertTrue(u1.equals(u1)); Assert.assertTrue(u1.equals(u2)); Assert.assertFalse(u1.equals(new Rotation(1, 0, 0, 0, false))); -Assert.assertFalse(u1.equals(new Vector3D(1, 2, 3 + 10 * Precision.EPSILON))); -Assert.assertFalse(u1.equals(new Vector3D(1, 2 + 10 * Precision.EPSILON, 3))); -Assert.assertFalse(u1.equals(new Vector3D(1 + 10 * Precision.EPSILON, 2, 3))); -Assert.assertTrue(new Vector3D(0, Double.NaN, 0).equals(new Vector3D(0, 0, Double.NaN))); +Assert.assertFalse(u1.equals(new Coordinates3D(1, 2, 3 + 10 * Precision.EPSILON))); +Assert.assertFalse(u1.equals(new Coordinates3D(1, 2 + 10 * Precision.EPSILON, 3))); +Assert.assertFalse(u1.equals(new Coordinates3D(1 + 10 * Precision.EPSILON, 2, 3))); +Assert.assertTrue(new Coordinates3D(0, Double.NaN, 0).equals(new Coordinates3D(0, 0, Double.NaN))); } @Test public void testHash() { -Assert.assertEquals(new Vector3D(0, Double.NaN, 0).hashCode(), new Vector3D(0, 0, Double.NaN).hashCode()); -Vector3D u = new Vector3D(1, 2, 3); -Vector3D v = new Vector3D(1, 2, 3 + 10 * Precision.EPSILO
[28/31] [math] MATH-1284: Restore Vector2D class as an abstract implementation of Vector and now Cartesian2D extends Vector2D. Restore the public interface of Vector2DFormat to act on Vec
MATH-1284: Restore Vector2D class as an abstract implementation of Vector and now Cartesian2D extends Vector2D. Restore the public interface of Vector2DFormat to act on Vector2D. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/09c55eb8 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/09c55eb8 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/09c55eb8 Branch: refs/heads/master Commit: 09c55eb8120da36aef1807628f87bde83749428b Parents: 9be91f3 Author: Ray DeCampo Authored: Sat May 6 10:51:16 2017 -0400 Committer: Ray DeCampo Committed: Sat May 6 10:51:16 2017 -0400 -- .../geometry/euclidean/twod/Cartesian2D.java| 2 +- .../math4/geometry/euclidean/twod/Vector2D.java | 38 ++ .../geometry/euclidean/twod/Vector2DFormat.java | 10 ++--- .../twod/Vector2DFormatAbstractTest.java| 42 ++-- 4 files changed, 65 insertions(+), 27 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/09c55eb8/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java index 51109d0..7e68362 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java @@ -36,7 +36,7 @@ import org.apache.commons.math4.util.MathUtils; * Instances of this class are guaranteed to be immutable. * @since 4.0 */ -public class Cartesian2D implements Point, Vector { +public class Cartesian2D extends Vector2D implements Point { /** Origin (coordinates: 0, 0). */ public static final Cartesian2D ZERO = new Cartesian2D(0, 0); http://git-wip-us.apache.org/repos/asf/commons-math/blob/09c55eb8/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java new file mode 100644 index 000..4a2a398 --- /dev/null +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java @@ -0,0 +1,38 @@ +/* + * 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.math4.geometry.euclidean.twod; + +import org.apache.commons.math4.geometry.Vector; + +/** This class represents a 2D vector. + * @since 3.0 + */ +public abstract class Vector2D implements Vector { + +/** Get the abscissa of the vector. + * @return abscissa of the vector + * @see #Vector2D(double, double) + */ +public abstract double getX(); + +/** Get the ordinate of the vector. + * @return ordinate of the vector + * @see #Vector2D(double, double) + */ +public abstract double getY(); + +} http://git-wip-us.apache.org/repos/asf/commons-math/blob/09c55eb8/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java index 936450a..cb76596 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java @@ -108,26 +108,26 @@ public class Vector2DFormat extends VectorFormat { @Override public StringBuffer format(final Vector vector, final StringBuffer toAppendTo, final FieldPosition pos) { -final Cartesian2D p2 = (Cartesian2D) vector; +final Vector2D p2 = (Vector2D) vector;
[10/31] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java index bec2d74..dc538a5 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3D.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.util.FastMath; import org.apache.commons.math4.util.MathArrays; /** - * This class is a re-implementation of {@link Vector3D} using {@link RealFieldElement}. + * This class is a re-implementation of {@link Coordinates3D} using {@link RealFieldElement}. * Instance of this class are guaranteed to be immutable. * @param the type of the field elements * @since 3.2 @@ -110,7 +110,7 @@ public class FieldVector3D> implements Serializabl * @param a scale factor * @param u base (unscaled) vector */ -public FieldVector3D(final T a, final Vector3D u) { +public FieldVector3D(final T a, final Coordinates3D u) { this.x = a.multiply(u.getX()); this.y = a.multiply(u.getY()); this.z = a.multiply(u.getZ()); @@ -152,8 +152,8 @@ public class FieldVector3D> implements Serializabl * @param a2 second scale factor * @param u2 second base (unscaled) vector */ -public FieldVector3D(final T a1, final Vector3D u1, - final T a2, final Vector3D u2) { +public FieldVector3D(final T a1, final Coordinates3D u1, + final T a2, final Coordinates3D u2) { final T prototype = a1; this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2); this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2); @@ -205,9 +205,9 @@ public class FieldVector3D> implements Serializabl * @param a3 third scale factor * @param u3 third base (unscaled) vector */ -public FieldVector3D(final T a1, final Vector3D u1, - final T a2, final Vector3D u2, - final T a3, final Vector3D u3) { +public FieldVector3D(final T a1, final Coordinates3D u1, + final T a2, final Coordinates3D u2, + final T a3, final Coordinates3D u3) { final T prototype = a1; this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2, u3.getX(), a3); this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2, u3.getY(), a3); @@ -267,10 +267,10 @@ public class FieldVector3D> implements Serializabl * @param a4 fourth scale factor * @param u4 fourth base (unscaled) vector */ -public FieldVector3D(final T a1, final Vector3D u1, - final T a2, final Vector3D u2, - final T a3, final Vector3D u3, - final T a4, final Vector3D u4) { +public FieldVector3D(final T a1, final Coordinates3D u1, + final T a2, final Coordinates3D u2, + final T a3, final Coordinates3D u3, + final T a4, final Coordinates3D u4) { final T prototype = a1; this.x = prototype.linearCombination(u1.getX(), a1, u2.getX(), a2, u3.getX(), a3, u4.getX(), a4); this.y = prototype.linearCombination(u1.getY(), a1, u2.getY(), a2, u3.getY(), a3, u4.getY(), a4); @@ -338,8 +338,8 @@ public class FieldVector3D> implements Serializabl /** Convert to a constant vector without derivatives. * @return a constant vector */ -public Vector3D toVector3D() { -return new Vector3D(x.getReal(), y.getReal(), z.getReal()); +public Coordinates3D toVector3D() { +return new Coordinates3D(x.getReal(), y.getReal(), z.getReal()); } /** Get the L1 norm for the vector. @@ -415,7 +415,7 @@ public class FieldVector3D> implements Serializabl * @param v vector to add * @return a new vector */ -public FieldVector3D add(final Vector3D v) { +public FieldVector3D add(final Coordinates3D v) { return new FieldVector3D<>(x.add(v.getX()), y.add(v.getY()), z.add(v.getZ())); } @@ -433,7 +433,7 @@ public class FieldVector3D> implements Serializabl * @param v vector to add * @return a new vector */ -public FieldVector3D add(final T factor, final Vector3D v) { +public FieldVector3D add(final T factor, final Coordinates3D v) { return new FieldVector3D<>(x.add(factor.multiply(v.getX())), y.add(factor.multiply(v.getY())), z.add(factor.multiply(v.getZ(; @@ -453,7 +453,7 @@ public class FieldVector3D
[21/31] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java index a05ab8e..6392e3f 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java @@ -820,8 +820,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusK) coordinates are : // sin (theta), -sin (phi) cos (theta), cos (phi) cos (theta) // and we can choose to have theta in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_I); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_K); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_I); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_K); if ((v2.getX().getReal() < -0.99) || (v2.getX().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -836,8 +836,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusJ) coordinates are : // -sin (psi), cos (phi) cos (psi), sin (phi) cos (psi) // and we can choose to have psi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_I); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_J); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_I); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_J); if ((v2.getX().getReal() < -0.99) || (v2.getX().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -852,8 +852,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusK) coordinates are : // sin (theta) cos (phi), -sin (phi), cos (theta) cos (phi) // and we can choose to have phi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_J); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_K); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_J); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_K); if ((v2.getY().getReal() < -0.99) || (v2.getY().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -868,8 +868,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusI) coordinates are : // cos (theta) cos (psi), sin (psi), -sin (theta) cos (psi) // and we can choose to have psi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_J); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_I); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_J); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_I); if ((v2.getY().getReal() < -0.99) || (v2.getY().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -884,8 +884,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusJ) coordinates are : // -sin (psi) cos (phi), cos (psi) cos (phi), sin (phi) // and we can choose to have phi in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_K); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_J); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_K); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_J); if ((v2.getZ().getReal() < -0.99) || (v2.getZ().getReal() > 0.99)) { throw new CardanEulerSingularityException(true); } @@ -900,8 +900,8 @@ public class FieldRotation> implements Serializabl // (-r) (Vector3D.plusI) coordinates are : // cos (psi) cos (theta), sin (psi) cos (theta), -sin (theta) // and we can choose to have theta in the interval [-PI/2 ; +PI/2] -FieldVector3D v1 = applyTo(Coordinates3D.PLUS_K); -FieldVector3D v2 = applyInverseTo(Coordinates3D.PLUS_I); +FieldVector3D v1 = applyTo(Cartesian3D.PLUS_K); +FieldVector3D v2 = applyInverseTo(Cartesian3D.PLUS_I);
[15/31] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java index 296ade8..a0e9f59 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java @@ -27,7 +27,7 @@ import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.geometry.Space; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.util.FastMath; @@ -39,27 +39,27 @@ public class Vector3DTest { @Test public void testConstructors() throws DimensionMismatchException { double r = FastMath.sqrt(2) /2; -checkVector(new Coordinates3D(2, new Coordinates3D(FastMath.PI / 3, -FastMath.PI / 4)), +checkVector(new Cartesian3D(2, new Cartesian3D(FastMath.PI / 3, -FastMath.PI / 4)), r, r * FastMath.sqrt(3), -2 * r); -checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, - -3, Coordinates3D.MINUS_K), +checkVector(new Cartesian3D(2, Cartesian3D.PLUS_I, + -3, Cartesian3D.MINUS_K), 2, 0, 3); -checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, - 5, Coordinates3D.PLUS_J, - -3, Coordinates3D.MINUS_K), +checkVector(new Cartesian3D(2, Cartesian3D.PLUS_I, + 5, Cartesian3D.PLUS_J, + -3, Cartesian3D.MINUS_K), 2, 5, 3); -checkVector(new Coordinates3D(2, Coordinates3D.PLUS_I, - 5, Coordinates3D.PLUS_J, - 5, Coordinates3D.MINUS_J, - -3, Coordinates3D.MINUS_K), +checkVector(new Cartesian3D(2, Cartesian3D.PLUS_I, + 5, Cartesian3D.PLUS_J, + 5, Cartesian3D.MINUS_J, + -3, Cartesian3D.MINUS_K), 2, 0, 3); -checkVector(new Coordinates3D(new double[] { 2, 5, -3 }), +checkVector(new Cartesian3D(new double[] { 2, 5, -3 }), 2, 5, -3); } @Test public void testSpace() { -Space space = new Coordinates3D(1, 2, 2).getSpace(); +Space space = new Cartesian3D(1, 2, 2).getSpace(); Assert.assertEquals(3, space.getDimension()); Assert.assertEquals(2, space.getSubSpace().getDimension()); Space deserialized = (Space) TestUtils.serializeAndRecover(space); @@ -68,63 +68,63 @@ public class Vector3DTest { @Test public void testZero() { -Assert.assertEquals(0, new Coordinates3D(1, 2, 2).getZero().getNorm(), 1.0e-15); +Assert.assertEquals(0, new Cartesian3D(1, 2, 2).getZero().getNorm(), 1.0e-15); } @Test public void testEquals() { -Coordinates3D u1 = new Coordinates3D(1, 2, 3); -Coordinates3D u2 = new Coordinates3D(1, 2, 3); +Cartesian3D u1 = new Cartesian3D(1, 2, 3); +Cartesian3D u2 = new Cartesian3D(1, 2, 3); Assert.assertTrue(u1.equals(u1)); Assert.assertTrue(u1.equals(u2)); Assert.assertFalse(u1.equals(new Rotation(1, 0, 0, 0, false))); -Assert.assertFalse(u1.equals(new Coordinates3D(1, 2, 3 + 10 * Precision.EPSILON))); -Assert.assertFalse(u1.equals(new Coordinates3D(1, 2 + 10 * Precision.EPSILON, 3))); -Assert.assertFalse(u1.equals(new Coordinates3D(1 + 10 * Precision.EPSILON, 2, 3))); -Assert.assertTrue(new Coordinates3D(0, Double.NaN, 0).equals(new Coordinates3D(0, 0, Double.NaN))); +Assert.assertFalse(u1.equals(new Cartesian3D(1, 2, 3 + 10 * Precision.EPSILON))); +Assert.assertFalse(u1.equals(new Cartesian3D(1, 2 + 10 * Precision.EPSILON, 3))); +Assert.assertFalse(u1.equals(new Cartesian3D(1 + 10 * Precision.EPSILON, 2, 3))); +Assert.assertTrue(new Cartesian3D(0, Double.NaN, 0).equals(new Cartesian3D(0, 0, Double.NaN))); } @Test public void testHash() { -Assert.assertEquals(new Coordinates3D(0, Double.NaN, 0).hashCode(), new Coordinates3D(0, 0, Double.NaN).hashCode()); -Coordinates
[17/31] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java index 7728b96..02c059e 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java @@ -26,7 +26,7 @@ import org.apache.commons.math4.analysis.differentiation.DerivativeStructure; import org.apache.commons.math4.exception.DimensionMismatchException; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; import org.apache.commons.math4.util.FastMath; @@ -59,7 +59,7 @@ public class FieldVector3DTest { createVector(1, 0, 0, 4)), 2, 0, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, 0, 2, 0); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0)), + new Cartesian3D(1, 0, 0)), 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -71,9 +71,9 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 0, 3, -1, 0, 0, 1, 0, -1, 0, 0, 0, 0, -1, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0), + new Cartesian3D(1, 0, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Coordinates3D(0, 0, -1)), + new Cartesian3D(0, 0, -1)), 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -88,11 +88,11 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 5, 3, 4, 0, 0, 1, 0, 4, 0, 1, 0, 0, 4, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0), + new Cartesian3D(1, 0, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Coordinates3D(0, 1, 0), + new Cartesian3D(0, 1, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Coordinates3D(0, 0, -1)), + new Cartesian3D(0, 0, -1)), 2, 5, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -1); checkVector(new FieldVector3D<>(2, createVector(1, 0, 0, 3), @@ -110,13 +110,13 @@ public class FieldVector3DTest { createVector(0, 0, -1, 4)), 2, 0, 3, 9, 0, 0, 1, 0, 9, 0, 0, 0, 0, 9, -1); checkVector(new FieldVector3D<>(new DerivativeStructure(4, 1, 3, 2.0), - new Coordinates3D(1, 0, 0), + new Cartesian3D(1, 0, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Coordinates3D(0, 1, 0), + new Cartesian3D(0, 1, 0), new DerivativeStructure(4, 1, 3, 5.0), - new Coordinates3D(0, -1, 0), + new Cartesian3D(0, -1, 0), new DerivativeStructure(4, 1, 3, -3.0), - new Coordinates3D(0, 0, -1)), + new Cartesian3D(0, 0, -1)), 2, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1); checkVector(new FieldVector3D<>(new DerivativeStructure[] { @@ -270,12 +270,12 @@ public class FieldVector3DTest { Assert.assertEquals(0, distance.getPartialDerivative(1, 0, 0), 1.0e-12); Assert.assertEquals(0, distance.getPartialDerivative(0, 1, 0), 1.0e-12); Assert.assertEquals(0,
[08/31] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java index a19a876..7ac90d4 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGenerator.java @@ -26,26 +26,26 @@ import org.apache.commons.math4.util.FastMath; /** Class generating an enclosing ball from its support points. * @since 3.3 */ -public class DiskGenerator implements SupportBallGenerator { +public class DiskGenerator implements SupportBallGenerator { /** {@inheritDoc} */ @Override -public EnclosingBall ballOnSupport(final List support) { +public EnclosingBall ballOnSupport(final List support) { if (support.size() < 1) { -return new EnclosingBall<>(Vector2D.ZERO, Double.NEGATIVE_INFINITY); +return new EnclosingBall<>(Coordinates2D.ZERO, Double.NEGATIVE_INFINITY); } else { -final Vector2D vA = support.get(0); +final Coordinates2D vA = support.get(0); if (support.size() < 2) { return new EnclosingBall<>(vA, 0, vA); } else { -final Vector2D vB = support.get(1); +final Coordinates2D vB = support.get(1); if (support.size() < 3) { -return new EnclosingBall<>(new Vector2D(0.5, vA, 0.5, vB), +return new EnclosingBall<>(new Coordinates2D(0.5, vA, 0.5, vB), 0.5 * vA.distance(vB), vA, vB); } else { -final Vector2D vC = support.get(2); +final Coordinates2D vC = support.get(2); // a disk is 2D can be defined as: // (1) (x - x_0)^2 + (y - y_0)^2 = r^2 // which can be written: @@ -86,7 +86,7 @@ public class DiskGenerator implements SupportBallGenerator(new Vector2D(centerX.doubleValue(), +return new EnclosingBall<>(new Coordinates2D(centerX.doubleValue(), centerY.doubleValue()), FastMath.sqrt(r2.doubleValue()), vA, vB, vC); http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java index dd89296..7df7277 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java @@ -19,11 +19,10 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.exception.util.LocalizedFormats; import org.apache.commons.math4.geometry.Point; -import org.apache.commons.math4.geometry.Vector; import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.oned.OrientedPoint; -import org.apache.commons.math4.geometry.euclidean.oned.Vector1D; +import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D; import org.apache.commons.math4.geometry.partitioning.Embedding; import org.apache.commons.math4.geometry.partitioning.Hyperplane; import org.apache.commons.math4.geometry.partitioning.SubHyperplane; @@ -85,7 +84,7 @@ public class Line implements Hyperplane, Embedding, Embedding, Embedding, Embedding, Embedding vector) { -return toSubSpace((Point) vector); -} +//public Coordinates1D toSubSpace(Vector vector) { +//return toSubSpace((Point) vector); +//} /** Transform a sub-space point into a space point. * @param vector (n-1)-dimension point of the sub-space * @return n-dimension point of the space corresponding to the * specified sub-space point */ -public Vector2D toSpace(Vector vector) { -return toSpace((Point) vector); -} +//public Coordinates2D toSpace(Vector vector) { +//return toSpace((Point) vector); +//} /** {@inheritDoc} */ @Override -
[24/31] [math] MATH-1284: Replace uses of "Vector2D" in comments and supporting files with "Cartesian2D".
MATH-1284: Replace uses of "Vector2D" in comments and supporting files with "Cartesian2D". Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/c7d20472 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/c7d20472 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/c7d20472 Branch: refs/heads/master Commit: c7d20472de0dad34bce9483557f43c524e4f3e16 Parents: a398481 Author: Ray DeCampo Authored: Thu May 4 07:25:15 2017 -0400 Committer: Ray DeCampo Committed: Thu May 4 07:25:15 2017 -0400 -- .../geometry/euclidean/twod/Cartesian2D.java| 6 +- .../math4/geometry/euclidean/twod/Line.java | 4 +- .../geometry/euclidean/twod/NestedLoops.java| 2 +- src/site/design/twoD.puml | 4 +- src/site/xdoc/userguide/geometry.xml| 4 +- src/site/xdoc/userguide/leastsquares.xml| 20 +- .../euclidean/twod/Cartesian2DTest.java | 235 +++ .../geometry/euclidean/twod/Vector2DTest.java | 235 --- .../userguide/ClusterAlgorithmComparison.java | 40 ++-- .../LowDiscrepancyGeneratorComparison.java | 43 ++-- .../userguide/geometry/GeometryExample.java | 36 +-- 11 files changed, 314 insertions(+), 315 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/c7d20472/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java index 0272322..51109d0 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java @@ -149,7 +149,7 @@ public class Cartesian2D implements Point, Vector { /** Get the abscissa of the vector. * @return abscissa of the vector - * @see #Vector2D(double, double) + * @see #Cartesian2D(double, double) */ public double getX() { return x; @@ -157,7 +157,7 @@ public class Cartesian2D implements Point, Vector { /** Get the ordinate of the vector. * @return ordinate of the vector - * @see #Vector2D(double, double) + * @see #Cartesian2D(double, double) */ public double getY() { return y; @@ -165,7 +165,7 @@ public class Cartesian2D implements Point, Vector { /** Get the vector coordinates as a dimension 2 array. * @return vector coordinates - * @see #Vector2D(double[]) + * @see #Cartesian2D(double[]) */ public double[] toArray() { return new double[] { x, y }; http://git-wip-us.apache.org/repos/asf/commons-math/blob/c7d20472/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java index 36f0998..561cdc7 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java @@ -202,8 +202,8 @@ public class Line implements Hyperplane, Embedding * * As long as neither the instance nor its reverse are modified - * (i.e. as long as none of the {@link #reset(Vector2D, Vector2D)}, - * {@link #reset(Vector2D, double)}, {@link #revertSelf()}, + * (i.e. as long as none of the {@link #reset(Cartesian2D, Cartesian2D)}, + * {@link #reset(Cartesian2D, double)}, {@link #revertSelf()}, * {@link #setAngle(double)} or {@link #setOriginOffset(double)} * methods are called), then the line and its reverse remain linked * together so that {@code line.getReverse().getReverse() == line}. http://git-wip-us.apache.org/repos/asf/commons-math/blob/c7d20472/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java index 3a5038e..dcfc76a 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/NestedLoops.java @@ -165,7 +165,7 @@ class NestedLoops { /** Correct the orientation of the loops contained in the tree. * This is this method that really inverts the loops that where - * provided through the
[19/31] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java index 7df7277..36f0998 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Line.java @@ -19,10 +19,11 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.exception.util.LocalizedFormats; import org.apache.commons.math4.geometry.Point; +import org.apache.commons.math4.geometry.Vector; import org.apache.commons.math4.geometry.euclidean.oned.Euclidean1D; import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.oned.OrientedPoint; -import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D; +import org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D; import org.apache.commons.math4.geometry.partitioning.Embedding; import org.apache.commons.math4.geometry.partitioning.Hyperplane; import org.apache.commons.math4.geometry.partitioning.SubHyperplane; @@ -84,7 +85,7 @@ public class Line implements Hyperplane, Embedding, Embedding, Embedding, Embedding, Embedding vector) { -//return toSubSpace((Point) vector); -//} +public Cartesian1D toSubSpace(Vector vector) { +return toSubSpace((Cartesian2D) vector); +} /** Transform a sub-space point into a space point. * @param vector (n-1)-dimension point of the sub-space * @return n-dimension point of the space corresponding to the * specified sub-space point */ -//public Coordinates2D toSpace(Vector vector) { -//return toSpace((Point) vector); -//} +public Cartesian2D toSpace(Vector vector) { +return toSpace((Cartesian1D) vector); +} /** {@inheritDoc} */ @Override -public Coordinates1D toSubSpace(final Point point) { -Coordinates2D p2 = (Coordinates2D) point; -return new Coordinates1D(MathArrays.linearCombination(cos, p2.getX(), sin, p2.getY())); +public Cartesian1D toSubSpace(final Point point) { +return toSubSpace((Cartesian2D) point); } /** {@inheritDoc} */ @Override -public Coordinates2D toSpace(final Point point) { -final double abscissa = ((Coordinates1D) point).getX(); -return new Coordinates2D(MathArrays.linearCombination(abscissa, cos, -originOffset, sin), +public Cartesian2D toSpace(final Point point) { +return toSpace((Cartesian1D) point); +} + +/** Transform a space point into a sub-space point. + * @param cartesian n-dimension point of the space + * @return (n-1)-dimension point of the sub-space corresponding to + * the specified space point + */ +public Cartesian1D toSubSpace(final Cartesian2D cartesian) { +return new Cartesian1D(MathArrays.linearCombination(cos, cartesian.getX(), sin, cartesian.getY())); +} + +/** Transform a sub-space point into a space point. + * @param cartesian (n-1)-dimension point of the sub-space + * @return n-dimension point of the space corresponding to the + * specified sub-space point + */ +public Cartesian2D toSpace(Cartesian1D cartesian) { +final double abscissa = cartesian.getX(); +return new Cartesian2D(MathArrays.linearCombination(abscissa, cos, -originOffset, sin), MathArrays.linearCombination(abscissa, sin, originOffset, cos)); } @@ -258,12 +276,12 @@ public class Line implements Hyperplane, Embedding, Embedding vector) { -//return getOffset((Point) vector); -//} +public double getOffset(Vector vector) { +return getOffset((Cartesian2D) vector); +} /** {@inheritDoc} */ @Override public double getOffset(final Point point) { -Coordinates2D p2 = (Coordinates2D) point; -return MathArrays.linearCombination(sin, p2.getX(), -cos, p2.getY(), 1.0, originOffset); +return getOffset((Cartesian2D) point); +} + +/** Get the offset (oriented distance) of a point. + * @param cartesian point to check + * @return offset of the point + */ +public double getOffset(Cartesian2D cartesian) { +return MathArrays.linearCombination(sin, cartesian.getX(), -cos, cartesian.getY(), 1.0, originOffset); } /** {@inheritDoc} */ @@ -341,10 +366,10 @@ public class Line implements Hyperplane, Embedding, Embedding, Embedding, Embedding, Embedding, Embedding point) { -final Coordinates2D p2D = (Coordinates2D) point; +public Cartesian2D apply(final Poin
[25/31] [math] MATH-1284: Replace uses of Vector3D in user guide with Cartesian2D.
MATH-1284: Replace uses of Vector3D in user guide with Cartesian2D. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/e508ad09 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/e508ad09 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/e508ad09 Branch: refs/heads/master Commit: e508ad09d79302d3cc6b86077d4a6ddb0679a0f5 Parents: c7d2047 Author: Ray DeCampo Authored: Thu May 4 07:27:37 2017 -0400 Committer: Ray DeCampo Committed: Thu May 4 07:27:37 2017 -0400 -- .../math4/userguide/sofm/ChineseRings.java | 20 ++-- .../userguide/sofm/ChineseRingsClassifier.java | 10 +- 2 files changed, 15 insertions(+), 15 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/e508ad09/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java -- diff --git a/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java b/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java index 57393a6..a497da6 100644 --- a/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java +++ b/src/userguide/java/org/apache/commons/math4/userguide/sofm/ChineseRings.java @@ -20,7 +20,7 @@ package org.apache.commons.math4.userguide.sofm; import org.apache.commons.rng.UniformRandomProvider; import org.apache.commons.rng.simple.RandomSource; -import org.apache.commons.math4.geometry.euclidean.threed.Vector3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator; import org.apache.commons.math4.distribution.RealDistribution; @@ -32,7 +32,7 @@ import org.apache.commons.math4.distribution.UniformRealDistribution; */ public class ChineseRings { /** Points in the two rings. */ -private final Vector3D[] points; +private final Cartesian3D[] points; /** * @param orientationRing1 Vector othogonal to the plane containing the @@ -44,7 +44,7 @@ public class ChineseRings { * @param numPointsRing1 Number of points in the first ring. * @param numPointsRing2 Number of points in the second ring. */ -public ChineseRings(Vector3D orientationRing1, +public ChineseRings(Cartesian3D orientationRing1, double radiusRing1, double halfWidthRing1, double radiusRing2, @@ -52,9 +52,9 @@ public class ChineseRings { int numPointsRing1, int numPointsRing2) { // First ring (centered at the origin). -final Vector3D[] firstRing = new Vector3D[numPointsRing1]; +final Cartesian3D[] firstRing = new Cartesian3D[numPointsRing1]; // Second ring (centered around the first ring). -final Vector3D[] secondRing = new Vector3D[numPointsRing2]; +final Cartesian3D[] secondRing = new Cartesian3D[numPointsRing2]; // Create two rings lying in xy-plane. final UnitSphereRandomVectorGenerator unit @@ -72,7 +72,7 @@ public class ChineseRings { final double[] v = unit.nextVector(); final double r = radius1.sample(); // First ring is in the xy-plane, centered at (0, 0, 0). -firstRing[i] = new Vector3D(v[0] * r, +firstRing[i] = new Cartesian3D(v[0] * r, v[1] * r, widthRing1.sample()); } @@ -87,16 +87,16 @@ public class ChineseRings { final double[] v = unit.nextVector(); final double r = radius2.sample(); // Second ring is in the xz-plane, centered at (radiusRing1, 0, 0). -secondRing[i] = new Vector3D(radiusRing1 + v[0] * r, +secondRing[i] = new Cartesian3D(radiusRing1 + v[0] * r, widthRing2.sample(), v[1] * r); } // Move first and second rings into position. -final Rotation rot = new Rotation(Vector3D.PLUS_K, +final Rotation rot = new Rotation(Cartesian3D.PLUS_K, orientationRing1.normalize()); int count = 0; -points = new Vector3D[numPointsRing1 + numPointsRing2]; +points = new Cartesian3D[numPointsRing1 + numPointsRing2]; for (int i = 0; i < numPointsRing1; i++) { points[count++] = rot.applyTo(firstRing[i]); } @@ -108,7 +108,7 @@ public class ChineseRings { /** * Gets all the points. */ -public Vector3D[] getPo
[09/31] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java index 5de70a5..ff8f17e 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Rotation.java @@ -48,8 +48,8 @@ import org.apache.commons.math4.util.MathArrays; * Focus is oriented on what a rotation do rather than on its * underlying representation. Once it has been built, and regardless of its * internal representation, a rotation is an operator which basically - * transforms three dimensional {@link Vector3D vectors} into other three - * dimensional {@link Vector3D vectors}. Depending on the application, the + * transforms three dimensional {@link Coordinates3D vectors} into other three + * dimensional {@link Coordinates3D vectors}. Depending on the application, the * meaning of these vectors may vary and the semantics of the rotation also. * For example in an spacecraft attitude simulation tool, users will often * consider the vectors are fixed (say the Earth direction for example) and the @@ -88,7 +88,7 @@ import org.apache.commons.math4.util.MathArrays; * * Rotations are guaranteed to be immutable objects. * - * @see Vector3D + * @see Coordinates3D * @see RotationOrder * @since 1.2 */ @@ -162,7 +162,7 @@ public class Rotation implements Serializable { * @deprecated as of 3.6, replaced with {@link #Rotation(Vector3D, double, RotationConvention)} */ @Deprecated - public Rotation(Vector3D axis, double angle) throws MathIllegalArgumentException { + public Rotation(Coordinates3D axis, double angle) throws MathIllegalArgumentException { this(axis, angle, RotationConvention.VECTOR_OPERATOR); } @@ -173,7 +173,7 @@ public class Rotation implements Serializable { * @exception MathIllegalArgumentException if the axis norm is zero * @since 3.6 */ - public Rotation(final Vector3D axis, final double angle, final RotationConvention convention) + public Rotation(final Coordinates3D axis, final double angle, final RotationConvention convention) throws MathIllegalArgumentException { double norm = axis.getNorm(); @@ -272,18 +272,18 @@ public class Rotation implements Serializable { * @exception MathArithmeticException if the norm of one of the vectors is zero, * or if one of the pair is degenerated (i.e. the vectors of the pair are collinear) */ - public Rotation(Vector3D u1, Vector3D u2, Vector3D v1, Vector3D v2) + public Rotation(Coordinates3D u1, Coordinates3D u2, Coordinates3D v1, Coordinates3D v2) throws MathArithmeticException { // build orthonormalized base from u1, u2 // this fails when vectors are null or collinear, which is forbidden to define a rotation - final Vector3D u3 = u1.crossProduct(u2).normalize(); + final Coordinates3D u3 = u1.crossProduct(u2).normalize(); u2 = u3.crossProduct(u1).normalize(); u1 = u1.normalize(); // build an orthonormalized base from v1, v2 // this fails when vectors are null or collinear, which is forbidden to define a rotation - final Vector3D v3 = v1.crossProduct(v2).normalize(); + final Coordinates3D v3 = v1.crossProduct(v2).normalize(); v2 = v3.crossProduct(v1).normalize(); v1 = v1.normalize(); @@ -327,7 +327,7 @@ public class Rotation implements Serializable { * @param v desired image of u by the rotation * @exception MathArithmeticException if the norm of one of the vectors is zero */ - public Rotation(Vector3D u, Vector3D v) throws MathArithmeticException { + public Rotation(Coordinates3D u, Coordinates3D v) throws MathArithmeticException { double normProduct = u.getNorm() * v.getNorm(); if (normProduct == 0) { @@ -339,7 +339,7 @@ public class Rotation implements Serializable { if (dot < ((2.0e-15 - 1.0) * normProduct)) { // special case u = -v: we select a PI angle rotation around // an arbitrary vector orthogonal to u - Vector3D w = u.orthogonal(); + Coordinates3D w = u.orthogonal(); q0 = 0.0; q1 = -w.getX(); q2 = -w.getY(); @@ -349,7 +349,7 @@ public class Rotation implements Serializable { // the shortest possible rotation: axis orthogonal to this plane q0 = FastMath.sqrt(0.5 * (1.0 + dot / normProduct)); double coeff = 1.0 / (2.0 * q0 * normProduct); - Vector3D q = v.crossProduct(u); + Coordinates3D q = v.crossProduct(u); q1 = coeff * q.getX(); q2 = coeff * q.getY(); q3 = coeff * q.getZ(); @@ -522,7 +522,7 @@ public class Rotation implements Serializable { *
[16/31] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java index a2ebce8..a02ac26 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/RotationTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.geometry.euclidean.threed.CardanEulerSingularity import org.apache.commons.math4.geometry.euclidean.threed.NotARotationMatrixException; import org.apache.commons.math4.geometry.euclidean.threed.Rotation; import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder; -import org.apache.commons.math4.geometry.euclidean.threed.Coordinates3D; +import org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D; import org.apache.commons.math4.util.FastMath; import org.apache.commons.math4.util.MathUtils; import org.junit.Assert; @@ -36,21 +36,21 @@ public class RotationTest { public void testIdentity() { Rotation r = Rotation.IDENTITY; -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_I); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_K); checkAngle(r.getAngle(), 0); r = new Rotation(-1, 0, 0, 0, false); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_I); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_K); checkAngle(r.getAngle(), 0); r = new Rotation(42, 0, 0, 0, true); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_I); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_I); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_K); checkAngle(r.getAngle(), 0); } @@ -59,95 +59,95 @@ public class RotationTest { @Deprecated public void testAxisAngleDeprecated() throws MathIllegalArgumentException { -Rotation r = new Rotation(new Coordinates3D(10, 10, 10), 2 * FastMath.PI / 3); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordinates3D.PLUS_J); -checkVector(r.applyTo(Coordinates3D.PLUS_J), Coordinates3D.PLUS_K); -checkVector(r.applyTo(Coordinates3D.PLUS_K), Coordinates3D.PLUS_I); +Rotation r = new Rotation(new Cartesian3D(10, 10, 10), 2 * FastMath.PI / 3); +checkVector(r.applyTo(Cartesian3D.PLUS_I), Cartesian3D.PLUS_J); +checkVector(r.applyTo(Cartesian3D.PLUS_J), Cartesian3D.PLUS_K); +checkVector(r.applyTo(Cartesian3D.PLUS_K), Cartesian3D.PLUS_I); double s = 1 / FastMath.sqrt(3); -checkVector(r.getAxis(), new Coordinates3D(s, s, s)); +checkVector(r.getAxis(), new Cartesian3D(s, s, s)); checkAngle(r.getAngle(), 2 * FastMath.PI / 3); try { - new Rotation(new Coordinates3D(0, 0, 0), 2 * FastMath.PI / 3); + new Rotation(new Cartesian3D(0, 0, 0), 2 * FastMath.PI / 3); Assert.fail("an exception should have been thrown"); } catch (MathIllegalArgumentException e) { } -r = new Rotation(Coordinates3D.PLUS_K, 1.5 * FastMath.PI); -checkVector(r.getAxis(), new Coordinates3D(0, 0, -1)); +r = new Rotation(Cartesian3D.PLUS_K, 1.5 * FastMath.PI); +checkVector(r.getAxis(), new Cartesian3D(0, 0, -1)); checkAngle(r.getAngle(), 0.5 * FastMath.PI); -r = new Rotation(Coordinates3D.PLUS_J, FastMath.PI); -checkVector(r.getAxis(), Coordinates3D.PLUS_J); +r = new Rotation(Cartesian3D.PLUS_J, FastMath.PI); +checkVector(r.getAxis(), Cartesian3D.PLUS_J); checkAngle(r.getAngle(), FastMath.PI); -checkVector(Rotation.IDENTITY.getAxis(), Coordinates3D.PLUS_I); +checkVector(Rotation.IDENTITY.getAxis(), Cartesian3D.PLUS_I); } @Test public void testAxisAngleVectorOperator() throws MathIllegalArgumentException { -Rotation r = new Rotation(new Coordinates3D(10, 10, 10), 2 * FastMath.PI / 3, RotationConvention.VECTOR_OPERATOR); -checkVector(r.applyTo(Coordinates3D.PLUS_I), Coordi
[26/31] [math] MATH-1284: Replace uses of "Vector1D" in comments and supporting files with "Cartesian1D".
MATH-1284: Replace uses of "Vector1D" in comments and supporting files with "Cartesian1D". Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a27ca511 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a27ca511 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a27ca511 Branch: refs/heads/master Commit: a27ca511a591caf813c26862a888e90e54af19a9 Parents: e508ad0 Author: Ray DeCampo Authored: Thu May 4 07:30:27 2017 -0400 Committer: Ray DeCampo Committed: Thu May 4 07:30:27 2017 -0400 -- .../geometry/euclidean/oned/Cartesian1D.java| 6 +- .../math4/geometry/partitioning/Embedding.java | 2 +- src/site/xdoc/userguide/geometry.xml| 4 +- .../euclidean/oned/Cartesian1DTest.java | 219 +++ .../geometry/euclidean/oned/Vector1DTest.java | 219 --- 5 files changed, 225 insertions(+), 225 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java index 0a248a1..f406125 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1D.java @@ -126,7 +126,7 @@ public class Cartesian1D implements Point, Vector { /** Get the abscissa of the vector. * @return abscissa of the vector - * @see #Vector1D(double) + * @see #Cartesian1D(double) */ public double getX() { return x; @@ -332,8 +332,8 @@ public class Cartesian1D implements Point, Vector { * * @param other Object to test for equality to this * @return true if two 1D vector objects are equal, false if - * object is null, not an instance of Vector1D, or - * not equal to this Vector1D instance + * object is null, not an instance of Cartesian1D, or + * not equal to this Cartesian1D instance * */ @Override http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java b/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java index ae48f11..9e78d90 100644 --- a/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java +++ b/src/main/java/org/apache/commons/math4/geometry/partitioning/Embedding.java @@ -28,7 +28,7 @@ import org.apache.commons.math4.geometry.Space; * org.apache.commons.math4.geometry.euclidean.threed.Line Line} in 3D * implements Embedding<{@link * org.apache.commons.math4.geometry.euclidean.threed.Cartesian3D Cartesian3D}, {link - * org.apache.commons.math4.geometry.euclidean.oned.Vector1D Vector1D}, i.e. it + * org.apache.commons.math4.geometry.euclidean.oned.Cartesian1D Cartesian1D}, i.e. it * maps directly dimensions 3 and 1. * In the 3D euclidean space, hyperplanes are 2D planes, and the 1D http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/site/xdoc/userguide/geometry.xml -- diff --git a/src/site/xdoc/userguide/geometry.xml b/src/site/xdoc/userguide/geometry.xml index 6c76e3b..4242c96 100644 --- a/src/site/xdoc/userguide/geometry.xml +++ b/src/site/xdoc/userguide/geometry.xml @@ -76,8 +76,8 @@ - - Vector1D, + + Cartesian1D, Cartesian2D and Cartesian3D provide simple vector types. One important feature is that instances of these classes are guaranteed http://git-wip-us.apache.org/repos/asf/commons-math/blob/a27ca511/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java new file mode 100644 index 000..2b60c3d --- /dev/null +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/oned/Cartesian1DTest.java @@ -0,0 +1,219 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional informat
[13/31] [math] MATH-1284: Replace/rename Coordinate?D classes (nee Vector?D) as Cartesian?D classes as per discussion. When there are existing overridden methods accepting Vector and Poin
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java index 41f9d77..cbbd003 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; -import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; +import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D; import org.apache.commons.math4.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -27,20 +27,20 @@ public class SegmentTest { @Test public void testDistance() { -Coordinates2D start = new Coordinates2D(2, 2); -Coordinates2D end = new Coordinates2D(-2, -2); +Cartesian2D start = new Cartesian2D(2, 2); +Cartesian2D end = new Cartesian2D(-2, -2); Segment segment = new Segment(start, end, new Line(start, end, 1.0e-10)); // distance to center of segment -Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Coordinates2D(1, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Cartesian2D(1, -1)), 1.0e-10); // distance a point on segment -Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Coordinates2D(0, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Cartesian2D(0, -1)), 1.0e-10); // distance to end point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, 4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Cartesian2D(0, 4)), 1.0e-10); // distance to start point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, -4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Cartesian2D(0, -4)), 1.0e-10); } } http://git-wip-us.apache.org/repos/asf/commons-math/blob/e21d4d43/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java index c59ab8c..cdfc2c0 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; +import org.apache.commons.math4.geometry.euclidean.twod.Cartesian2D; import org.apache.commons.math4.geometry.partitioning.RegionFactory; import org.junit.Assert; import org.junit.Test; @@ -32,19 +32,19 @@ public class SubLineTest { @Test public void testEndPoints() { -Coordinates2D p1 = new Coordinates2D(-1, -7); -Coordinates2D p2 = new Coordinates2D(7, -1); +Cartesian2D p1 = new Cartesian2D(-1, -7); +Cartesian2D p2 = new Cartesian2D(7, -1); Segment segment = new Segment(p1, p2, new Line(p1, p2, 1.0e-10)); SubLine sub = new SubLine(segment); List segments = sub.getSegments(); Assert.assertEquals(1, segments.size()); -Assert.assertEquals(0.0, new Coordinates2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); -Assert.assertEquals(0.0, new Coordinates2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); +Assert.assertEquals(0.0, new Cartesian2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); +Assert.assertEquals(0.0, new Cartesian2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); } @Test public void testNoEndPoints() { -SubLine wholeLine = new Line(new Coordinates2D(-1, 7), new Coordinates2D(7, 1), 1.0e-10).wholeHyperplane(); +SubLine wholeLine = new Line(new Cartesian2D(-1, 7), new Cartesian2D(7, 1), 1.0e-10).wholeHyperplane(); List segments = wholeLine.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getX())
[03/31] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java index 08ffdcd..01bfdb3 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java @@ -22,12 +22,12 @@ import java.util.List; import org.apache.commons.math4.exception.MathIllegalArgumentException; import org.apache.commons.math4.geometry.euclidean.oned.Interval; import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; -import org.apache.commons.math4.geometry.euclidean.oned.Vector1D; +import org.apache.commons.math4.geometry.euclidean.oned.Coordinates1D; import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.PolygonsSet; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Vector2D; +import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; import org.apache.commons.math4.geometry.partitioning.BSPTree; import org.apache.commons.math4.geometry.partitioning.BSPTreeVisitor; import org.apache.commons.math4.geometry.partitioning.BoundaryProjection; @@ -44,41 +44,41 @@ public class PolygonsSetTest { @Test public void testSimplyConnected() { -Vector2D[][] vertices = new Vector2D[][] { -new Vector2D[] { -new Vector2D(36.0, 22.0), -new Vector2D(39.0, 32.0), -new Vector2D(19.0, 32.0), -new Vector2D( 6.0, 16.0), -new Vector2D(31.0, 10.0), -new Vector2D(42.0, 16.0), -new Vector2D(34.0, 20.0), -new Vector2D(29.0, 19.0), -new Vector2D(23.0, 22.0), -new Vector2D(33.0, 25.0) +Coordinates2D[][] vertices = new Coordinates2D[][] { +new Coordinates2D[] { +new Coordinates2D(36.0, 22.0), +new Coordinates2D(39.0, 32.0), +new Coordinates2D(19.0, 32.0), +new Coordinates2D( 6.0, 16.0), +new Coordinates2D(31.0, 10.0), +new Coordinates2D(42.0, 16.0), +new Coordinates2D(34.0, 20.0), +new Coordinates2D(29.0, 19.0), +new Coordinates2D(23.0, 22.0), +new Coordinates2D(33.0, 25.0) } }; PolygonsSet set = buildSet(vertices); -Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector2D(50.0, 30.0))); -checkPoints(Region.Location.INSIDE, set, new Vector2D[] { -new Vector2D(30.0, 15.0), -new Vector2D(15.0, 20.0), -new Vector2D(24.0, 25.0), -new Vector2D(35.0, 30.0), -new Vector2D(19.0, 17.0) +Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Coordinates2D(50.0, 30.0))); +checkPoints(Region.Location.INSIDE, set, new Coordinates2D[] { +new Coordinates2D(30.0, 15.0), +new Coordinates2D(15.0, 20.0), +new Coordinates2D(24.0, 25.0), +new Coordinates2D(35.0, 30.0), +new Coordinates2D(19.0, 17.0) }); -checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] { -new Vector2D(50.0, 30.0), -new Vector2D(30.0, 35.0), -new Vector2D(10.0, 25.0), -new Vector2D(10.0, 10.0), -new Vector2D(40.0, 10.0), -new Vector2D(50.0, 15.0), -new Vector2D(30.0, 22.0) +checkPoints(Region.Location.OUTSIDE, set, new Coordinates2D[] { +new Coordinates2D(50.0, 30.0), +new Coordinates2D(30.0, 35.0), +new Coordinates2D(10.0, 25.0), +new Coordinates2D(10.0, 10.0), +new Coordinates2D(40.0, 10.0), +new Coordinates2D(50.0, 15.0), +new Coordinates2D(30.0, 22.0) }); -checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] { -new Vector2D(30.0, 32.0), -new Vector2D(34.0, 20.0) +checkPoints(Region.Location.BOUNDARY, set, new Coordinates2D[] { +new Coordinates2D(30.0, 32.0), +new Coordinates2D(34.0, 20.0) }); checkVertices(set.getVertices(), vertices); } @@ -98,18 +98,18 @@ public class PolygonsSetTest { @Test public void testStair() { -Vector2D[][] vertices = new Vector2D[][] { -new Vector2D[] { -new Vector2D( 0.0, 0.0), -
[02/31] [math] MATH-1284: Vector no longer extends Point. Replace/rename Vector?D classes with Coordinate?D classes which implement both Vector and Point. When there are multiple implementations of th
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java index 6c2ea15..41f9d77 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SegmentTest.java @@ -18,7 +18,7 @@ package org.apache.commons.math4.geometry.euclidean.twod; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; -import org.apache.commons.math4.geometry.euclidean.twod.Vector2D; +import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; import org.apache.commons.math4.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -27,20 +27,20 @@ public class SegmentTest { @Test public void testDistance() { -Vector2D start = new Vector2D(2, 2); -Vector2D end = new Vector2D(-2, -2); +Coordinates2D start = new Coordinates2D(2, 2); +Coordinates2D end = new Coordinates2D(-2, -2); Segment segment = new Segment(start, end, new Line(start, end, 1.0e-10)); // distance to center of segment -Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Vector2D(1, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(2), segment.distance(new Coordinates2D(1, -1)), 1.0e-10); // distance a point on segment -Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Vector2D(0, -1)), 1.0e-10); +Assert.assertEquals(FastMath.sin(Math.PI / 4.0), segment.distance(new Coordinates2D(0, -1)), 1.0e-10); // distance to end point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, 4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, 4)), 1.0e-10); // distance to start point -Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Vector2D(0, -4)), 1.0e-10); +Assert.assertEquals(FastMath.sqrt(8), segment.distance(new Coordinates2D(0, -4)), 1.0e-10); } } http://git-wip-us.apache.org/repos/asf/commons-math/blob/b815d2af/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java -- diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java index 249c5d7..c59ab8c 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/SubLineTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math4.geometry.euclidean.oned.IntervalsSet; import org.apache.commons.math4.geometry.euclidean.twod.Line; import org.apache.commons.math4.geometry.euclidean.twod.Segment; import org.apache.commons.math4.geometry.euclidean.twod.SubLine; -import org.apache.commons.math4.geometry.euclidean.twod.Vector2D; +import org.apache.commons.math4.geometry.euclidean.twod.Coordinates2D; import org.apache.commons.math4.geometry.partitioning.RegionFactory; import org.junit.Assert; import org.junit.Test; @@ -32,19 +32,19 @@ public class SubLineTest { @Test public void testEndPoints() { -Vector2D p1 = new Vector2D(-1, -7); -Vector2D p2 = new Vector2D(7, -1); +Coordinates2D p1 = new Coordinates2D(-1, -7); +Coordinates2D p2 = new Coordinates2D(7, -1); Segment segment = new Segment(p1, p2, new Line(p1, p2, 1.0e-10)); SubLine sub = new SubLine(segment); List segments = sub.getSegments(); Assert.assertEquals(1, segments.size()); -Assert.assertEquals(0.0, new Vector2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); -Assert.assertEquals(0.0, new Vector2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); +Assert.assertEquals(0.0, new Coordinates2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); +Assert.assertEquals(0.0, new Coordinates2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); } @Test public void testNoEndPoints() { -SubLine wholeLine = new Line(new Vector2D(-1, 7), new Vector2D(7, 1), 1.0e-10).wholeHyperplane(); +SubLine wholeLine = new Line(new Coordinates2D(-1, 7), new Coordinates2D(7, 1), 1.0e-10).wholeHyperplane(); List segments = wholeLine.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getX()) && @@ -59,7 +59,7 @@ public class SubLineTest {
[23/31] [math] MATH-1284: Replace uses of "Vector3D" in comments and supporting files with "Cartesian3D".
MATH-1284: Replace uses of "Vector3D" in comments and supporting files with "Cartesian3D". Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a3984815 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a3984815 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a3984815 Branch: refs/heads/master Commit: a3984815ebf24df07c2add09fbf0069f54666a20 Parents: e21d4d4 Author: Ray DeCampo Authored: Sun Apr 30 08:26:36 2017 -0400 Committer: Ray DeCampo Committed: Sun Apr 30 08:26:36 2017 -0400 -- findbugs-exclude-filter.xml | 6 +- .../geometry/euclidean/threed/Cartesian3D.java | 24 ++-- .../euclidean/threed/FieldRotation.java | 48 .../euclidean/threed/FieldVector3D.java | 14 +-- .../geometry/euclidean/threed/Rotation.java | 110 +-- .../euclidean/threed/RotationConvention.java| 16 +-- .../math4/geometry/partitioning/Embedding.java | 2 +- .../math4/geometry/spherical/twod/Circle.java | 4 +- .../spherical/twod/SphericalPolygonsSet.java| 2 +- src/site/design/threeD.puml | 4 +- src/site/xdoc/userguide/geometry.xml| 12 +- 11 files changed, 121 insertions(+), 121 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3984815/findbugs-exclude-filter.xml -- diff --git a/findbugs-exclude-filter.xml b/findbugs-exclude-filter.xml index 86d0087..7a90945 100644 --- a/findbugs-exclude-filter.xml +++ b/findbugs-exclude-filter.xml @@ -81,9 +81,9 @@ - - - + + + http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3984815/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java index 85696f6..5dc04c5 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java @@ -196,7 +196,7 @@ public class Cartesian3D implements Serializable, Point, Vector, Vector, Vector, Vector, Vector, Vector, Vector - * Vector3D k = u.normalize(); - * Vector3D i = k.orthogonal(); - * Vector3D j = Vector3D.crossProduct(k, i); + * Cartesian3D k = u.normalize(); + * Cartesian3D i = k.orthogonal(); + * Cartesian3D j = Cartesian3D.crossProduct(k, i); * * @return a new normalized vector orthogonal to the instance * @exception MathArithmeticException if the norm of the instance is null @@ -423,8 +423,8 @@ public class Cartesian3D implements Serializable, Point, Vector, Vector v) { final Cartesian3D v3 = (Cartesian3D) v; http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3984815/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java index 6392e3f..d3853c0 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java @@ -815,9 +815,9 @@ public class FieldRotation> implements Serializabl } else { if (order == RotationOrder.XYZ) { -// r (Vector3D.plusI) coordinates are : +// r (Cartesian3D.plusI) coordinates are : // cos (theta) cos (psi), -cos (theta) sin (psi), sin (theta) -// (-r) (Vector3D.plusK) coordinates are : +// (-r) (Cartesian3D.plusK) coordinates are : // sin (theta), -sin (phi) cos (theta), cos (phi) cos (theta) // and we can choose to have theta in the interval [-PI/2 ; +PI/2] FieldVector3D v1 = applyTo(Cartesian3D.PLUS_I); @@ -831,9 +831,9 @@ public class FieldRotation> implements Serializabl } else if (order == RotationOrder.XZY) { -// r (Vector3D.plusI) coordinates are : +// r (Cartesian3D.plusI) coordinates are : // cos (psi) cos (theta), -sin (psi), cos (psi) sin (theta) -// (-r) (Vector3D.plusJ) coordinates are : +// (-r) (Cartesian3D.plusJ) coordinates are : // -sin (psi),
[29/31] [math] MATH-1284: Restore Vector3D class as an abstract implementation of Vector and now Cartesian3D extends Vector3D. Restore the public interface of Vector3DFormat to act on Vec
MATH-1284: Restore Vector3D class as an abstract implementation of Vector and now Cartesian3D extends Vector3D. Restore the public interface of Vector3DFormat to act on Vector3D. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/05edf063 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/05edf063 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/05edf063 Branch: refs/heads/master Commit: 05edf06360cc8a1a61fbd1ce5f9abf5d83f9d3f9 Parents: 09c55eb Author: Ray DeCampo Authored: Sat May 6 10:59:17 2017 -0400 Committer: Ray DeCampo Committed: Sat May 6 10:59:17 2017 -0400 -- .../geometry/euclidean/threed/Cartesian3D.java | 2 +- .../geometry/euclidean/threed/Vector3D.java | 46 .../euclidean/threed/Vector3DFormat.java| 20 - .../threed/Vector3DFormatAbstractTest.java | 42 +- 4 files changed, 78 insertions(+), 32 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java index 5dc04c5..3880edf 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java @@ -39,7 +39,7 @@ import org.apache.commons.math4.util.MathUtils; * Instance of this class are guaranteed to be immutable. * @since 4.0 */ -public class Cartesian3D implements Serializable, Point, Vector { +public class Cartesian3D extends Vector3D implements Serializable, Point { /** Null vector (coordinates: 0, 0, 0). */ public static final Cartesian3D ZERO = new Cartesian3D(0, 0, 0); http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java new file mode 100644 index 000..23d644a --- /dev/null +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java @@ -0,0 +1,46 @@ +/* + * 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.math4.geometry.euclidean.threed; + +import org.apache.commons.math4.geometry.Vector; + +/** + * This class implements vectors in a three-dimensional space. + * @since 1.2 + */ +public abstract class Vector3D implements Vector { + +/** Get the abscissa of the vector. + * @return abscissa of the vector + * @see #Cartesian3D(double, double, double) + */ +public abstract double getX(); + +/** Get the ordinate of the vector. + * @return ordinate of the vector + * @see #Cartesian3D(double, double, double) + */ +public abstract double getY(); + +/** Get the height of the vector. + * @return height of the vector + * @see #Cartesian3D(double, double, double) + */ +public abstract double getZ(); + +} http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java -- diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java index dc2c0f9..1991c53 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java @@ -104,7 +104,7 @@ public class Vecto