Ignore:
Timestamp:
2020-12-07T11:52:15+01:00 (3 years ago)
Author:
GerdP
Message:

see #10205: Strange align nodes in circle behavior

  • allow to define center node also when a single unclosed way is selected
  • add robustness and more unit tests for evaluation of valid selections
  • if only nodes and no way are selected, order the nodes using the angle to the agv. east-north position. This should produce a predictable result
  • if way(s) are selected the order the nodes is determined by the occurence in the way(s). Self-Intersecting polygons are rejected if no center node is given
  • don't throw InvalidSelection when selection is valid but no point was moved, let buildCommand() return null instead

With a selection that gives a center point and way(s) which are not even close to a circular shape the result might still be surprising. Sometimes the way nodes are arranged around the center node, sometimes they are moved so that a circle arc with nearly the same length is produced. The result changes significantly when the way nodes are also selected. Subject to further improvements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/AlignInCircleActionTest.java

    r17386 r17393  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertFalse;
    56import static org.junit.jupiter.api.Assertions.assertNotNull;
    6 import static org.junit.jupiter.api.Assertions.assertThrows;
     7import static org.junit.jupiter.api.Assertions.assertNull;
     8import static org.junit.jupiter.api.Assertions.assertTrue;
    79
    810import java.nio.file.Files;
     
    1416import org.junit.jupiter.api.extension.RegisterExtension;
    1517import org.openstreetmap.josm.TestUtils;
     18import org.openstreetmap.josm.actions.AlignInCircleAction.InvalidSelection;
    1619import org.openstreetmap.josm.command.Command;
    1720import org.openstreetmap.josm.data.osm.DataSet;
    1821import org.openstreetmap.josm.data.osm.Node;
     22import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1923import org.openstreetmap.josm.data.osm.Way;
    2024import org.openstreetmap.josm.io.OsmReader;
    2125import org.openstreetmap.josm.testutils.JOSMTestRules;
     26import org.opentest4j.AssertionFailedError;
    2227
    2328import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    7176    /**
    7277     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20041">Bug #20041</a>.
    73      * Don't create move commands when no node is visibly moved
     78     * Don't create move commands when no node is visibly moved.
    7479     * @throws Exception if an error occurs
    7580     */
     
    8893        if (roundabout != null) {
    8994            ds.setSelected(roundabout);
    90             assertThrows(AlignInCircleAction.InvalidSelection.class, () -> AlignInCircleAction.buildCommand(ds));
     95            assertNull(AlignInCircleAction.buildCommand(ds));
    9196        }
    9297    }
     
    150155    }
    151156
     157    /**
     158     * Various cases of selections in file
     159     * @throws Exception if an error occurs
     160     */
     161    @Test
     162    void testSelectionEvaluation() throws Exception {
     163        DataSet ds = OsmReader.parseDataSet(
     164                Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "alignCircleCases.osm")), null);
     165
     166        for (int i = 0; i < 80; i++) {
     167            final String selVal = Integer.toString(i);
     168            Set<OsmPrimitive> sel = ds.allPrimitives().stream().filter(p -> p.hasTag("sel", selVal))
     169                    .collect(Collectors.toSet());
     170            if (sel.isEmpty())
     171                continue;
     172            ds.setSelected(sel);
     173            boolean selValid = sel.stream().noneMatch(p -> p.hasKey("invalid-selection"));
     174            try {
     175                AlignInCircleAction.buildCommand(ds);
     176                assertTrue(selValid, "sel=" + selVal + " is not valid?");
     177            } catch (InvalidSelection e) {
     178                assertFalse(selValid, "sel=" + selVal + " is not invalid?");
     179            } catch (Exception e) {
     180                throw new AssertionFailedError("test failed: sel=" + selVal,e);
     181            }
     182        }
     183    }
    152184}
Note: See TracChangeset for help on using the changeset viewer.