Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct licensing and incorporation of FastMath #49122

Merged
merged 4 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.elasticsearch.common.util;

/**
* Similar to Lucene's SloppyMath, but for additional math functions.
*/
public class ESSloppyMath {

private ESSloppyMath() {}

public static double sinh(double value) {
return FastMath.sinh(value);
}

public static double atan(double value) {
return FastMath.atan(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@

package org.elasticsearch.common.util;

/**
* Additions or modifications to this class should only come from the original org.math.plot.utils.FastMath source
*/
public final class FastMath {
talevy marked this conversation as resolved.
Show resolved Hide resolved

private FastMath() {

}
private FastMath() { }

//--------------------------------------------------------------------------
// RE-USABLE CONSTANTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import org.elasticsearch.test.ESTestCase;

import static org.elasticsearch.common.util.FastMath.atan;
import static org.elasticsearch.common.util.FastMath.sinh;
import static org.elasticsearch.common.util.ESSloppyMath.atan;
import static org.elasticsearch.common.util.ESSloppyMath.sinh;

public class FastMathTests extends ESTestCase {
public class ESSloppyMathTests extends ESTestCase {

// accuracy for atan(x)
static double ATAN_DELTA = 1E-15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.util.FastMath;
import org.elasticsearch.common.util.ESSloppyMath;
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
Expand Down Expand Up @@ -211,7 +211,7 @@ private static int validateZXY(int zoom, int xTile, int yTile) {
private static GeoPoint zxyToGeoPoint(int zoom, int xTile, int yTile) {
final int tiles = validateZXY(zoom, xTile, yTile);
final double n = Math.PI - (2.0 * Math.PI * (yTile + 0.5)) / tiles;
final double lat = Math.toDegrees(FastMath.atan(FastMath.sinh(n)));
final double lat = Math.toDegrees(ESSloppyMath.atan(ESSloppyMath.sinh(n)));
final double lon = ((xTile + 0.5) / tiles * 360.0) - 180;
return new GeoPoint(lat, lon);
}
Expand Down