Changeset 10856 in josm


Ignore:
Timestamp:
2016-08-19T22:47:37+02:00 (4 years ago)
Author:
Don-vip
Message:

fix #13375 - Fix icon rendering (patch by michael2402) - gsoc-core + add unit test

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r10842 r10856  
    703703        g.setFont(text.font);
    704704
    705         int x = (int) (p.getInViewX() + text.xOffset);
    706         int y = (int) (p.getInViewY() + text.yOffset);
     705        int x = (int) (Math.round(p.getInViewX()) + text.xOffset);
     706        int y = (int) (Math.round(p.getInViewY()) + text.yOffset);
    707707        /**
    708708         *
     
    890890        }
    891891
    892         double x = p.getInViewX();
    893         double y = p.getInViewY();
     892        double x = Math.round(p.getInViewX());
     893        double y = Math.round(p.getInViewY());
    894894        temporaryGraphics.translate(x, y);
    895895        temporaryGraphics.rotate(theta);
  • trunk/src/org/openstreetmap/josm/gui/MapViewState.java

    r10829 r10856  
    216216    public MapViewPoint getCenter() {
    217217        return getForView(viewWidth / 2.0, viewHeight / 2.0);
     218    }
     219
     220    /**
     221     * Gets the center of the view, rounded to a pixel coordinate
     222     * @return The center position.
     223     * @since 10856
     224     */
     225    public MapViewPoint getCenterAtPixel() {
     226        return getForView(viewWidth / 2, viewHeight / 2);
    218227    }
    219228
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r10843 r10856  
    294294     */
    295295    public void zoomIn() {
    296         zoomTo(getCenter(), scaleZoomIn());
     296        zoomTo(state.getCenterAtPixel().getEastNorth(), scaleZoomIn());
    297297    }
    298298
     
    301301     */
    302302    public void zoomOut() {
    303         zoomTo(getCenter(), scaleZoomOut());
     303        zoomTo(state.getCenterAtPixel().getEastNorth(), scaleZoomOut());
    304304    }
    305305
     
    408408     */
    409409    public EastNorth getCenter() {
    410         return state.getCenter().getEastNorth();
     410        return state.getCenterAtPixel().getEastNorth();
    411411    }
    412412
     
    608608        if (!newCenter.equals(getCenter())) {
    609609            EastNorth oldCenter = getCenter();
    610             state = state.usingCenter(newCenter);
     610            state = state.movedTo(state.getCenterAtPixel(), newCenter);
    611611            if (!initial) {
    612612                firePropertyChange(PROPNAME_CENTER, oldCenter, newCenter);
     
    617617            state = state.usingScale(newScale);
    618618            // temporary. Zoom logic needs to be moved.
    619             state = state.movedTo(state.getCenter(), newCenter);
     619            state = state.movedTo(state.getCenterAtPixel(), newCenter);
    620620            if (!initial) {
    621621                firePropertyChange(PROPNAME_SCALE, oldScale, newScale);
  • trunk/test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java

    r10462 r10856  
    77import java.awt.geom.Point2D;
    88import java.util.Arrays;
     9import java.util.function.Function;
    910
    1011import org.junit.Before;
     
    2324public class MapViewStateTest {
    2425
    25     private static final int WIDTH = 300;
     26    private static final int WIDTH = 301;
    2627    private static final int HEIGHT = 200;
    2728    private MapViewState state;
     
    4344    }
    4445
     46    private void doTestGetCenter(Function<MapViewState, MapViewPoint> getter, Function<Integer, Double> divider) {
     47        MapViewPoint center = getter.apply(state);
     48        assertHasViewCoords(divider.apply(WIDTH), divider.apply(HEIGHT), center);
     49
     50        MapViewState newState = state.movedTo(center, new EastNorth(3, 4));
     51
     52        // state should not change, but new state should.
     53        center = getter.apply(state);
     54        assertHasViewCoords(divider.apply(WIDTH), divider.apply(HEIGHT), center);
     55
     56        center = getter.apply(newState);
     57        assertEquals("east", 3, center.getEastNorth().east(), 0.01);
     58        assertEquals("north", 4, center.getEastNorth().north(), 0.01);
     59    }
     60
    4561    /**
    4662     * Test {@link MapViewState#getCenter()} returns map view center.
     
    4864    @Test
    4965    public void testGetCenter() {
    50         MapViewPoint center = state.getCenter();
    51         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center);
    52 
    53         MapViewState newState = state.movedTo(center, new EastNorth(3, 4));
    54 
    55         // state should not change, but new state should.
    56         center = state.getCenter();
    57         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center);
    58 
    59         center = newState.getCenter();
    60         assertEquals("east", 3, center.getEastNorth().east(), 0.01);
    61         assertEquals("north", 4, center.getEastNorth().north(), 0.01);
     66        doTestGetCenter(s -> s.getCenter(), t -> t / 2d);
    6267    }
    6368
    64     private void assertHasViewCoords(double x, double y, MapViewPoint center) {
     69    /**
     70     * Test {@link MapViewState#getCenterAtPixel()} returns map view center.
     71     */
     72    @Test
     73    public void testGetCenterAtPixel() {
     74        doTestGetCenter(s -> s.getCenterAtPixel(), t -> (double) (t / 2));
     75    }
     76
     77    private static void assertHasViewCoords(double x, double y, MapViewPoint center) {
    6578        assertEquals("x", x, center.getInViewX(), 0.01);
    6679        assertEquals("y", y, center.getInViewY(), 0.01);
     
    101114    @Test
    102115    public void testPointConversions() {
    103         MapViewPoint p = state.getForView(WIDTH / 2, HEIGHT / 2);
    104         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, p);
     116        MapViewPoint p = state.getForView(WIDTH / 2d, HEIGHT / 2d);
     117        assertHasViewCoords(WIDTH / 2d, HEIGHT / 2d, p);
    105118
    106119        EastNorth eastnorth = p.getEastNorth();
     
    110123        assertEquals("north", shouldEastNorth.north(), eastnorth.north(), 0.01);
    111124        MapViewPoint reversed = state.getPointFor(shouldEastNorth);
    112         assertHasViewCoords(WIDTH / 2, HEIGHT / 2, reversed);
     125        assertHasViewCoords(WIDTH / 2d, HEIGHT / 2d, reversed);
    113126
    114127        LatLon latlon = p.getLatLon();
Note: See TracChangeset for help on using the changeset viewer.