You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kw...@apache.org on 2016/06/22 11:51:27 UTC
[1/2] lucene-solr:master: LUCENE-7194: Ban Math.toRadians and
Math.toDegrees
Repository: lucene-solr
Updated Branches:
refs/heads/master 7afa3333c -> ece9d85cb
LUCENE-7194: Ban Math.toRadians and Math.toDegrees
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b11e48c7
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b11e48c7
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b11e48c7
Branch: refs/heads/master
Commit: b11e48c7553daed127b1b231641d7367a09aed1b
Parents: 740198f
Author: Karl Wright <Da...@gmail.com>
Authored: Wed Jun 22 03:53:47 2016 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Wed Jun 22 03:53:47 2016 -0400
----------------------------------------------------------------------
.../java/org/apache/lucene/geo/Rectangle.java | 4 +--
.../java/org/apache/lucene/util/SloppyMath.java | 20 ++++++++++++++-
.../demo/facet/DistanceFacetsExample.java | 27 ++++++++++----------
.../lucene/spatial3d/geom/GeoPathTest.java | 2 +-
.../org/apache/lucene/geo/EarthDebugger.java | 4 +--
.../java/org/apache/lucene/geo/GeoTestUtil.java | 8 +++---
lucene/tools/forbiddenApis/lucene.txt | 3 +++
7 files changed, 45 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b11e48c7/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java b/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
index 592e202..c8fddf7 100644
--- a/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
+++ b/lucene/core/src/java/org/apache/lucene/geo/Rectangle.java
@@ -19,8 +19,6 @@ package org.apache.lucene.geo;
import static java.lang.Math.PI;
import static java.lang.Math.max;
import static java.lang.Math.min;
-import static java.lang.Math.toDegrees;
-import static java.lang.Math.toRadians;
import static org.apache.lucene.geo.GeoUtils.checkLatitude;
import static org.apache.lucene.geo.GeoUtils.checkLongitude;
import static org.apache.lucene.geo.GeoUtils.MAX_LAT_INCL;
@@ -34,6 +32,8 @@ import static org.apache.lucene.geo.GeoUtils.sloppySin;
import static org.apache.lucene.util.SloppyMath.TO_DEGREES;
import static org.apache.lucene.util.SloppyMath.asin;
import static org.apache.lucene.util.SloppyMath.cos;
+import static org.apache.lucene.util.SloppyMath.toDegrees;
+import static org.apache.lucene.util.SloppyMath.toRadians;
/** Represents a lat/lon rectangle. */
public class Rectangle {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b11e48c7/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java b/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
index 0bfca5e..44f2c3b 100644
--- a/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
+++ b/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
@@ -176,6 +176,24 @@ public class SloppyMath {
}
}
+ /**
+ * Convert to degrees.
+ * @param radians radians to convert to degrees
+ * @return degrees
+ */
+ public static double toDegrees(final double radians) {
+ return radians * TO_DEGREES;
+ }
+
+ /**
+ * Convert to radians.
+ * @param degrees degrees to convert to radians
+ * @return radians
+ */
+ public static double toRadians(final double degrees) {
+ return degrees * TO_RADIANS;
+ }
+
// haversin
// TODO: remove these for java 9, they fixed Math.toDegrees()/toRadians() to work just like this.
public static final double TO_RADIANS = Math.PI / 180D;
@@ -209,7 +227,7 @@ public class SloppyMath {
// Supposed to be >= sin(77.2deg), as fdlibm code is supposed to work with values > 0.975,
// but seems to work well enough as long as value >= sin(25deg).
- private static final double ASIN_MAX_VALUE_FOR_TABS = StrictMath.sin(Math.toRadians(73.0));
+ private static final double ASIN_MAX_VALUE_FOR_TABS = StrictMath.sin(toRadians(73.0));
private static final int ASIN_TABS_SIZE = (1<<13) + 1;
private static final double ASIN_DELTA = ASIN_MAX_VALUE_FOR_TABS/(ASIN_TABS_SIZE - 1);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b11e48c7/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
----------------------------------------------------------------------
diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
index 96ca57c..7d029ee 100644
--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
@@ -46,6 +46,7 @@ import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.SloppyMath;
import java.io.Closeable;
import java.io.IOException;
@@ -148,8 +149,8 @@ public class DistanceFacetsExample implements Closeable {
// since it's a 2D trie...
// Degrees -> Radians:
- double originLatRadians = Math.toRadians(originLat);
- double originLngRadians = Math.toRadians(originLng);
+ double originLatRadians = SloppyMath.toRadians(originLat);
+ double originLngRadians = SloppyMath.toRadians(originLng);
double angle = maxDistanceKM / EARTH_RADIUS_KM;
@@ -158,28 +159,28 @@ public class DistanceFacetsExample implements Closeable {
double minLng;
double maxLng;
- if (minLat > Math.toRadians(-90) && maxLat < Math.toRadians(90)) {
+ if (minLat > SloppyMath.toRadians(-90) && maxLat < SloppyMath.toRadians(90)) {
double delta = Math.asin(Math.sin(angle)/Math.cos(originLatRadians));
minLng = originLngRadians - delta;
- if (minLng < Math.toRadians(-180)) {
+ if (minLng < SloppyMath.toRadians(-180)) {
minLng += 2 * Math.PI;
}
maxLng = originLngRadians + delta;
- if (maxLng > Math.toRadians(180)) {
+ if (maxLng > SloppyMath.toRadians(180)) {
maxLng -= 2 * Math.PI;
}
} else {
// The query includes a pole!
- minLat = Math.max(minLat, Math.toRadians(-90));
- maxLat = Math.min(maxLat, Math.toRadians(90));
- minLng = Math.toRadians(-180);
- maxLng = Math.toRadians(180);
+ minLat = Math.max(minLat, SloppyMath.toRadians(-90));
+ maxLat = Math.min(maxLat, SloppyMath.toRadians(90));
+ minLng = SloppyMath.toRadians(-180);
+ maxLng = SloppyMath.toRadians(180);
}
BooleanQuery.Builder f = new BooleanQuery.Builder();
// Add latitude range filter:
- f.add(DoublePoint.newRangeQuery("latitude", Math.toDegrees(minLat), Math.toDegrees(maxLat)),
+ f.add(DoublePoint.newRangeQuery("latitude", SloppyMath.toDegrees(minLat), SloppyMath.toDegrees(maxLat)),
BooleanClause.Occur.FILTER);
// Add longitude range filter:
@@ -187,13 +188,13 @@ public class DistanceFacetsExample implements Closeable {
// The bounding box crosses the international date
// line:
BooleanQuery.Builder lonF = new BooleanQuery.Builder();
- lonF.add(DoublePoint.newRangeQuery("longitude", Math.toDegrees(minLng), Double.POSITIVE_INFINITY),
+ lonF.add(DoublePoint.newRangeQuery("longitude", SloppyMath.toDegrees(minLng), Double.POSITIVE_INFINITY),
BooleanClause.Occur.SHOULD);
- lonF.add(DoublePoint.newRangeQuery("longitude", Double.NEGATIVE_INFINITY, Math.toDegrees(maxLng)),
+ lonF.add(DoublePoint.newRangeQuery("longitude", Double.NEGATIVE_INFINITY, SloppyMath.toDegrees(maxLng)),
BooleanClause.Occur.SHOULD);
f.add(lonF.build(), BooleanClause.Occur.MUST);
} else {
- f.add(DoublePoint.newRangeQuery("longitude", Math.toDegrees(minLng), Math.toDegrees(maxLng)),
+ f.add(DoublePoint.newRangeQuery("longitude", SloppyMath.toDegrees(minLng), SloppyMath.toDegrees(maxLng)),
BooleanClause.Occur.FILTER);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b11e48c7/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
index 96c7ea7..f5dd8b0 100755
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
@@ -18,7 +18,7 @@ package org.apache.lucene.spatial3d.geom;
import org.junit.Test;
-import static java.lang.Math.toRadians;
+import static org.apache.lucene.util.SloppyMath.toRadians;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b11e48c7/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java b/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
index fdef990..4f68adb 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/geo/EarthDebugger.java
@@ -207,8 +207,8 @@ public class EarthDebugger {
newAngle:
while (angle < 360) {
- double x = Math.cos(Math.toRadians(angle));
- double y = Math.sin(Math.toRadians(angle));
+ double x = Math.cos(SloppyMath.toRadians(angle));
+ double y = Math.sin(SloppyMath.toRadians(angle));
double factor = 2.0;
double step = 1.0;
int last = 0;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b11e48c7/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java
index 62b824f..619b682 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/geo/GeoTestUtil.java
@@ -322,8 +322,8 @@ public class GeoTestUtil {
for(int i=0;i<gons;i++) {
double angle = 360.0-i*(360.0/gons);
//System.out.println(" angle " + angle);
- double x = Math.cos(Math.toRadians(angle));
- double y = Math.sin(Math.toRadians(angle));
+ double x = Math.cos(SloppyMath.toRadians(angle));
+ double y = Math.sin(SloppyMath.toRadians(angle));
double factor = 2.0;
double step = 1.0;
int last = 0;
@@ -476,8 +476,8 @@ public class GeoTestUtil {
}
double len = radius * (1.0 - radiusDelta + radiusDelta * random().nextDouble());
//System.out.println(" len=" + len);
- double lat = centerLat + len * Math.cos(Math.toRadians(angle));
- double lon = centerLon + len * Math.sin(Math.toRadians(angle));
+ double lat = centerLat + len * Math.cos(SloppyMath.toRadians(angle));
+ double lon = centerLon + len * Math.sin(SloppyMath.toRadians(angle));
if (lon <= GeoUtils.MIN_LON_INCL || lon >= GeoUtils.MAX_LON_INCL) {
// cannot cross dateline: try again!
continue newPoly;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b11e48c7/lucene/tools/forbiddenApis/lucene.txt
----------------------------------------------------------------------
diff --git a/lucene/tools/forbiddenApis/lucene.txt b/lucene/tools/forbiddenApis/lucene.txt
index 5b89af7..e02bd40 100644
--- a/lucene/tools/forbiddenApis/lucene.txt
+++ b/lucene/tools/forbiddenApis/lucene.txt
@@ -24,3 +24,6 @@ java.io.RandomAccessFile
java.nio.file.Path#toFile()
java.util.jar.JarFile
java.util.zip.ZipFile
+@defaultMessage Use home-grown methods instead
+java.lang.Math#toRadians(double)
+java.lang.Math#toDegrees(double)
[2/2] lucene-solr:master: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/lucene-solr
Posted by kw...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/lucene-solr
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ece9d85c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ece9d85c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ece9d85c
Branch: refs/heads/master
Commit: ece9d85cbea962fd7d327010f1ba184cefdfa8ed
Parents: b11e48c 7afa333
Author: Karl Wright <Da...@gmail.com>
Authored: Wed Jun 22 07:51:07 2016 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Wed Jun 22 07:51:07 2016 -0400
----------------------------------------------------------------------
lucene/CHANGES.txt | 2 +-
.../apache/lucene/search/ConjunctionDISI.java | 124 ++++++++++++++++---
.../org/apache/lucene/search/LRUQueryCache.java | 34 ++++-
.../org/apache/lucene/util/BitSetIterator.java | 10 ++
.../lucene/search/TestConjunctionDISI.java | 98 +++++++++++----
.../apache/lucene/search/TestScorerPerf.java | 1 +
6 files changed, 227 insertions(+), 42 deletions(-)
----------------------------------------------------------------------