This commit is contained in:
Hannes Janetzek 2013-09-16 02:53:51 +02:00
parent d50a6fa203
commit 1c0315cd54
3 changed files with 114 additions and 8 deletions

@ -14,15 +14,38 @@
*/
package org.oscim.core;
/**
* The Class Box.
*/
public class Box {
/** The min x. */
public double minX;
/** The max x. */
public double maxX;
/** The min y. */
public double minY;
/** The max y. */
public double maxY;
public Box(){
/**
* Instantiates a new Box with all values being 0.
*/
public Box() {
}
/**
* Instantiates a new Box.
*
* @param minX the min x
* @param minY the min y
* @param maxX the max x
* @param maxY the max y
*/
public Box(double minX, double minY, double maxX, double maxY) {
this.minX = minX;
this.minY = minY;
@ -30,11 +53,24 @@ public class Box {
this.maxY = maxY;
}
public boolean contains(double x, double y){
/**
* Check if Box contains point defined by coordinates x and y.
*
* @param x the x ordinate
* @param y the y ordinate
* @return true, if point is inside box.
*/
public boolean contains(double x, double y) {
return (x >= minX && x <= maxY && y >= minY && y <= maxY);
}
public boolean contains(Point p){
/**
* Check if Box contains Point.
*
* @param p the point
* @return true, if point is inside box.
*/
public boolean contains(Point p) {
return (p.x >= minX && p.x <= maxY && p.y >= minY && p.y <= maxY);
}
}

@ -1,22 +1,29 @@
package org.oscim.core;
// TODO: Auto-generated Javadoc
// TODO
// - getter methods!
// - check indexPos < Short.Max
// - should make internals private, maybe
/**
* Class to hold temporary geometry data for processing. Only One
* geometry type can be set at a time. Use 'clear()' to reset the
* The GeometryBuffer class holds temporary geometry data for processing.
* Only One geometry type can be set at a time. Use 'clear()' to reset the
* internal state.
* - 'points[]' holds the coordinates
* - 'index[]' is used to encode multi-linestrings and (multi-)polygons.
* <p>
* 'points[]' holds interleaved x,y coordinates
* <p>
* 'index[]' is used to store number of points within a geometry and encode
* multi-linestrings and (multi-)polygons.
*/
public class GeometryBuffer {
private final static int GROW_INDICES = 64;
private final static int GROW_POINTS = 512;
/**
* The Enum GeometryType.
*/
public enum GeometryType {
NONE(0),
POINT(1),
@ -31,13 +38,27 @@ public class GeometryBuffer {
public final int nativeInt;
}
/** The points. */
public float[] points;
/** The indexes. */
public short[] index;
/** The current index position. */
public int indexPos;
/** The current position in points array. */
public int pointPos;
/** The current geometry type. */
public GeometryType type;
/**
* Instantiates a new geometry buffer.
*
* @param points the points
* @param index the index
*/
public GeometryBuffer(float[] points, short[] index) {
if (points == null)
points = new float[GROW_POINTS];
@ -51,11 +72,20 @@ public class GeometryBuffer {
this.pointPos = 0;
}
/**
* Instantiates a new geometry buffer.
*
* @param numPoints the num points
* @param numIndices the num indices
*/
public GeometryBuffer(int numPoints, int numIndices) {
this(new float[numPoints * 2], new short[numIndices]);
}
// ---- API ----
/**
* Reset buffer.
*/
public void clear() {
index[0] = -1;
indexPos = 0;
@ -63,6 +93,12 @@ public class GeometryBuffer {
type = GeometryType.NONE;
}
/**
* Adds a point with the coordinates x and y.
*
* @param x the x ordinate
* @param y the y ordinate
*/
public void addPoint(float x, float y) {
if (pointPos >= points.length - 1)
ensurePointSize((pointPos >> 1) + 1, true);
@ -85,15 +121,28 @@ public class GeometryBuffer {
return type == GeometryType.POINT;
}
/**
* Sets the point x,y at position pos.
*
* @param pos the pos
* @param x the x ordinate
* @param y the y ordinate
*/
public void setPoint(int pos, float x, float y) {
points[(pos << 1) + 0] = x;
points[(pos << 1) + 1] = y;
}
/**
* Set geometry type for points.
*/
public void startPoints() {
setOrCheckMode(GeometryType.POINT);
}
/**
* Start a new line. Sets geometry type for lines.
*/
public void startLine() {
setOrCheckMode(GeometryType.LINE);
@ -109,6 +158,9 @@ public class GeometryBuffer {
index[indexPos + 1] = -1;
}
/**
* Start a new polygon. Sets geometry type for polygons.
*/
public void startPolygon() {
boolean start = (type == GeometryType.NONE);
setOrCheckMode(GeometryType.POLY);
@ -132,6 +184,9 @@ public class GeometryBuffer {
index[indexPos + 1] = -1;
}
/**
* Starts a new polygon hole (inner ring).
*/
public void startHole() {
checkMode(GeometryType.POLY);
@ -147,6 +202,13 @@ public class GeometryBuffer {
}
// ---- internals ----
/**
* Ensure point size.
*
* @param size the size
* @param copy the copy
* @return the float[] array holding current coordinates
*/
public float[] ensurePointSize(int size, boolean copy) {
if (size * 2 < points.length)
return points;
@ -159,6 +221,13 @@ public class GeometryBuffer {
return points;
}
/**
* Ensure index size.
*
* @param size the size
* @param copy the copy
* @return the short[] array holding current index
*/
public short[] ensureIndexSize(int size, boolean copy) {
if (size < index.length)
return index;

@ -19,7 +19,8 @@ package org.oscim.core;
// move it to tilesource package
/**
* Reusable containter for geometry with tags.
* The MapElement class is a reusable containter for a geometry
* with tags.
* MapElement is created by TileDataSource(s) and passed to
* MapTileLoader via ITileDataSink.process().
* This is just a buffer that belongs to TileDataSource,