Changeset 18590 in josm for trunk/test
- Timestamp:
- 2022-11-08T21:50:55+01:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/GeometryTest.java
r18589 r18590 5 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 6 import static org.junit.jupiter.api.Assertions.assertNotEquals; 7 import static org.junit.jupiter.api.Assertions.assertNotNull; 7 8 import static org.junit.jupiter.api.Assertions.assertTrue; 8 9 … … 17 18 import java.util.stream.Stream; 18 19 19 import org.junit.Assert;20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 20 21 import org.junit.jupiter.api.Test; 21 22 import org.junit.jupiter.api.extension.RegisterExtension; … … 40 41 import org.openstreetmap.josm.testutils.JOSMTestRules; 41 42 42 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;43 44 43 /** 45 44 * Unit tests of {@link Geometry} class. … … 51 50 @RegisterExtension 52 51 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 53 public JOSMTestRules test = new JOSMTestRules().preferences().projection();52 static JOSMTestRules test = new JOSMTestRules().preferences().projection(); 54 53 55 54 /** … … 65 64 EastNorth intersectionPoint = Geometry.getLineLineIntersection(p1, p2, p3, p4); 66 65 66 assertNotNull(intersectionPoint); 67 67 EastNorth d1 = p3.subtract(intersectionPoint); 68 68 EastNorth d2 = p1.subtract(p2); … … 72 72 Double len2 = d2.length(); 73 73 74 Double angle1 = Geometry.getCornerAngle(p1, p2, intersectionPoint); 75 Double angle2 = Geometry.getCornerAngle(p3, p4, intersectionPoint); 76 Assert.assertTrue("intersection point not on line, angle: " + angle1, 77 Math.abs(angle1) < 1e-10); 78 Assert.assertTrue("intersection point not on line, angle: " + angle2, 79 Math.abs(angle1) < 1e-10); 80 81 Assert.assertTrue("cross product != 1 : " + Math.abs(crossProduct/len1/len2), 82 Math.abs(Math.abs(crossProduct/len1/len2) - 1) < 1e-10); 83 Assert.assertTrue("scalar product != 0 : " + scalarProduct/len1/len2, 84 Math.abs(scalarProduct/len1/len2) < 1e-10); 74 double angle1 = Geometry.getCornerAngle(p1, p2, intersectionPoint); 75 double angle2 = Geometry.getCornerAngle(p3, p4, intersectionPoint); 76 assertTrue(Math.abs(angle1) < 1e-10, "intersection point not on line, angle: " + angle1); 77 assertTrue(Math.abs(angle1) < 1e-10, "intersection point not on line, angle: " + angle2); 78 79 assertTrue(Math.abs(Math.abs(crossProduct/len1/len2) - 1) < 1e-10, "cross product != 1 : " + Math.abs(crossProduct/len1/len2)); 80 assertTrue(Math.abs(scalarProduct/len1/len2) < 1e-10, "scalar product != 0 : " + scalarProduct/len1/len2); 85 81 } 86 82 … … 96 92 Way closedWay = (Way) SubclassFilteredCollection.filter(ds.allPrimitives(), 97 93 SearchCompiler.compile("landuse=forest")).iterator().next(); 98 Assert.assertEquals(5760015.7353515625, Geometry.closedWayArea(closedWay), 1e-3);99 Assert.assertEquals(5760015.7353515625, Geometry.computeArea(closedWay), 1e-3);94 assertEquals(5760015.7353515625, Geometry.closedWayArea(closedWay), 1e-3); 95 assertEquals(5760015.7353515625, Geometry.computeArea(closedWay), 1e-3); 100 96 } 101 97 } … … 111 107 DataSet ds = OsmReader.parseDataSet(in, null); 112 108 final Relation r = ds.getRelations().iterator().next(); 113 Assert.assertEquals(4401735.20703125, Geometry.multipolygonArea(r), 1e-3);114 Assert.assertEquals(4401735.20703125, Geometry.computeArea(r), 1e-3);109 assertEquals(4401735.20703125, Geometry.multipolygonArea(r), 1e-3); 110 assertEquals(4401735.20703125, Geometry.computeArea(r), 1e-3); 115 111 } 116 112 } … … 128 124 SearchCompiler.compile("landuse=forest")).iterator().next(); 129 125 Geometry.AreaAndPerimeter areaAndPerimeter = Geometry.getAreaAndPerimeter(closedWay.getNodes()); 130 Assert.assertEquals(12495000., areaAndPerimeter.getArea(), 1e-3);131 Assert.assertEquals(15093.201209424187, areaAndPerimeter.getPerimeter(), 1e-3);126 assertEquals(12495000., areaAndPerimeter.getArea(), 1e-3); 127 assertEquals(15093.201209424187, areaAndPerimeter.getPerimeter(), 1e-3); 132 128 } 133 129 } … … 374 370 mp2.put("type", "multipolygon"); 375 371 assertFalse(Geometry.isPolygonInsideMultiPolygon(w1.getNodes(), mp2, null)); 376 assertFalse(Geometry.filterInsideMultipolygon( Arrays.asList(w1), mp2).contains(w1));372 assertFalse(Geometry.filterInsideMultipolygon(Collections.singletonList(w1), mp2).contains(w1)); 377 373 378 374 node4.setCoor(new LatLon(1.006, 0.99)); 379 375 // now w1 is inside 380 376 assertTrue(Geometry.isPolygonInsideMultiPolygon(w1.getNodes(), mp2, null)); 381 assertTrue(Geometry.filterInsideMultipolygon( Arrays.asList(w1), mp2).contains(w1));382 assertTrue(Geometry.filterInsideMultipolygon( Arrays.asList(mp1), mp2).contains(mp1));377 assertTrue(Geometry.filterInsideMultipolygon(Collections.singletonList(w1), mp2).contains(w1)); 378 assertTrue(Geometry.filterInsideMultipolygon(Collections.singletonList(mp1), mp2).contains(mp1)); 383 379 assertTrue(Geometry.filterInsideMultipolygon(Arrays.asList(w1, mp1), mp2).contains(w1)); 384 380 assertTrue(Geometry.filterInsideMultipolygon(Arrays.asList(w1, mp1), mp2).contains(mp1)); … … 494 490 495 491 Way closestSegment = Geometry.getClosestWaySegment(way1, new Node(new LatLon(0, 0.5))).toWay(); 496 Assert.assertTrue(closestSegment.containsNode(node1));497 Assert.assertTrue(closestSegment.containsNode(node2));492 assertTrue(closestSegment.containsNode(node1)); 493 assertTrue(closestSegment.containsNode(node2)); 498 494 } 499 495
Note:
See TracChangeset
for help on using the changeset viewer.