Index: contrib/spatial/src/test/org/apache/lucene/spatial/geometry/TestArcGeoDistanceCalculator.java
===================================================================
--- contrib/spatial/src/test/org/apache/lucene/spatial/geometry/TestArcGeoDistanceCalculator.java	Fri Dec 11 15:04:05 CET 2009
+++ contrib/spatial/src/test/org/apache/lucene/spatial/geometry/TestArcGeoDistanceCalculator.java	Fri Dec 11 15:04:05 CET 2009
@@ -0,0 +1,42 @@
+/**
+ * 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.
+ */
+
+package org.apache.lucene.spatial.geometry;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link org.apache.lucene.spatial.geometry.ArcGeoDistanceCalculator}
+ */
+public class TestArcGeoDistanceCalculator extends TestCase {
+
+  /**
+   * Pass condition: The distance calculated in miles matches the expected distance
+   */
+  public void testCalculate_miles() {
+    double distance = new ArcGeoDistanceCalculator().calculate(53.85, 4.51, 43.22, 9.68, DistanceUnits.MILES);
+    assertEquals(771.958067752198, distance, 0D);
+  }
+
+  /**
+   * Pass condition: The distance calculated in kilometers matches the expected distance
+   */
+  public void testCalculate_kilometers() {
+    double distance = new ArcGeoDistanceCalculator().calculate(53.85, 4.51, 43.22, 9.68, DistanceUnits.KILOMETERS);
+    assertEquals(1242.3460845885934, distance, 0D);
+  }
+}
Index: contrib/spatial/src/java/org/apache/lucene/spatial/geometry/GeoDistanceCalculator.java
===================================================================
--- contrib/spatial/src/java/org/apache/lucene/spatial/geometry/GeoDistanceCalculator.java	Fri Dec 11 14:52:03 CET 2009
+++ contrib/spatial/src/java/org/apache/lucene/spatial/geometry/GeoDistanceCalculator.java	Fri Dec 11 14:52:03 CET 2009
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+
+package org.apache.lucene.spatial.geometry;
+
+/**
+ * Abstraction of the idea of a calculator of distance between 2 points.  This is useful since while the world is curved,
+ * its not always necessary to calcuate the distance between 2 points as if they are on a curve.
+ *
+ * <p><font color="red"><b>NOTE:</b> This API is still in flux and might change in incompatible ways in the next release.</font>
+ */
+public interface GeoDistanceCalculator {
+
+  /**
+   * Calculates the distance between the point defined by the source latitude/longitude and the point defined by the
+   * target latitude/longitude
+   *
+   * @param sourceLongitude Longitude of the point the distance is being calculated from
+   * @param sourceLatitude Latitude of the point the distance is being calculated from
+   * @param targetLongitude Longitude of the point the distance is being calculated to
+   * @param targetLatitude Latitude of the point the distance is being calculated to
+   * @param unit Unit of distance the result should be returned in
+   * @return Distance between the 2 points in the unit of distance requested
+   */
+  double calculate(double sourceLatitude, double sourceLongitude, double targetLatitude, double targetLongitude, DistanceUnits unit);
+}
Index: contrib/spatial/src/java/org/apache/lucene/spatial/geometry/PlaneGeoDistanceCalculator.java
===================================================================
--- contrib/spatial/src/java/org/apache/lucene/spatial/geometry/PlaneGeoDistanceCalculator.java	Fri Dec 11 15:02:01 CET 2009
+++ contrib/spatial/src/java/org/apache/lucene/spatial/geometry/PlaneGeoDistanceCalculator.java	Fri Dec 11 15:02:01 CET 2009
@@ -0,0 +1,49 @@
+/**
+ * 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.
+ */
+
+package org.apache.lucene.spatial.geometry;
+
+import org.apache.lucene.spatial.util.SpatialConstants;
+
+/**
+ * Implementation of {@link GeoDistanceCalculator} that assumes that the 2 points are on a flat plane.
+ * <p/>
+ * Obviously since the world is curved, this calculation with have some error.  However in many cases, the bigger the
+ * distance, the less important the error.  The impact of doing such a simple calculation is that the performance of
+ * calculating the distance of millions of points is considerably reduced.
+ *
+ * <p><font color="red"><b>NOTE:</b> This API is still in flux and might change in incompatible ways in the next release.</font>
+ */
+public class PlaneGeoDistanceCalculator implements GeoDistanceCalculator {
+
+  private final static double DISTANCE_PER_DEGREE = SpatialConstants.EARTH_CIRCUMFERENCE_MILES / 360;
+
+  /**
+   * {@inheritDoc}
+   */
+  public double calculate(
+      double sourceLatitude,
+      double sourceLongitude,
+      double targetLatitude,
+      double targetLongitude,
+      DistanceUnits unit) {
+    double px = targetLongitude - sourceLongitude;
+    double py = targetLatitude - sourceLatitude;
+    double distanceMiles = Math.sqrt(px * px + py * py) * DISTANCE_PER_DEGREE;
+    return DistanceUnits.convert(distanceMiles, DistanceUnits.MILES, unit);
+  }
+}
Index: contrib/spatial/src/java/org/apache/lucene/spatial/geometry/ArcGeoDistanceCalculator.java
===================================================================
--- contrib/spatial/src/java/org/apache/lucene/spatial/geometry/ArcGeoDistanceCalculator.java	Fri Dec 11 15:00:28 CET 2009
+++ contrib/spatial/src/java/org/apache/lucene/spatial/geometry/ArcGeoDistanceCalculator.java	Fri Dec 11 15:00:28 CET 2009
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+
+package org.apache.lucene.spatial.geometry;
+
+/**
+ * Implementation of {@link GeoDistanceCalculator} that calculates distances as though the points are on a globe.
+ *
+ * <p><font color="red"><b>NOTE:</b> This API is still in flux and might change in incompatible ways in the next release.</font>
+ */
+public class ArcGeoDistanceCalculator implements GeoDistanceCalculator {
+
+  /**
+   * {@inheritDoc}
+   */
+  public double calculate(
+      double sourceLatitude,
+      double sourceLongitude,
+      double targetLatitude,
+      double targetLongitude,
+      DistanceUnits unit) {
+    LatLng sourcePoint = new LatLng(sourceLatitude, sourceLongitude);
+    LatLng targetPoint = new LatLng(targetLatitude, targetLongitude);
+    return DistanceUnits.convert(sourcePoint.arcDistance(targetPoint, DistanceUnits.MILES), DistanceUnits.MILES, unit);
+  }
+}
Index: contrib/spatial/src/test/org/apache/lucene/spatial/geometry/TestPlaneGeoDistanceCalculator.java
===================================================================
--- contrib/spatial/src/test/org/apache/lucene/spatial/geometry/TestPlaneGeoDistanceCalculator.java	Fri Dec 11 15:04:57 CET 2009
+++ contrib/spatial/src/test/org/apache/lucene/spatial/geometry/TestPlaneGeoDistanceCalculator.java	Fri Dec 11 15:04:57 CET 2009
@@ -0,0 +1,42 @@
+/**
+ * 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.
+ */
+
+package org.apache.lucene.spatial.geometry;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link org.apache.lucene.spatial.geometry.PlaneGeoDistanceCalculator}
+ */
+public class TestPlaneGeoDistanceCalculator extends TestCase {
+
+  /**
+   * Pass condition: The distance calculated in miles matches the expected distance
+   */
+  public void testCalculate_miles() {
+    double distance = new PlaneGeoDistanceCalculator().calculate(53.85, 4.51, 43.22, 9.68, DistanceUnits.MILES);
+    assertEquals(817.6548750234183, distance, 0D);
+  }
+
+  /**
+   * Pass condition: The distance calculated in kilometers matches the expected distance
+   */
+  public void testCalculate_kilometers() {
+    double distance = new PlaneGeoDistanceCalculator().calculate(53.85, 4.51, 43.22, 9.68, DistanceUnits.KILOMETERS);
+    assertEquals(1315.8879671896882, distance, 0D);
+  }
+}
