This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit cd225fa8b46e48558139af7c9620e956e3ebb5ba
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jun 11 10:58:04 2019 +0200
Leverage java.util.function for Line and Plane equations.
---
.../src/main/java/org/apache/sis/math/Line.java | 22 +++++++++++++++++++---
.../src/main/java/org/apache/sis/math/Plane.java | 21 +++++++++++++++++++--
2 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/Line.java b/core/sis-utility/src/main/java/org/apache/sis/math/Line.java
index 3493df9..34f38fb 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/Line.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/Line.java
@@ -17,6 +17,7 @@
package org.apache.sis.math;
import java.io.Serializable;
+import java.util.function.DoubleUnaryOperator;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
import org.apache.sis.internal.util.DoubleDouble;
@@ -43,7 +44,7 @@ import static java.lang.Double.*;
* and (<var>x₂</var>,<var>y₂</var>) points, {@code Line} objects
extend toward infinity.</div>
*
* @author Martin Desruisseaux (MPO, IRD)
- * @version 0.8
+ * @version 1.0
*
* @see Plane
* @see org.apache.sis.referencing.operation.builder.LinearTransformBuilder
@@ -51,7 +52,7 @@ import static java.lang.Double.*;
* @since 0.5
* @module
*/
-public class Line implements Cloneable, Serializable {
+public class Line implements DoubleUnaryOperator, Cloneable, Serializable {
/**
* Serial number for compatibility with different versions.
*/
@@ -155,7 +156,7 @@ public class Line implements Cloneable, Serializable {
* Computes <var>y</var> = <var>f</var>(<var>x</var>).
* If the line is vertical, then this method returns an infinite value.
*
- * @param x the <var>x</var> value where to evaluate the inverse function.
+ * @param x the <var>x</var> value where to evaluate the function.
* @return the <var>y</var> value for the given <var>x</var>
value.
*
* @see #x(double)
@@ -165,6 +166,21 @@ public class Line implements Cloneable, Serializable {
}
/**
+ * Evaluates this equation for the given value. The default implementation delegates
+ * to {@link #y(double) y(x)}, but subclasses may override with different formulas.
+ * This method is provided for interoperability with libraries making use of {@link java.util.function}.
+ *
+ * @param x the value where to evaluate the function.
+ * @return the function value for the given operand.
+ *
+ * @since 1.0
+ */
+ @Override
+ public double applyAsDouble(double x) {
+ return y(x);
+ }
+
+ /**
* Translates the line. The slope stay unchanged.
*
* @param dx the horizontal translation.
diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java b/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java
index e8e6b2e..1583f81 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java
@@ -18,6 +18,7 @@ package org.apache.sis.math;
import java.util.Iterator;
import java.io.Serializable;
+import java.util.function.DoubleBinaryOperator;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
import org.apache.sis.internal.util.DoubleDouble;
@@ -46,7 +47,7 @@ import static java.lang.Math.ulp;
*
* @author Martin Desruisseaux (MPO, IRD)
* @author Howard Freeland (MPO, for algorithmic inspiration)
- * @version 0.8
+ * @version 1.0
*
* @see Line
* @see org.apache.sis.referencing.operation.builder.LinearTransformBuilder
@@ -54,7 +55,7 @@ import static java.lang.Math.ulp;
* @since 0.5
* @module
*/
-public class Plane implements Cloneable, Serializable {
+public class Plane implements DoubleBinaryOperator, Cloneable, Serializable {
/**
* Serial number for compatibility with different versions.
*/
@@ -202,6 +203,22 @@ public class Plane implements Cloneable, Serializable {
}
/**
+ * Evaluates this equation for the given values. The default implementation delegates
to
+ * {@link #z(double,double) z(x,y)}, but subclasses may override with different formulas.
+ * This method is provided for interoperability with libraries making use of {@link java.util.function}.
+ *
+ * @param x the first operand where to evaluate the function.
+ * @param y the second operand where to evaluate the function.
+ * @return the function value for the given operands.
+ *
+ * @since 1.0
+ */
+ @Override
+ public double applyAsDouble(double x, double y) {
+ return z(x, y);
+ }
+
+ /**
* Sets the equation of this plane to the given coefficients.
*
* @param sx the slope along the <var>x</var> values.
|