Skip to content

Commit

Permalink
[SEDONA-204] Change Double.MIN_Value to -Double.MAX_Value (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayuasu committed Dec 12, 2022
1 parent 9fff785 commit 7dbefc4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
8 changes: 4 additions & 4 deletions common/src/main/java/org/apache/sedona/common/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static double xMin(Geometry geometry) {

public static double xMax(Geometry geometry) {
Coordinate[] points = geometry.getCoordinates();
double max = Double.MIN_VALUE;
double max = - Double.MAX_VALUE;
for (int i=0; i < points.length; i++) {
max = Math.max(points[i].getX(), max);
}
Expand All @@ -148,7 +148,7 @@ public static double yMin(Geometry geometry) {

public static double yMax(Geometry geometry) {
Coordinate[] points = geometry.getCoordinates();
double max = Double.MIN_VALUE;
double max = - Double.MAX_VALUE;
for (int i=0; i < points.length; i++) {
max = Math.max(points[i].getY(), max);
}
Expand All @@ -157,13 +157,13 @@ public static double yMax(Geometry geometry) {

public static Double zMax(Geometry geometry) {
Coordinate[] points = geometry.getCoordinates();
double max = Double.MIN_VALUE;
double max = - Double.MAX_VALUE;
for (int i=0; i < points.length; i++) {
if(java.lang.Double.isNaN(points[i].getZ()))
continue;
max = Math.max(points[i].getZ(), max);
}
return max == Double.MIN_VALUE ? null : max;
return max == -Double.MAX_VALUE ? null : max;
}

public static Double zMin(Geometry geometry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class Accumulators {
public static class Envelope {
public double minX = Double.MAX_VALUE;
public double minY = Double.MAX_VALUE;
public double maxX = Double.MIN_VALUE;
public double maxY = Double.MIN_VALUE;
public double maxX = -Double.MAX_VALUE;
public double maxY = -Double.MAX_VALUE;
void reset() {
minX = Double.MAX_VALUE;
minY = Double.MAX_VALUE;
maxX = Double.MIN_VALUE;
maxY = Double.MIN_VALUE;
maxX = -Double.MAX_VALUE;
maxY = -Double.MAX_VALUE;
}
}
public static class AccGeometry {
Expand Down
12 changes: 5 additions & 7 deletions sql/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ import org.apache.commons.codec.binary.Hex
import org.apache.sedona.sql.implicits._
import org.apache.spark.sql.functions._
import org.apache.spark.sql.{DataFrame, Row}
import org.geotools.referencing.CRS
import org.locationtech.jts.algorithm.MinimumBoundingCircle
import org.locationtech.jts.geom.{Geometry, Polygon}
import org.locationtech.jts.io.WKTWriter
import org.locationtech.jts.linearref.LengthIndexedLine
import org.locationtech.jts.operation.distance3d.Distance3DOp
import org.opengis.referencing.{FactoryException, NoSuchAuthorityCodeException}
import org.scalatest.{GivenWhenThen, Matchers}
import org.xml.sax.InputSource
import java.io.StringReader

import java.io.StringReader
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPathFactory
import org.apache.sedona.sql.utils.GeometrySerializer
import org.apache.spark.SparkException
import org.geotools.referencing.CRS
import org.opengis.referencing.{FactoryException, NoSuchAuthorityCodeException}

class functionTestScala extends TestBaseScala with Matchers with GeometrySample with GivenWhenThen {

Expand Down Expand Up @@ -73,8 +71,8 @@ class functionTestScala extends TestBaseScala with Matchers with GeometrySample
}

it("Passed ST_YMax") {
var test = sparkSession.sql("SELECT ST_YMax(ST_GeomFromWKT('POLYGON ((-3 -3, 3 -3, 3 3, -3 3, -3 -3))'))")
assert(test.take(1)(0).get(0).asInstanceOf[Double] == 3.0)
var test = sparkSession.sql("SELECT ST_YMax(ST_GeomFromWKT('POLYGON ((-3 -3, 3 -3, 3 -2, -3 -1, -3 -3))'))")
assert(test.take(1)(0).get(0).asInstanceOf[Double] == -1)
}

it("Passed ST_YMin") {
Expand Down

0 comments on commit 7dbefc4

Please sign in to comment.