Ticket #13397: patch-fix-13397.patch

File patch-fix-13397.patch, 5.2 KB (added by michael2402, 3 years ago)
  • src/org/openstreetmap/josm/gui/MapViewState.java

    diff --git a/src/org/openstreetmap/josm/gui/MapViewState.java b/src/org/openstreetmap/josm/gui/MapViewState.java
    index 9cc4701..97e6037 100644
    a b public final class MapViewState { 
    4646     * A flag indicating that the point is outside to the left of the map view.
    4747     * @since 10827
    4848     */
    49     public static final int OUTSIDE_LEFT = 3;
     49    public static final int OUTSIDE_LEFT = 4;
    5050
    5151    /**
    5252     * A flag indicating that the point is outside to the right of the map view.
    5353     * @since 10827
    5454     */
    55     public static final int OUTSIDE_RIGHT = 4;
     55    public static final int OUTSIDE_RIGHT = 8;
    5656
    5757    private final Projecting projecting;
    5858
    public final class MapViewState { 
    498498         * @since 10827
    499499         */
    500500        public double oneNormInView(MapViewPoint p2) {
    501             return Math.abs(getInViewX() - p2.getInViewX()) + Math.abs(getInViewY()) - p2.getInViewY();
     501            return Math.abs(getInViewX() - p2.getInViewX()) + Math.abs(getInViewY() - p2.getInViewY());
    502502        }
    503503
    504504        /**
  • test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java b/test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java
    index b03d25f..9621595 100644
    a b import org.openstreetmap.josm.Main; 
    1616import org.openstreetmap.josm.data.coor.EastNorth;
    1717import org.openstreetmap.josm.data.coor.LatLon;
    1818import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
     19import org.openstreetmap.josm.gui.MapViewState.MapViewRectangle;
    1920
    2021/**
    2122 * Test {@link MapViewState}
    public class MapViewStateTest { 
    150151    }
    151152
    152153    /**
     154     * Test {@link MapViewState#OUTSIDE_BOTTOM} and similar constants.
     155     * @since xxx
     156     */
     157    @Test
     158    public void testOutsideFlags() {
     159        assertEquals(1, Integer.bitCount(MapViewState.OUTSIDE_BOTTOM));
     160        assertEquals(1, Integer.bitCount(MapViewState.OUTSIDE_TOP));
     161        assertEquals(1, Integer.bitCount(MapViewState.OUTSIDE_LEFT));
     162        assertEquals(1, Integer.bitCount(MapViewState.OUTSIDE_RIGHT));
     163        assertEquals(4, Integer.bitCount(MapViewState.OUTSIDE_BOTTOM | MapViewState.OUTSIDE_TOP
     164                | MapViewState.OUTSIDE_LEFT | MapViewState.OUTSIDE_RIGHT));
     165    }
     166
     167    /**
     168     * Test {@link MapViewPoint#getOutsideRectangleFlags(MapViewRectangle)}
     169     * @since xxx
     170     */
     171    @Test
     172    public void testPointGetOutsideRectangleFlags() {
     173        MapViewRectangle rect = state.getForView(0, 0).rectTo(state.getForView(10, 10));
     174        assertEquals(0, state.getForView(1, 1).getOutsideRectangleFlags(rect));
     175        assertEquals(0, state.getForView(1, 5).getOutsideRectangleFlags(rect));
     176        assertEquals(0, state.getForView(9, 1).getOutsideRectangleFlags(rect));
     177        assertEquals(0, state.getForView(10 - 1e-10, 1e-10).getOutsideRectangleFlags(rect));
     178        assertEquals(0, state.getForView(10 - 1e-10, 10 - 1e-10).getOutsideRectangleFlags(rect));
     179
     180
     181        assertEquals(MapViewState.OUTSIDE_TOP, state.getForView(1, -11).getOutsideRectangleFlags(rect));
     182        assertEquals(MapViewState.OUTSIDE_TOP, state.getForView(1, -1e20).getOutsideRectangleFlags(rect));
     183
     184        assertEquals(MapViewState.OUTSIDE_BOTTOM, state.getForView(1, 11).getOutsideRectangleFlags(rect));
     185        assertEquals(MapViewState.OUTSIDE_BOTTOM, state.getForView(1, 1e20).getOutsideRectangleFlags(rect));
     186
     187        assertEquals(MapViewState.OUTSIDE_LEFT, state.getForView(-11, 1).getOutsideRectangleFlags(rect));
     188        assertEquals(MapViewState.OUTSIDE_LEFT, state.getForView(-1e20, 1).getOutsideRectangleFlags(rect));
     189        assertEquals(MapViewState.OUTSIDE_RIGHT, state.getForView(11, 1).getOutsideRectangleFlags(rect));
     190        assertEquals(MapViewState.OUTSIDE_RIGHT, state.getForView(1e20, 1).getOutsideRectangleFlags(rect));
     191
     192        assertEquals(MapViewState.OUTSIDE_RIGHT | MapViewState.OUTSIDE_TOP, state.getForView(11, -11).getOutsideRectangleFlags(rect));
     193        assertEquals(MapViewState.OUTSIDE_RIGHT | MapViewState.OUTSIDE_BOTTOM, state.getForView(11, 11).getOutsideRectangleFlags(rect));
     194        assertEquals(MapViewState.OUTSIDE_LEFT | MapViewState.OUTSIDE_TOP, state.getForView(-11, -11).getOutsideRectangleFlags(rect));
     195        assertEquals(MapViewState.OUTSIDE_LEFT | MapViewState.OUTSIDE_BOTTOM, state.getForView(-11, 11).getOutsideRectangleFlags(rect));
     196    }
     197
     198    /**
     199     * Test {@link MapViewPoint#oneNormInView(MapViewPoint)}
     200     * @since xxx
     201     */
     202    @Test
     203    public void testPointOneNormInView() {
     204        MapViewPoint p = state.getForView(5, 15);
     205        assertEquals(0, p.oneNormInView(p), 1e-10);
     206        assertEquals(6, p.oneNormInView(state.getForView(-1, 15)), 1e-10);
     207        assertEquals(5, p.oneNormInView(state.getForView(5, 20)), 1e-10);
     208        assertEquals(22, p.oneNormInView(state.getForView(-1, -1)), 1e-10);
     209        assertEquals(40, p.oneNormInView(state.getForView(30, 30)), 1e-10);
     210    }
     211
     212    /**
    153213     * Test {@link MapViewState.MapViewViewPoint#toString()} and {@link MapViewState.MapViewEastNorthPoint#toString()}
    154214     */
    155215    @Test