refactor: PointD -> Point, remove PointF

This commit is contained in:
Hannes Janetzek 2013-09-10 17:56:28 +02:00
parent e203f2916d
commit d397624fdc
14 changed files with 43 additions and 83 deletions

View File

@ -34,7 +34,7 @@ public class Box {
return (x >= minX && x <= maxY && y >= minY && y <= maxY); return (x >= minX && x <= maxY && y >= minY && y <= maxY);
} }
public boolean contains(PointD p){ public boolean contains(Point p){
return (p.x >= minX && p.x <= maxY && p.y >= minY && p.y <= maxY); return (p.x >= minX && p.x <= maxY && p.y >= minY && p.y <= maxY);
} }
} }

View File

@ -68,7 +68,7 @@ public class GeoPoint implements Comparable<GeoPoint> {
this(latitudeE6 / CONVERSION_FACTOR, longitudeE6 / CONVERSION_FACTOR); this(latitudeE6 / CONVERSION_FACTOR, longitudeE6 / CONVERSION_FACTOR);
} }
public void project(PointD out) { public void project(Point out) {
out.x = MercatorProjection.longitudeToX(this.longitudeE6 / CONVERSION_FACTOR); out.x = MercatorProjection.longitudeToX(this.longitudeE6 / CONVERSION_FACTOR);
out.y = MercatorProjection.latitudeToY(this.latitudeE6 / CONVERSION_FACTOR); out.y = MercatorProjection.latitudeToY(this.latitudeE6 / CONVERSION_FACTOR);
} }

View File

@ -91,9 +91,9 @@ public final class MercatorProjection {
return 360.0 * (x - 0.5); return 360.0 * (x - 0.5);
} }
public static PointD project(GeoPoint p, PointD reuse) { public static Point project(GeoPoint p, Point reuse) {
if (reuse == null) if (reuse == null)
reuse = new PointD(); reuse = new Point();
reuse.x = ((p.longitudeE6 / 1E6) + 180.0) / 360.0; reuse.x = ((p.longitudeE6 / 1E6) + 180.0) / 360.0;

View File

@ -14,12 +14,12 @@
*/ */
package org.oscim.core; package org.oscim.core;
public class PointD { public class Point {
public double x; public double x;
public double y; public double y;
public PointD() { public Point() {
} }
PointD(double x, double y){ public Point(double x, double y){
this.x = x; this.x = x;
this.y = y; this.y = y;
} }

View File

@ -1,38 +0,0 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
/**
* without further ado: This class represents a 2D Point using float coordinates
*/
public class PointF {
public float x;
public float y;
public PointF() {
}
public PointF(float x, float y) {
this.x = x;
this.y = y;
}
public void set(float x, float y) {
this.x = x;
this.y = y;
}
}

View File

@ -19,8 +19,7 @@ import java.util.List;
import org.oscim.backend.input.MotionEvent; import org.oscim.backend.input.MotionEvent;
import org.oscim.core.BoundingBox; import org.oscim.core.BoundingBox;
import org.oscim.core.PointD; import org.oscim.core.Point;
import org.oscim.core.PointF;
import org.oscim.view.Map; import org.oscim.view.Map;
import org.oscim.view.Viewport; import org.oscim.view.Viewport;
@ -31,7 +30,7 @@ public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverl
protected OnItemGestureListener<Item> mOnItemGestureListener; protected OnItemGestureListener<Item> mOnItemGestureListener;
private int mDrawnItemsLimit = Integer.MAX_VALUE; private int mDrawnItemsLimit = Integer.MAX_VALUE;
private final PointD mTmpPoint = new PointD(); private final Point mTmpPoint = new Point();
public ItemizedIconOverlay( public ItemizedIconOverlay(
final Map map, final Map map,
@ -57,7 +56,7 @@ public class ItemizedIconOverlay<Item extends OverlayItem> extends ItemizedOverl
// } // }
@Override @Override
public boolean onSnapToItem(final int pX, final int pY, final PointF pSnapPoint) { public boolean onSnapToItem(final int pX, final int pY, final Point pSnapPoint) {
// TODO Implement this! // TODO Implement this!
return false; return false;
} }

View File

@ -23,7 +23,7 @@ package org.oscim.layers.overlay;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection; import org.oscim.core.MercatorProjection;
import org.oscim.core.PointD; import org.oscim.core.Point;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLRenderer.Matrices;
import org.oscim.renderer.layers.BasicRenderLayer; import org.oscim.renderer.layers.BasicRenderLayer;
@ -152,9 +152,9 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
continue; continue;
} }
int state = 0; //int state = 0;
if (mDrawFocusedItem && (mFocusedItem == it.item)) //if (mDrawFocusedItem && (mFocusedItem == it.item))
state = OverlayItem.ITEM_STATE_FOCUSED_MASK; // state = OverlayItem.ITEM_STATE_FOCUSED_MASK;
//Drawable marker = it.item.getDrawable(); //Drawable marker = it.item.getDrawable();
OverlayMarker marker = it.item.getMarker(); OverlayMarker marker = it.item.getMarker();
@ -223,7 +223,7 @@ public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
mLayer = new ItemOverlay(); mLayer = new ItemOverlay();
} }
private final PointD mMapPoint = new PointD(); private final Point mMapPoint = new Point();
/** /**
* Utility method to perform all processing on a new ItemizedOverlay. * Utility method to perform all processing on a new ItemizedOverlay.

View File

@ -16,9 +16,9 @@
package org.oscim.layers.overlay; package org.oscim.layers.overlay;
import org.oscim.view.Map; import org.oscim.core.Point;
import org.oscim.core.PointF;
import org.oscim.layers.InputLayer; import org.oscim.layers.InputLayer;
import org.oscim.view.Map;
/** /**
* Base class representing an overlay which may be displayed on top of a * Base class representing an overlay which may be displayed on top of a
@ -60,7 +60,7 @@ public abstract class Overlay extends InputLayer {
* untouched if not snapping. * untouched if not snapping.
* @return Whether or not to snap to the interesting point. * @return Whether or not to snap to the interesting point.
*/ */
boolean onSnapToItem(int x, int y, PointF snapPoint); boolean onSnapToItem(int x, int y, Point snapPoint);
} }
///** ///**

