Changeset 10856 in josm
- Timestamp:
- 2016-08-19T22:47:37+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r10842 r10856 703 703 g.setFont(text.font); 704 704 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); 707 707 /** 708 708 * … … 890 890 } 891 891 892 double x = p.getInViewX();893 double y = p.getInViewY();892 double x = Math.round(p.getInViewX()); 893 double y = Math.round(p.getInViewY()); 894 894 temporaryGraphics.translate(x, y); 895 895 temporaryGraphics.rotate(theta); -
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r10829 r10856 216 216 public MapViewPoint getCenter() { 217 217 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); 218 227 } 219 228 -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r10843 r10856 294 294 */ 295 295 public void zoomIn() { 296 zoomTo( getCenter(), scaleZoomIn());296 zoomTo(state.getCenterAtPixel().getEastNorth(), scaleZoomIn()); 297 297 } 298 298 … … 301 301 */ 302 302 public void zoomOut() { 303 zoomTo( getCenter(), scaleZoomOut());303 zoomTo(state.getCenterAtPixel().getEastNorth(), scaleZoomOut()); 304 304 } 305 305 … … 408 408 */ 409 409 public EastNorth getCenter() { 410 return state.getCenter ().getEastNorth();410 return state.getCenterAtPixel().getEastNorth(); 411 411 } 412 412 … … 608 608 if (!newCenter.equals(getCenter())) { 609 609 EastNorth oldCenter = getCenter(); 610 state = state. usingCenter(newCenter);610 state = state.movedTo(state.getCenterAtPixel(), newCenter); 611 611 if (!initial) { 612 612 firePropertyChange(PROPNAME_CENTER, oldCenter, newCenter); … … 617 617 state = state.usingScale(newScale); 618 618 // temporary. Zoom logic needs to be moved. 619 state = state.movedTo(state.getCenter (), newCenter);619 state = state.movedTo(state.getCenterAtPixel(), newCenter); 620 620 if (!initial) { 621 621 firePropertyChange(PROPNAME_SCALE, oldScale, newScale); -
trunk/test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java
r10462 r10856 7 7 import java.awt.geom.Point2D; 8 8 import java.util.Arrays; 9 import java.util.function.Function; 9 10 10 11 import org.junit.Before; … … 23 24 public class MapViewStateTest { 24 25 25 private static final int WIDTH = 30 0;26 private static final int WIDTH = 301; 26 27 private static final int HEIGHT = 200; 27 28 private MapViewState state; … … 43 44 } 44 45 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 45 61 /** 46 62 * Test {@link MapViewState#getCenter()} returns map view center. … … 48 64 @Test 49 65 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); 62 67 } 63 68 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) { 65 78 assertEquals("x", x, center.getInViewX(), 0.01); 66 79 assertEquals("y", y, center.getInViewY(), 0.01); … … 101 114 @Test 102 115 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); 105 118 106 119 EastNorth eastnorth = p.getEastNorth(); … … 110 123 assertEquals("north", shouldEastNorth.north(), eastnorth.north(), 0.01); 111 124 MapViewPoint reversed = state.getPointFor(shouldEastNorth); 112 assertHasViewCoords(WIDTH / 2 , HEIGHT / 2, reversed);125 assertHasViewCoords(WIDTH / 2d, HEIGHT / 2d, reversed); 113 126 114 127 LatLon latlon = p.getLatLon();
Note:
See TracChangeset
for help on using the changeset viewer.