Ticket #12975: patch-fix-12975.patch

File patch-fix-12975.patch, 2.4 KB (added by michael2402, 8 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 a975608..fc74e39 100644
    a b public final class MapViewState {  
    171171     * @since xxx
    172172     */
    173173    public AffineTransform getAffineTransform() {
    174         return new AffineTransform(1.0 / scale, 0.0, 0.0, -1.0 / scale, topLeft.east() / scale,
     174        return new AffineTransform(1.0 / scale, 0.0, 0.0, -1.0 / scale, -topLeft.east() / scale,
    175175                topLeft.north() / scale);
    176176    }
    177177
  • 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 334a020..8bf9591 100644
    a b package org.openstreetmap.josm.gui;  
    33
    44import static org.junit.Assert.assertEquals;
    55
     6import java.awt.geom.AffineTransform;
     7import java.awt.geom.Point2D;
     8import java.util.Arrays;
     9
    610import org.junit.Before;
    711import org.junit.BeforeClass;
    812import org.junit.Test;
    public class MapViewStateTest {  
    99103        MapViewPoint p = state.getForView(WIDTH / 2, HEIGHT / 2);
    100104        assertHasViewCoords(WIDTH / 2, HEIGHT / 2, p);
    101105
    102 
    103106        EastNorth eastnorth = p.getEastNorth();
    104107        LatLon shouldLatLon = Main.getProjection().getWorldBoundsLatLon().getCenter();
    105108        EastNorth shouldEastNorth = Main.getProjection().latlon2eastNorth(shouldLatLon);
    public class MapViewStateTest {  
    116119        assertEquals("east", 2, p2.getEastNorth().east(), 0.01);
    117120        assertEquals("north", 3, p2.getEastNorth().north(), 0.01);
    118121    }
     122
     123    /**
     124     * Test {@link MapViewState#getAffineTransform()}
     125     */
     126    @Test
     127    public void testGetAffineTransform() {
     128        for (EastNorth en : Arrays.asList(new EastNorth(100, 100), new EastNorth(0, 0), new EastNorth(300, 200),
     129                new EastNorth(-1, -2.5))) {
     130            MapViewPoint should = state.getPointFor(en);
     131            AffineTransform transform = state.getAffineTransform();
     132            Point2D result = transform.transform(new Point2D.Double(en.getX(), en.getY()), null);
     133
     134            assertEquals("x", should.getInViewX(), result.getX(), 0.01);
     135            assertEquals("y", should.getInViewY(), result.getY(), 0.01);
     136        }
     137    }
    119138}