View File

@ -15,19 +15,19 @@
package org.oscim.layers.overlay; package org.oscim.layers.overlay;
import org.oscim.backend.canvas.Bitmap; import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.PointF; import org.oscim.core.Point;
import org.oscim.layers.overlay.OverlayItem.HotspotPlace; import org.oscim.layers.overlay.OverlayItem.HotspotPlace;
public class OverlayMarker { public class OverlayMarker {
final Bitmap[] mBitmap; final Bitmap[] mBitmap;
// Hotspot offset // Hotspot offset
final PointF[] mOffset; final Point[] mOffset;
public OverlayMarker(Bitmap bitmap, float relX, float relY) { public OverlayMarker(Bitmap bitmap, float relX, float relY) {
mBitmap = new Bitmap[1]; mBitmap = new Bitmap[1];
mBitmap[0] = bitmap; mBitmap[0] = bitmap;
mOffset = new PointF[1]; mOffset = new Point[1];
mOffset[0] = new PointF(relX, relY); mOffset[0] = new Point(relX, relY);
} }
public OverlayMarker(Bitmap bitmap, HotspotPlace hotspot) { public OverlayMarker(Bitmap bitmap, HotspotPlace hotspot) {
@ -76,11 +76,11 @@ public class OverlayMarker {
mBitmap = new Bitmap[1]; mBitmap = new Bitmap[1];
mBitmap[0] = bitmap; mBitmap[0] = bitmap;
mOffset = new PointF[1]; mOffset = new Point[1];
mOffset[0] = new PointF(x, y); mOffset[0] = new Point(x, y);
} }
public PointF getHotspot() { public Point getHotspot() {
return mOffset[0]; return mOffset[0];
} }

View File

@ -15,7 +15,7 @@
package org.oscim.renderer.sublayers; package org.oscim.renderer.sublayers;
import org.oscim.backend.canvas.Bitmap; import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.PointF; import org.oscim.core.Point;
import org.oscim.renderer.atlas.TextureRegion; import org.oscim.renderer.atlas.TextureRegion;
import org.oscim.utils.pool.Inlist; import org.oscim.utils.pool.Inlist;
import org.oscim.utils.pool.SyncPool; import org.oscim.utils.pool.SyncPool;
@ -46,6 +46,6 @@ public class SymbolItem extends Inlist<SymbolItem> {
public TextureRegion symbol; public TextureRegion symbol;
public Bitmap bitmap; public Bitmap bitmap;
public PointF offset; public Point offset;
} }

View File

@ -129,8 +129,8 @@ public final class SymbolLayer extends TextureLayer {
y1 = (short) (SCALE * (hh)); y1 = (short) (SCALE * (hh));
y2 = (short) (SCALE * (-hh)); y2 = (short) (SCALE * (-hh));
} else { } else {
float hw = it.offset.x * width; float hw = (float)(it.offset.x * width);
float hh = it.offset.y * height; float hh = (float)(it.offset.y * height);
x1 = (short) (SCALE * (-hw)); x1 = (short) (SCALE * (-hw));
x2 = (short) (SCALE * (width - hw)); x2 = (short) (SCALE * (width - hw));
y1 = (short) (SCALE * (height - hh)); y1 = (short) (SCALE * (height - hh));

View File

@ -14,7 +14,7 @@
*/ */
package org.oscim.utils; package org.oscim.utils;
import org.oscim.core.PointD; import org.oscim.core.Point;
/** /**
@ -176,7 +176,7 @@ public final class GeometryUtils {
double ax2, double ay2, double ax2, double ay2,
double bx1, double by1, double bx1, double by1,
double bx2, double by2, double bx2, double by2,
PointD point) Point point)
{ {
double ua_numr = (bx2 - bx1) * (ay1 - by1) - (by2 - by1) * (ax1 - bx1); double ua_numr = (bx2 - bx1) * (ay1 - by1) - (by2 - by1) * (ax1 - bx1);
double ub_numr = (ax2 - ax1) * (ay1 - by1) - (ay2 - ay1) * (ax1 - bx1); double ub_numr = (ax2 - ax1) * (ay1 - by1) - (ay2 - ay1) * (ax1 - bx1);

View File

@ -23,7 +23,7 @@ import org.oscim.backend.Log;
import org.oscim.backend.input.KeyEvent; import org.oscim.backend.input.KeyEvent;
import org.oscim.backend.input.MotionEvent; import org.oscim.backend.input.MotionEvent;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.PointF; import org.oscim.core.Point;
import org.oscim.layers.InputLayer; import org.oscim.layers.InputLayer;
import org.oscim.layers.Layer; import org.oscim.layers.Layer;
import org.oscim.layers.overlay.Overlay.Snappable; import org.oscim.layers.overlay.Overlay.Snappable;
@ -227,7 +227,7 @@ public class Layers extends AbstractList<Layer> {
return false; return false;
} }
public boolean onSnapToItem(final int x, final int y, final PointF snapPoint) { public boolean onSnapToItem(int x, int y, Point snapPoint) {
if (mDirtyLayers) if (mDirtyLayers)
updateLayers(); updateLayers();

View File

@ -20,8 +20,7 @@ import org.oscim.core.Box;
import org.oscim.core.GeoPoint; import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection; import org.oscim.core.MercatorProjection;
import org.oscim.core.PointD; import org.oscim.core.Point;
import org.oscim.core.PointF;
import org.oscim.core.Tile; import org.oscim.core.Tile;
import org.oscim.utils.FastMath; import org.oscim.utils.FastMath;
import org.oscim.utils.Matrix4; import org.oscim.utils.Matrix4;
@ -66,7 +65,7 @@ public class Viewport {
private final Matrix4 mTmpMatrix = new Matrix4(); private final Matrix4 mTmpMatrix = new Matrix4();
// temporary vars: only use in synchronized functions! // temporary vars: only use in synchronized functions!
private final PointD mMovePoint = new PointD(); private final Point mMovePoint = new Point();
private final float[] mv = new float[4]; private final float[] mv = new float[4];
private final float[] mu = new float[4]; private final float[] mu = new float[4];
private final float[] mViewCoords = new float[8]; private final float[] mViewCoords = new float[8];
@ -300,7 +299,7 @@ public class Viewport {
* @param y screen coordinate * @param y screen coordinate
* @param out Point coords will be set * @param out Point coords will be set
*/ */
public synchronized void getScreenPointOnMap(float x, float y, double scale, PointD out) { public synchronized void getScreenPointOnMap(float x, float y, double scale, Point out) {
// scale to -1..1 // scale to -1..1
float mx = 1 - (x / mWidth * 2); float mx = 1 - (x / mWidth * 2);
@ -338,7 +337,7 @@ public class Viewport {
* @param x screen coordinate * @param x screen coordinate
* @param y screen coordinate * @param y screen coordinate
*/ */
public synchronized void fromScreenPixels(double x, double y, PointD out) { public synchronized void fromScreenPixels(double x, double y, Point out) {
// scale to -1..1 // scale to -1..1
float mx = (float) (1 - (x / mWidth * 2)); float mx = (float) (1 - (x / mWidth * 2));
float my = (float) (1 - (y / mHeight * 2)); float my = (float) (1 - (y / mHeight * 2));
@ -375,7 +374,7 @@ public class Viewport {
* @param geoPoint the GeoPoint * @param geoPoint the GeoPoint
* @param out Point projected to screen pixel relative to center * @param out Point projected to screen pixel relative to center
*/ */
public synchronized void project(GeoPoint geoPoint, PointD out) { public synchronized void project(GeoPoint geoPoint, Point out) {
MercatorProjection.project(geoPoint, out); MercatorProjection.project(geoPoint, out);
project(out.x, out.y, out); project(out.x, out.y, out);
} }
@ -385,7 +384,7 @@ public class Viewport {
* *
* @param out Point projected to screen pixel * @param out Point projected to screen pixel
*/ */
public synchronized void project(double x, double y, PointD out) { public synchronized void project(double x, double y, Point out) {
mv[0] = (float) (x * mCurScale - mCurX); mv[0] = (float) (x * mCurScale - mCurX);
mv[1] = (float) (y * mCurScale - mCurY); mv[1] = (float) (y * mCurScale - mCurY);
@ -454,7 +453,7 @@ public class Viewport {
// stop animation // stop animation
animCancel(); animCancel();
PointD p = applyRotation(mx, my); Point p = applyRotation(mx, my);
move(p.x, p.y); move(p.x, p.y);
} }
@ -474,7 +473,7 @@ public class Viewport {
updatePosition(); updatePosition();
} }
private PointD applyRotation(float mx, float my) { private Point applyRotation(float mx, float my) {
double rad = Math.toRadians(mRotation); double rad = Math.toRadians(mRotation);
double rcos = Math.cos(rad); double rcos = Math.cos(rad);
double rsin = Math.sin(rad); double rsin = Math.sin(rad);
@ -720,7 +719,7 @@ public class Viewport {
float dy = mVelocityY * adv; float dy = mVelocityY * adv;
if (dx != 0 || dy != 0) { if (dx != 0 || dy != 0) {
PointD p = applyRotation((float) (dx - mScrollX), (float) (dy - mScrollY)); Point p = applyRotation((float) (dx - mScrollX), (float) (dy - mScrollY));
move(p.x, p.y); move(p.x, p.y);
mScrollX = dx; mScrollX = dx;
@ -835,7 +834,7 @@ public class Viewport {
if (mAnimPivot) { if (mAnimPivot) {
scale = mAbsScale / scale; scale = mAbsScale / scale;
PointD p = applyRotation( Point p = applyRotation(
(float) (mScrollX * (1.0 - scale)), (float) (mScrollX * (1.0 - scale)),
(float) (mScrollY * (1.0 - scale))); (float) (mScrollY * (1.0 - scale)));
move(p.x, p.y); move(p.x, p.y);