You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/05/04 15:19:03 UTC
svn commit: r1677595 [9/9] - in
/lucene/dev/branches/lucene6196/lucene/spatial/src:
java/org/apache/lucene/spatial/spatial4j/geo3d/
test/org/apache/lucene/spatial/spatial4j/
test/org/apache/lucene/spatial/spatial4j/geo3d/
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPathTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPathTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPathTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPathTest.java Mon May 4 13:19:02 2015
@@ -25,160 +25,160 @@ import static org.junit.Assert.assertTru
public class GeoPathTest {
- @Test
- public void testPathDistance() {
- // Start with a really simple case
- GeoPath p;
- GeoPoint gp;
- p = new GeoPath(0.1);
- p.addPoint(0.0,0.0);
- p.addPoint(0.0,0.1);
- p.addPoint(0.0,0.2);
- p.done();
- gp = new GeoPoint(Math.PI * 0.5,0.15);
- assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.0);
- gp = new GeoPoint(0.05,0.15);
- assertEquals(0.15 + 0.05, p.computeArcDistance(gp), 0.000001);
- gp = new GeoPoint(0.0,0.12);
- assertEquals(0.12 + 0.0, p.computeArcDistance(gp), 0.000001);
- gp = new GeoPoint(-0.15,0.05);
- assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.000001);
- gp = new GeoPoint(0.0,0.25);
- assertEquals(0.20 + 0.05, p.computeArcDistance(gp), 0.000001);
- gp = new GeoPoint(0.0,-0.05);
- assertEquals(0.0 + 0.05, p.computeArcDistance(gp), 0.000001);
-
- // Compute path distances now
- p = new GeoPath(0.1);
- p.addPoint(0.0,0.0);
- p.addPoint(0.0,0.1);
- p.addPoint(0.0,0.2);
- p.done();
- gp = new GeoPoint(0.05,0.15);
- assertEquals(0.15 + 0.05, p.computeArcDistance(gp), 0.000001);
- gp = new GeoPoint(0.0,0.12);
- assertEquals(0.12, p.computeArcDistance(gp), 0.000001);
-
- // Now try a vertical path, and make sure distances are as expected
- p = new GeoPath(0.1);
- p.addPoint(-Math.PI * 0.25,-0.5);
- p.addPoint(Math.PI * 0.25,-0.5);
- p.done();
- gp = new GeoPoint(0.0,0.0);
- assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.0);
- gp = new GeoPoint(-0.1,-1.0);
- assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.0);
- gp = new GeoPoint(Math.PI*0.25+0.05,-0.5);
- assertEquals(Math.PI * 0.5 + 0.05, p.computeArcDistance(gp), 0.000001);
- gp = new GeoPoint(-Math.PI*0.25-0.05,-0.5);
- assertEquals(0.0 + 0.05, p.computeArcDistance(gp), 0.000001);
- }
-
- @Test
- public void testPathPointWithin() {
- // Tests whether we can properly detect whether a point is within a path or not
- GeoPath p;
- GeoPoint gp;
- p = new GeoPath(0.1);
- // Build a diagonal path crossing the equator
- p.addPoint(-0.2,-0.2);
- p.addPoint(0.2,0.2);
- p.done();
- // Test points on the path
- gp = new GeoPoint(-0.2,-0.2);
- assertTrue(p.isWithin(gp));
- gp = new GeoPoint(0.0,0.0);
- assertTrue(p.isWithin(gp));
- gp = new GeoPoint(0.1,0.1);
- assertTrue(p.isWithin(gp));
- // Test points off the path
- gp = new GeoPoint(-0.2,0.2);
- assertFalse(p.isWithin(gp));
- gp = new GeoPoint(-Math.PI*0.5,0.0);
- assertFalse(p.isWithin(gp));
- gp = new GeoPoint(0.2,-0.2);
- assertFalse(p.isWithin(gp));
- gp = new GeoPoint(0.0,Math.PI);
- assertFalse(p.isWithin(gp));
- // Repeat the test, but across the terminator
- p = new GeoPath(0.1);
- // Build a diagonal path crossing the equator
- p.addPoint(-0.2,Math.PI-0.2);
- p.addPoint(0.2,-Math.PI+0.2);
- // Test points on the path
- gp = new GeoPoint(-0.2,Math.PI-0.2);
- assertTrue(p.isWithin(gp));
- gp = new GeoPoint(0.0,Math.PI);
- assertTrue(p.isWithin(gp));
- gp = new GeoPoint(0.1,-Math.PI+0.1);
- assertTrue(p.isWithin(gp));
- // Test points off the path
- gp = new GeoPoint(-0.2,-Math.PI+0.2);
- assertFalse(p.isWithin(gp));
- gp = new GeoPoint(-Math.PI*0.5,0.0);
- assertFalse(p.isWithin(gp));
- gp = new GeoPoint(0.2,Math.PI-0.2);
- assertFalse(p.isWithin(gp));
- gp = new GeoPoint(0.0,0.0);
- assertFalse(p.isWithin(gp));
-
- }
-
- @Test
- public void testGetRelationship() {
- GeoArea rect;
- GeoPath p;
-
- // Start by testing the basic kinds of relationship, increasing in order of difficulty.
-
- p = new GeoPath(0.1);
- p.addPoint(-0.3,-0.3);
- p.addPoint(0.3,0.3);
- p.done();
- // Easiest: The path is wholly contains the georect
- rect = new GeoRectangle(0.05,-0.05,-0.05,0.05);
- assertEquals(GeoArea.CONTAINS, rect.getRelationship(p));
- // Next easiest: Some endpoints of the rectangle are inside, and some are outside.
- rect = new GeoRectangle(0.05,-0.05,-0.05,0.5);
- assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
- // Now, all points are outside, but the figures intersect
- rect = new GeoRectangle(0.05,-0.05,-0.5,0.5);
- assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
- // Finally, all points are outside, and the figures *do not* intersect
- rect = new GeoRectangle(0.5,-0.5,-0.5,0.5);
- assertEquals(GeoArea.WITHIN, rect.getRelationship(p));
- // Check that segment edge overlap detection works
- rect = new GeoRectangle(0.1,0.0,-0.1,0.0);
- assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
- rect = new GeoRectangle(0.2,0.1,-0.2,-0.1);
- assertEquals(GeoArea.DISJOINT, rect.getRelationship(p));
- // Check if overlap at endpoints behaves as expected next
- rect = new GeoRectangle(0.5,-0.5,-0.5,-0.35);
- assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
- rect = new GeoRectangle(0.5,-0.5,-0.5,-0.45);
- assertEquals(GeoArea.DISJOINT, rect.getRelationship(p));
-
- }
-
- @Test
- public void testPathBounds() {
- GeoPath c;
- Bounds b;
-
- c = new GeoPath(0.1);
- c.addPoint(-0.3,-0.3);
- c.addPoint(0.3,0.3);
- c.done();
-
- b = c.getBounds(null);
- assertFalse(b.checkNoLongitudeBound());
- assertFalse(b.checkNoTopLatitudeBound());
- assertFalse(b.checkNoBottomLatitudeBound());
- assertEquals(-0.4046919,b.getLeftLongitude(),0.000001);
- assertEquals(0.4046919,b.getRightLongitude(),0.000001);
- assertEquals(-0.3999999,b.getMinLatitude(),0.000001);
- assertEquals(0.3999999,b.getMaxLatitude(),0.000001);
+ @Test
+ public void testPathDistance() {
+ // Start with a really simple case
+ GeoPath p;
+ GeoPoint gp;
+ p = new GeoPath(0.1);
+ p.addPoint(0.0, 0.0);
+ p.addPoint(0.0, 0.1);
+ p.addPoint(0.0, 0.2);
+ p.done();
+ gp = new GeoPoint(Math.PI * 0.5, 0.15);
+ assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.0);
+ gp = new GeoPoint(0.05, 0.15);
+ assertEquals(0.15 + 0.05, p.computeArcDistance(gp), 0.000001);
+ gp = new GeoPoint(0.0, 0.12);
+ assertEquals(0.12 + 0.0, p.computeArcDistance(gp), 0.000001);
+ gp = new GeoPoint(-0.15, 0.05);
+ assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.000001);
+ gp = new GeoPoint(0.0, 0.25);
+ assertEquals(0.20 + 0.05, p.computeArcDistance(gp), 0.000001);
+ gp = new GeoPoint(0.0, -0.05);
+ assertEquals(0.0 + 0.05, p.computeArcDistance(gp), 0.000001);
+
+ // Compute path distances now
+ p = new GeoPath(0.1);
+ p.addPoint(0.0, 0.0);
+ p.addPoint(0.0, 0.1);
+ p.addPoint(0.0, 0.2);
+ p.done();
+ gp = new GeoPoint(0.05, 0.15);
+ assertEquals(0.15 + 0.05, p.computeArcDistance(gp), 0.000001);
+ gp = new GeoPoint(0.0, 0.12);
+ assertEquals(0.12, p.computeArcDistance(gp), 0.000001);
+
+ // Now try a vertical path, and make sure distances are as expected
+ p = new GeoPath(0.1);
+ p.addPoint(-Math.PI * 0.25, -0.5);
+ p.addPoint(Math.PI * 0.25, -0.5);
+ p.done();
+ gp = new GeoPoint(0.0, 0.0);
+ assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.0);
+ gp = new GeoPoint(-0.1, -1.0);
+ assertEquals(Double.MAX_VALUE, p.computeArcDistance(gp), 0.0);
+ gp = new GeoPoint(Math.PI * 0.25 + 0.05, -0.5);
+ assertEquals(Math.PI * 0.5 + 0.05, p.computeArcDistance(gp), 0.000001);
+ gp = new GeoPoint(-Math.PI * 0.25 - 0.05, -0.5);
+ assertEquals(0.0 + 0.05, p.computeArcDistance(gp), 0.000001);
+ }
+
+ @Test
+ public void testPathPointWithin() {
+ // Tests whether we can properly detect whether a point is within a path or not
+ GeoPath p;
+ GeoPoint gp;
+ p = new GeoPath(0.1);
+ // Build a diagonal path crossing the equator
+ p.addPoint(-0.2, -0.2);
+ p.addPoint(0.2, 0.2);
+ p.done();
+ // Test points on the path
+ gp = new GeoPoint(-0.2, -0.2);
+ assertTrue(p.isWithin(gp));
+ gp = new GeoPoint(0.0, 0.0);
+ assertTrue(p.isWithin(gp));
+ gp = new GeoPoint(0.1, 0.1);
+ assertTrue(p.isWithin(gp));
+ // Test points off the path
+ gp = new GeoPoint(-0.2, 0.2);
+ assertFalse(p.isWithin(gp));
+ gp = new GeoPoint(-Math.PI * 0.5, 0.0);
+ assertFalse(p.isWithin(gp));
+ gp = new GeoPoint(0.2, -0.2);
+ assertFalse(p.isWithin(gp));
+ gp = new GeoPoint(0.0, Math.PI);
+ assertFalse(p.isWithin(gp));
+ // Repeat the test, but across the terminator
+ p = new GeoPath(0.1);
+ // Build a diagonal path crossing the equator
+ p.addPoint(-0.2, Math.PI - 0.2);
+ p.addPoint(0.2, -Math.PI + 0.2);
+ // Test points on the path
+ gp = new GeoPoint(-0.2, Math.PI - 0.2);
+ assertTrue(p.isWithin(gp));
+ gp = new GeoPoint(0.0, Math.PI);
+ assertTrue(p.isWithin(gp));
+ gp = new GeoPoint(0.1, -Math.PI + 0.1);
+ assertTrue(p.isWithin(gp));
+ // Test points off the path
+ gp = new GeoPoint(-0.2, -Math.PI + 0.2);
+ assertFalse(p.isWithin(gp));
+ gp = new GeoPoint(-Math.PI * 0.5, 0.0);
+ assertFalse(p.isWithin(gp));
+ gp = new GeoPoint(0.2, Math.PI - 0.2);
+ assertFalse(p.isWithin(gp));
+ gp = new GeoPoint(0.0, 0.0);
+ assertFalse(p.isWithin(gp));
+
+ }
+
+ @Test
+ public void testGetRelationship() {
+ GeoArea rect;
+ GeoPath p;
+
+ // Start by testing the basic kinds of relationship, increasing in order of difficulty.
+
+ p = new GeoPath(0.1);
+ p.addPoint(-0.3, -0.3);
+ p.addPoint(0.3, 0.3);
+ p.done();
+ // Easiest: The path is wholly contains the georect
+ rect = new GeoRectangle(0.05, -0.05, -0.05, 0.05);
+ assertEquals(GeoArea.CONTAINS, rect.getRelationship(p));
+ // Next easiest: Some endpoints of the rectangle are inside, and some are outside.
+ rect = new GeoRectangle(0.05, -0.05, -0.05, 0.5);
+ assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
+ // Now, all points are outside, but the figures intersect
+ rect = new GeoRectangle(0.05, -0.05, -0.5, 0.5);
+ assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
+ // Finally, all points are outside, and the figures *do not* intersect
+ rect = new GeoRectangle(0.5, -0.5, -0.5, 0.5);
+ assertEquals(GeoArea.WITHIN, rect.getRelationship(p));
+ // Check that segment edge overlap detection works
+ rect = new GeoRectangle(0.1, 0.0, -0.1, 0.0);
+ assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
+ rect = new GeoRectangle(0.2, 0.1, -0.2, -0.1);
+ assertEquals(GeoArea.DISJOINT, rect.getRelationship(p));
+ // Check if overlap at endpoints behaves as expected next
+ rect = new GeoRectangle(0.5, -0.5, -0.5, -0.35);
+ assertEquals(GeoArea.OVERLAPS, rect.getRelationship(p));
+ rect = new GeoRectangle(0.5, -0.5, -0.5, -0.45);
+ assertEquals(GeoArea.DISJOINT, rect.getRelationship(p));
+
+ }
+
+ @Test
+ public void testPathBounds() {
+ GeoPath c;
+ Bounds b;
+
+ c = new GeoPath(0.1);
+ c.addPoint(-0.3, -0.3);
+ c.addPoint(0.3, 0.3);
+ c.done();
+
+ b = c.getBounds(null);
+ assertFalse(b.checkNoLongitudeBound());
+ assertFalse(b.checkNoTopLatitudeBound());
+ assertFalse(b.checkNoBottomLatitudeBound());
+ assertEquals(-0.4046919, b.getLeftLongitude(), 0.000001);
+ assertEquals(0.4046919, b.getRightLongitude(), 0.000001);
+ assertEquals(-0.3999999, b.getMinLatitude(), 0.000001);
+ assertEquals(0.3999999, b.getMaxLatitude(), 0.000001);
- }
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonTest.java Mon May 4 13:19:02 2015
@@ -17,65 +17,68 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-import java.util.*;
-
-import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class GeoPolygonTest {
- @Test
- public void testPolygonPointWithin() {
- GeoMembershipShape c;
- GeoPoint gp;
- List<GeoPoint> points;
-
- points = new ArrayList<GeoPoint>();
- points.add(new GeoPoint(-0.1,-0.5));
- points.add(new GeoPoint(0.0,-0.6));
- points.add(new GeoPoint(0.1,-0.5));
- points.add(new GeoPoint(0.0,-0.4));
-
- c = GeoPolygonFactory.makeGeoPolygon(points,0);
- // Sample some points within
- gp = new GeoPoint(0.0,-0.5);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(0.0,-0.55);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(0.0,-0.45);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(-0.05,-0.5);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(0.05,-0.5);
- assertTrue(c.isWithin(gp));
- // Sample some nearby points outside
- gp = new GeoPoint(0.0,-0.65);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(0.0,-0.35);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(-0.15,-0.5);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(0.15,-0.5);
- assertFalse(c.isWithin(gp));
- // Random points outside
- gp = new GeoPoint(0.0,0.0);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(Math.PI * 0.5,0.0);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(0.0,Math.PI);
- assertFalse(c.isWithin(gp));
-
- points = new ArrayList<GeoPoint>();
- points.add(new GeoPoint(-0.1,-0.5));
- points.add(new GeoPoint(-0.01,-0.6));
- points.add(new GeoPoint(-0.1,-0.7));
- points.add(new GeoPoint(0.0,-0.8));
- points.add(new GeoPoint(0.1,-0.7));
- points.add(new GeoPoint(0.01,-0.6));
- points.add(new GeoPoint(0.1,-0.5));
- points.add(new GeoPoint(0.0,-0.4));
+ @Test
+ public void testPolygonPointWithin() {
+ GeoMembershipShape c;
+ GeoPoint gp;
+ List<GeoPoint> points;
+
+ points = new ArrayList<GeoPoint>();
+ points.add(new GeoPoint(-0.1, -0.5));
+ points.add(new GeoPoint(0.0, -0.6));
+ points.add(new GeoPoint(0.1, -0.5));
+ points.add(new GeoPoint(0.0, -0.4));
+
+ c = GeoPolygonFactory.makeGeoPolygon(points, 0);
+ // Sample some points within
+ gp = new GeoPoint(0.0, -0.5);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(0.0, -0.55);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(0.0, -0.45);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(-0.05, -0.5);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(0.05, -0.5);
+ assertTrue(c.isWithin(gp));
+ // Sample some nearby points outside
+ gp = new GeoPoint(0.0, -0.65);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(0.0, -0.35);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(-0.15, -0.5);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(0.15, -0.5);
+ assertFalse(c.isWithin(gp));
+ // Random points outside
+ gp = new GeoPoint(0.0, 0.0);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(Math.PI * 0.5, 0.0);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(0.0, Math.PI);
+ assertFalse(c.isWithin(gp));
+
+ points = new ArrayList<GeoPoint>();
+ points.add(new GeoPoint(-0.1, -0.5));
+ points.add(new GeoPoint(-0.01, -0.6));
+ points.add(new GeoPoint(-0.1, -0.7));
+ points.add(new GeoPoint(0.0, -0.8));
+ points.add(new GeoPoint(0.1, -0.7));
+ points.add(new GeoPoint(0.01, -0.6));
+ points.add(new GeoPoint(0.1, -0.5));
+ points.add(new GeoPoint(0.0, -0.4));
/*
System.out.println("Points: ");
@@ -83,60 +86,60 @@ public class GeoPolygonTest {
System.out.println(" "+p);
}
*/
-
- c = GeoPolygonFactory.makeGeoPolygon(points,0);
- // Sample some points within
- gp = new GeoPoint(0.0,-0.5);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(0.0,-0.55);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(0.0,-0.45);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(-0.05,-0.5);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(0.05,-0.5);
- assertTrue(c.isWithin(gp));
- gp = new GeoPoint(0.0,-0.7);
- assertTrue(c.isWithin(gp));
- // Sample some nearby points outside
- gp = new GeoPoint(0.0,-0.35);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(-0.15,-0.5);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(0.15,-0.5);
- assertFalse(c.isWithin(gp));
- // Random points outside
- gp = new GeoPoint(0.0,0.0);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(Math.PI * 0.5,0.0);
- assertFalse(c.isWithin(gp));
- gp = new GeoPoint(0.0,Math.PI);
- assertFalse(c.isWithin(gp));
-
- }
-
- @Test
- public void testPolygonBounds() {
- GeoMembershipShape c;
- Bounds b;
- List<GeoPoint> points;
-
- points = new ArrayList<GeoPoint>();
- points.add(new GeoPoint(-0.1,-0.5));
- points.add(new GeoPoint(0.0,-0.6));
- points.add(new GeoPoint(0.1,-0.5));
- points.add(new GeoPoint(0.0,-0.4));
-
- c = GeoPolygonFactory.makeGeoPolygon(points,0);
- b = c.getBounds(null);
- assertFalse(b.checkNoLongitudeBound());
- assertFalse(b.checkNoTopLatitudeBound());
- assertFalse(b.checkNoBottomLatitudeBound());
- assertEquals(-0.6,b.getLeftLongitude(),0.000001);
- assertEquals(-0.4,b.getRightLongitude(),0.000001);
- assertEquals(-0.1,b.getMinLatitude(),0.000001);
- assertEquals(0.1,b.getMaxLatitude(),0.000001);
- }
+ c = GeoPolygonFactory.makeGeoPolygon(points, 0);
+ // Sample some points within
+ gp = new GeoPoint(0.0, -0.5);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(0.0, -0.55);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(0.0, -0.45);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(-0.05, -0.5);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(0.05, -0.5);
+ assertTrue(c.isWithin(gp));
+ gp = new GeoPoint(0.0, -0.7);
+ assertTrue(c.isWithin(gp));
+ // Sample some nearby points outside
+ gp = new GeoPoint(0.0, -0.35);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(-0.15, -0.5);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(0.15, -0.5);
+ assertFalse(c.isWithin(gp));
+ // Random points outside
+ gp = new GeoPoint(0.0, 0.0);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(Math.PI * 0.5, 0.0);
+ assertFalse(c.isWithin(gp));
+ gp = new GeoPoint(0.0, Math.PI);
+ assertFalse(c.isWithin(gp));
+
+ }
+
+ @Test
+ public void testPolygonBounds() {
+ GeoMembershipShape c;
+ Bounds b;
+ List<GeoPoint> points;
+
+ points = new ArrayList<GeoPoint>();
+ points.add(new GeoPoint(-0.1, -0.5));
+ points.add(new GeoPoint(0.0, -0.6));
+ points.add(new GeoPoint(0.1, -0.5));
+ points.add(new GeoPoint(0.0, -0.4));
+
+ c = GeoPolygonFactory.makeGeoPolygon(points, 0);
+
+ b = c.getBounds(null);
+ assertFalse(b.checkNoLongitudeBound());
+ assertFalse(b.checkNoTopLatitudeBound());
+ assertFalse(b.checkNoBottomLatitudeBound());
+ assertEquals(-0.6, b.getLeftLongitude(), 0.000001);
+ assertEquals(-0.4, b.getRightLongitude(), 0.000001);
+ assertEquals(-0.1, b.getMinLatitude(), 0.000001);
+ assertEquals(0.1, b.getMaxLatitude(), 0.000001);
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/PlaneTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/PlaneTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/PlaneTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/PlaneTest.java Mon May 4 13:19:02 2015
@@ -22,43 +22,44 @@ import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-/** Test basic plane functionality.
-*/
+/**
+ * Test basic plane functionality.
+ */
public class PlaneTest {
- @Test
- public void testIdenticalPlanes() {
- final GeoPoint p = new GeoPoint(0.123,-0.456);
- final Plane plane1 = new Plane(p,0.0);
- final Plane plane2 = new Plane(p,0.0);
- assertTrue(plane1.isNumericallyIdentical(plane2));
- final Plane plane3 = new Plane(p,0.1);
- assertFalse(plane1.isNumericallyIdentical(plane3));
- final Vector v1 = new Vector(0.1,-0.732,0.9);
- final double constant = 0.432;
- final Vector v2 = new Vector(v1.x*constant,v1.y*constant,v1.z*constant);
- final Plane p1 = new Plane(v1,0.2);
- final Plane p2 = new Plane(v2,0.2*constant);
- assertTrue(p1.isNumericallyIdentical(p2));
- }
+ @Test
+ public void testIdenticalPlanes() {
+ final GeoPoint p = new GeoPoint(0.123, -0.456);
+ final Plane plane1 = new Plane(p, 0.0);
+ final Plane plane2 = new Plane(p, 0.0);
+ assertTrue(plane1.isNumericallyIdentical(plane2));
+ final Plane plane3 = new Plane(p, 0.1);
+ assertFalse(plane1.isNumericallyIdentical(plane3));
+ final Vector v1 = new Vector(0.1, -0.732, 0.9);
+ final double constant = 0.432;
+ final Vector v2 = new Vector(v1.x * constant, v1.y * constant, v1.z * constant);
+ final Plane p1 = new Plane(v1, 0.2);
+ final Plane p2 = new Plane(v2, 0.2 * constant);
+ assertTrue(p1.isNumericallyIdentical(p2));
+ }
+
+ @Test
+ public void testInterpolation() {
+ // [X=0.35168818443386646, Y=-0.19637966197066342, Z=0.9152870857244183],
+ // [X=0.5003343189532654, Y=0.522128543226148, Z=0.6906861469771293],
+
+ final GeoPoint start = new GeoPoint(0.35168818443386646, -0.19637966197066342, 0.9152870857244183);
+ final GeoPoint end = new GeoPoint(0.5003343189532654, 0.522128543226148, 0.6906861469771293);
+
+ // [A=-0.6135342247741855, B=0.21504338363863665, C=0.28188192383666794, D=0.0, side=-1.0] internal? false;
+ final Plane p = new Plane(-0.6135342247741855, 0.21504338363863665, 0.28188192383666794, 0.0);
+
+ final GeoPoint[] points = p.interpolate(start, end, new double[]{0.25, 0.50, 0.75});
- @Test
- public void testInterpolation() {
- // [X=0.35168818443386646, Y=-0.19637966197066342, Z=0.9152870857244183],
- // [X=0.5003343189532654, Y=0.522128543226148, Z=0.6906861469771293],
-
- final GeoPoint start = new GeoPoint(0.35168818443386646,-0.19637966197066342,0.9152870857244183);
- final GeoPoint end = new GeoPoint(0.5003343189532654,0.522128543226148,0.6906861469771293);
-
- // [A=-0.6135342247741855, B=0.21504338363863665, C=0.28188192383666794, D=0.0, side=-1.0] internal? false;
- final Plane p = new Plane(-0.6135342247741855,0.21504338363863665,0.28188192383666794,0.0);
-
- final GeoPoint[] points = p.interpolate(start,end,new double[]{0.25,0.50,0.75});
-
- for (GeoPoint point : points) {
- assertTrue(p.evaluateIsZero(point));
- }
+ for (GeoPoint point : points) {
+ assertTrue(p.evaluateIsZero(point));
}
+ }
}