Ignore:
Timestamp:
2022-09-08T17:19:20+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #20716: Search for missing power line support features (patch by gaben, modified)

Way:

  • Avoid Arrays.stream in hasIncompleteNodes. This decreases CPU cost by 90%+ and makes it free from a memory allocation standpoint.
  • Add method to get segment lengths (meters)

CrossingWays:

  • Avoid Node#getEastNorth calls
  • Add a getSegments call that takes ILatLon

PowerLines:

  • Check for inconsistent support node reference numbering
  • Check for ways with unusually long segments without node supports
  • Check for ways where line types might be misused

ValUtil:

  • Avoid unnecessary calls to Node#getEastNorth
  • Add getSegmentCells for ILatLon

InspectPrimitiveDataText:

  • Add average segment length statistic

Geometry:

  • Add getSegmentSegmentIntersection for ILatLon to avoid new EastNorth objects

Utils:

  • Add getStandardDeviation methods
Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/WayTest.java

    r17275 r18553  
    88
    99import java.util.Arrays;
     10import java.util.Collections;
    1011import java.util.HashSet;
    1112
     
    4950        Way way = new Way(1);
    5051        assertFalse(way.getBBox().isValid());
    51         way.setNodes(Arrays.asList(n1));
     52        way.setNodes(Collections.singletonList(n1));
    5253        assertFalse(way.getBBox().isValid());
    53         way.setNodes(Arrays.asList(n2));
     54        way.setNodes(Collections.singletonList(n2));
    5455        assertTrue(way.getBBox().isValid());
    5556        way.setNodes(Arrays.asList(n1, n2));
     
    116117        assertEquals(Arrays.asList(n1, n2, n1), way.getNodes());
    117118        way.setNodes(Arrays.asList(n1, n2, n3, n4, n1));
    118         way.removeNodes(new HashSet<>(Arrays.asList(n1)));
     119        way.removeNodes(new HashSet<>(Collections.singletonList(n1)));
    119120        assertEquals(Arrays.asList(n2, n3, n4, n2), way.getNodes());
    120121    }
     
    135136        assertThrows(IllegalArgumentException.class, () -> new Way().load(new NodeData()));
    136137    }
     138
     139    @Test
     140    void getLongestSegmentLength() {
     141        DataSet ds = new DataSet();
     142        Node n1 = new Node(1);
     143        Node n2 = new Node(2);
     144        Node n3 = new Node(3);
     145        Node n4 = new Node(4);
     146        n1.setCoor(new LatLon(0.01, 0.01));
     147        n2.setCoor(new LatLon(0.02, 0.02));
     148        n3.setCoor(new LatLon(0.03, 0.03));
     149        n4.setCoor(new LatLon(0.05, 0.05));
     150        ds.addPrimitive(n1);
     151        ds.addPrimitive(n2);
     152        ds.addPrimitive(n3);
     153        ds.addPrimitive(n4);
     154        Way way = new Way(1);
     155        ds.addPrimitive(way);
     156
     157        assertEquals(0.0, way.getLongestSegmentLength());
     158        way.setNodes(Arrays.asList(n1, n2, n2, n3, n4));
     159
     160        assertEquals(3148.5902810874577, way.getLongestSegmentLength());
     161    }
    137162}
  • trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java

    r18037 r18553  
    128128    @Test
    129129    void testPositionListString() {
    130         assertEquals("1", Utils.getPositionListString(Arrays.asList(1)));
     130        assertEquals("1", Utils.getPositionListString(Collections.singletonList(1)));
    131131        assertEquals("1-2", Utils.getPositionListString(Arrays.asList(1, 2)));
    132132        assertEquals("1-3", Utils.getPositionListString(Arrays.asList(1, 2, 3)));
     
    251251    @Test
    252252    void testJoinAsHtmlUnorderedList() {
    253         List<? extends Object> items = Arrays.asList("1", Integer.valueOf(2));
     253        List<?> items = Arrays.asList("1", 2);
    254254        assertEquals("<ul><li>1</li><li>2</li></ul>", Utils.joinAsHtmlUnorderedList(items));
    255255        assertEquals("<ul></ul>", Utils.joinAsHtmlUnorderedList(Collections.emptyList()));
     
    532532        assertEquals("Hello World", output);
    533533    }
     534
     535    /**
     536     * Test of {@link Utils#getStandardDeviation(double[])} and {@link Utils#getStandardDeviation(double[], double)}
     537     */
     538    @Test
     539    void testGetStandardDeviation() {
     540        assertEquals(0.0, Utils.getStandardDeviation(new double[]{1, 1, 1, 1}));
     541        assertEquals(0.0, Utils.getStandardDeviation(new double[]{1, 1, 1, 1}, 1.0));
     542        assertEquals(0.5, Utils.getStandardDeviation(new double[]{1, 1, 2, 2}));
     543
     544        assertEquals(-1.0, Utils.getStandardDeviation(new double[]{}));
     545        assertEquals(-1.0, Utils.getStandardDeviation(new double[]{0}));
     546    }
    534547}
Note: See TracChangeset for help on using the changeset viewer.