lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r881037 - in /lucene/solr/trunk/src/java/org/apache/solr/search/function/distance: DistanceUtils.java HaversineFunction.java
Date Mon, 16 Nov 2009 23:14:00 GMT
Author: gsingers
Date: Mon Nov 16 23:14:00 2009
New Revision: 881037

URL: http://svn.apache.org/viewvc?rev=881037&view=rev
Log:
SOLR-1302: slight refactoring for common code.

Added:
    lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
  (with props)
Modified:
    lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java

Added: lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java?rev=881037&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
(added)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
Mon Nov 16 23:14:00 2009
@@ -0,0 +1,48 @@
+package org.apache.solr.search.function.distance;
+/**
+ * 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
+ *
+ *     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.
+ */
+
+
+/**
+ * Useful distance utiltities
+ *
+ **/
+public class DistanceUtils {
+  /**
+   * @see org.apache.solr.search.function.distance.HaversineFunction
+   * 
+   * @param x1
+   * @param y1
+   * @param x2
+   * @param y2
+   * @param radius
+   * @return
+   */
+  public static double haversine(double x1, double y1, double x2, double y2, double radius){
+    double result = 0;
+    if ((x1 != x2) || (y1 != y2)) {
+      double diffX = x1 - x2;
+      double diffY = y1 - y2;
+      double hsinX = Math.sin(diffX / 2);
+      double hsinY = Math.sin(diffY / 2);
+      double h = hsinX * hsinX +
+              (Math.cos(x1) * Math.cos(x2) * hsinY * hsinY);
+      result = (radius * 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)));
+    }
+    return result;
+  }
+}

Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/DistanceUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java?rev=881037&r1=881036&r2=881037&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
Mon Nov 16 23:14:00 2009
@@ -73,15 +73,7 @@
     double y2 = y2DV.doubleVal(doc);
 
     //make sure they aren't all the same, as then we can just return 0
-    if ((x1 != x2) || (y1 != y2)) {
-      double diffX = x1 - x2;
-      double diffY = y1 - y2;
-      double hsinX = Math.sin(diffX / 2);
-      double hsinY = Math.sin(diffY / 2);
-      double h = hsinX * hsinX +
-              (Math.cos(x1) * Math.cos(x2) * hsinY * hsinY);
-      result = (radius * 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)));
-    }
+    result = DistanceUtils.haversine(x1, y1, x2, y2, radius);
 
     return result;
   }



Mime
View raw message