Skip to content

Commit

Permalink
correct licensing and incorporation of FastMath
Browse files Browse the repository at this point in the history
this resolves incorrectly licensed code in elastic#49009.

ESSloppyMath is removed in favor of preserving as much of the original
FastMath as possible. Since no additional methods are introduced in
ESSloppyMath, this abstraction is removed.
  • Loading branch information
talevy committed Nov 14, 2019
1 parent 56d5f60 commit 8bc6297
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*
* 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
* Copyright 2012 Jeff Hain
*
* Licensed 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
*
Expand All @@ -14,16 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.elasticsearch.common.util;

/*
* =============================================================================
* Notice of fdlibm package this program is partially derived from:
*
* sinh and atan ported from
* https://github.com/yannrichet/jmathplot/blob/f25426e0ab0e68647ad2b75f577c7be050ecac86/src/main/java/org/math/plot/utils/FastMath.java
* (Apache 2.0) Copyright 2012 Jeff Hain, which is partially derived from fdlibm package
*
* =============================================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunSoft, a Sun Microsystems, Inc. business.
Expand All @@ -33,13 +27,18 @@
* =============================================================================
*/


/**
* Similar to Lucene's SloppyMath, but for additional math functions.
/*
* This code sourced from:
* https://github.com/yannrichet/jmathplot/blob/f25426e0ab0e68647ad2b75f577c7be050ecac86/src/main/java/org/math/plot/utils/FastMath.java
*/
public class ESSloppyMath {

private ESSloppyMath() {}
package org.elasticsearch.common.util;

public final class FastMath {

private FastMath() {

}

//--------------------------------------------------------------------------
// RE-USABLE CONSTANTS
Expand Down Expand Up @@ -177,4 +176,5 @@ public static double atan(double value) {
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
/*
* 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
* 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
* 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.
* 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;

import org.elasticsearch.test.ESTestCase;

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

public class ESSloppyMathTests extends ESTestCase {
public class FastMathTests 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.ESSloppyMath;
import org.elasticsearch.common.util.FastMath;
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(ESSloppyMath.atan(ESSloppyMath.sinh(n)));
final double lat = Math.toDegrees(FastMath.atan(FastMath.sinh(n)));
final double lon = ((xTile + 0.5) / tiles * 360.0) - 180;
return new GeoPoint(lat, lon);
}
Expand Down

0 comments on commit 8bc6297

Please sign in to comment.