|
23 | 23 | import java.util.ArrayList;
|
24 | 24 | import java.util.List;
|
25 | 25 |
|
26 |
| -import static org.junit.Assert.*; |
| 26 | +import static org.junit.Assert.assertEquals; |
| 27 | +import static org.junit.Assert.assertFalse; |
| 28 | +import static org.junit.Assert.assertSame; |
| 29 | +import static org.junit.Assert.assertTrue; |
27 | 30 |
|
28 | 31 | public class PolyUtilTest {
|
29 | 32 | private static final String TEST_LINE =
|
@@ -469,14 +472,60 @@ public void testIsClosedPolygon() {
|
469 | 472 | assertTrue(PolyUtil.isClosedPolygon(poly));
|
470 | 473 | }
|
471 | 474 |
|
| 475 | + /** |
| 476 | + * The following method checks whether {@link PolyUtil#distanceToLine(LatLng, LatLng, LatLng) distanceToLine()} } |
| 477 | + * is determining the distance between a point and a segment accurately. |
| 478 | + * |
| 479 | + * Currently there are tests for different orders of magnitude (i.e., 1X, 10X, 100X, 1000X), as well as a test |
| 480 | + * where the segment and the point lie in different hemispheres. |
| 481 | + * |
| 482 | + * If further tests need to be added here, make sure that the distance has been verified with <a href="https://www.qgis.org/">QGIS</a>. |
| 483 | + * |
| 484 | + * @see <a href="https://www.qgis.org/">QGIS</a> |
| 485 | + */ |
472 | 486 | @Test
|
473 | 487 | public void testDistanceToLine() {
|
474 | 488 | LatLng startLine = new LatLng(28.05359, -82.41632);
|
475 | 489 | LatLng endLine = new LatLng(28.05310, -82.41634);
|
476 | 490 | LatLng p = new LatLng(28.05342, -82.41594);
|
477 | 491 |
|
478 | 492 | double distance = PolyUtil.distanceToLine(p, startLine, endLine);
|
479 |
| - assertEquals(37.947946, distance, 1e-6); |
| 493 | + assertEquals(37.94596795917082, distance, 1e-6); |
| 494 | + |
| 495 | + startLine = new LatLng(49.321045, 12.097749); |
| 496 | + endLine = new LatLng(49.321016, 12.097795); |
| 497 | + p = new LatLng(49.3210674, 12.0978238); |
| 498 | + |
| 499 | + distance = PolyUtil.distanceToLine(p, startLine, endLine); |
| 500 | + assertEquals(5.559443879999753, distance, 1e-6); |
| 501 | + |
| 502 | + startLine = new LatLng(48.125961, 11.548998); |
| 503 | + endLine = new LatLng(48.125918, 11.549005); |
| 504 | + p = new LatLng(48.125941, 11.549028); |
| 505 | + |
| 506 | + distance = PolyUtil.distanceToLine(p, startLine, endLine); |
| 507 | + assertEquals(1.9733966358947437, distance, 1e-6); |
| 508 | + |
| 509 | + startLine = new LatLng(78.924669, 11.925521); |
| 510 | + endLine = new LatLng(78.924707, 11.929060); |
| 511 | + p = new LatLng(78.923164, 11.924029); |
| 512 | + |
| 513 | + distance = PolyUtil.distanceToLine(p, startLine, endLine); |
| 514 | + assertEquals(170.35662670453187, distance, 1e-6); |
| 515 | + |
| 516 | + startLine = new LatLng(69.664036, 18.957124); |
| 517 | + endLine = new LatLng(69.664029, 18.957109); |
| 518 | + p = new LatLng(69.672901, 18.967911); |
| 519 | + |
| 520 | + distance = PolyUtil.distanceToLine(p, startLine, endLine); |
| 521 | + assertEquals(1070.222749990837, distance, 1e-6); |
| 522 | + |
| 523 | + startLine = new LatLng(-0.018200, 109.343282); |
| 524 | + endLine = new LatLng(-0.017877, 109.343537); |
| 525 | + p = new LatLng(0.058299, 109.408054); |
| 526 | + |
| 527 | + distance = PolyUtil.distanceToLine(p, startLine, endLine); |
| 528 | + assertEquals(11100.157563150981, distance, 1e-6); |
480 | 529 | }
|
481 | 530 |
|
482 | 531 | @Test
|
|
0 commit comments