Package org.oscim.core
Class GeometryBuffer
java.lang.Object
org.oscim.core.GeometryBuffer
- Direct Known Subclasses:
MapElement
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 interleaved x,y coordinates
'index[]' is used to store number of points within a geometry and encode
multi-linestrings and (multi-)polygons.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionint[]The indexes.intThe current index position.intThe next position to insert a point in points array (equal to array size).float[]The points.The current geometry type. -
Constructor Summary
ConstructorsConstructorDescriptionGeometryBuffer(float[] points, int[] index) Instantiates a new geometry buffer.GeometryBuffer(int numPoints, int numIndices) Instantiates a new geometry buffer.GeometryBuffer(GeometryBuffer buffer) -
Method Summary
Modifier and TypeMethodDescriptionaddPoint(float x, float y) Adds a point with the coordinate x, y.voidAdd aPoint.voidAdd aPointF.floatarea()Calculates geometry area, only polygon outer ring is taken into account.clear()Reset buffer.int[]ensureIndexSize(int size, boolean copy) Ensure index size.float[]ensurePointSize(int size, boolean copy) Ensure that 'points' array can hold the number of points.intGet the number of 2D points.getPoint(int i) voidintGet the used size of points array.floatgetPointX(int i) floatgetPointY(int i) floatbooleanisLine()booleanisPoint()booleanisPoly()booleanisTris()static GeometryBuffermakeCircle(float x, float y, float radius, int segments) static GeometryBuffermakeCircle(GeometryBuffer g, float x, float y, float radius, int segments) voidRemove the last point.voidreverse()Reverse the order of points for lines and polygons.scale(float scaleX, float scaleY) Scale.voidsetPoint(int pos, float x, float y) Sets the point x,y at position pos.voidsimplify(float minSqDist, boolean keepLines) Remove points with distance less than minSqDistvoidStarts a new polygon hole (inner ring).Start a new line.voidSet geometry type for points.Start a new polygon.toString()translate(float dx, float dy) Translate.
-
Field Details
-
points
public float[] pointsThe points.POLY/LINE: store point in order of polygon with points[2 * n + 0] = x; points[2 * n + 1] = y; n is a N.
MESH: store points anywhere with points[3 * n + 0] = x; points[3 * n + 1] = y; points[3 * n + 2] = z; n ∈ ℕ0.
-
index
public int[] indexThe indexes.POLY/LINE: store 2 * number of points of each polygon / line. Point is (x, y).
MESH: store point indices of triangle (p1, p2, p3) with index[3 * n + 0] = p1; index[3 * n + 1] = p2; index[3 * n + 2] = p3; n ∈ ℕ0. Point p is (x, y, z).
-
indexCurrentPos
public int indexCurrentPosThe current index position. -
pointNextPos
public int pointNextPosThe next position to insert a point in points array (equal to array size). -
type
The current geometry type.
-
-
Constructor Details
-
GeometryBuffer
public GeometryBuffer() -
GeometryBuffer
public GeometryBuffer(int numPoints, int numIndices) Instantiates a new geometry buffer.- Parameters:
numPoints- the num of expected 2D pointsnumIndices- the num of expected indices
-
GeometryBuffer
public GeometryBuffer(float[] points, int[] index) Instantiates a new geometry buffer.- Parameters:
points- the pointsindex- the index
-
GeometryBuffer
- Parameters:
buffer- the buffer to copy
-
-
Method Details
-
getPoint
- Parameters:
out- PointF to set coordinates to.i- the 2D point position.
-
getPointX
public float getPointX(int i) - Parameters:
i- the 2D point position.- Returns:
- the x-coordinate of point.
-
getPointY
public float getPointY(int i) - Parameters:
i- the 2D point position.- Returns:
- the y-coordinate of point.
-
getPoint
- Parameters:
i- the 2D point position.- Returns:
- the PointF that belongs to GeometryBuffer.
-
getNumPoints
public int getNumPoints()Get the number of 2D points.- Returns:
- the number of 2D points.
-
getPointsSize
public int getPointsSize()Get the used size of points array. Equal to the next position to insert point in points array.- Returns:
- the size of point array.
-
clear
Reset buffer. -
addPoint
Adds a point with the coordinate x, y.- Parameters:
x- the x ordinatey- the y ordinate
-
isPoly
public boolean isPoly() -
isLine
public boolean isLine() -
isPoint
public boolean isPoint() -
isTris
public boolean isTris() -
setPoint
public void setPoint(int pos, float x, float y) Sets the point x,y at position pos.- Parameters:
pos- the 2D point positionx- the x coordinate (abscissa)y- the y coordinate (ordinate)
-
startPoints
public void startPoints()Set geometry type for points. -
startLine
Start a new line. Sets geometry type for lines. -
startPolygon
Start a new polygon. Sets geometry type for polygons. -
startHole
public void startHole()Starts a new polygon hole (inner ring). -
translate
Translate.- Parameters:
dx- the x translation.dy- the y translation.- Returns:
- a reference to this object.
-
scale
Scale.- Parameters:
scaleX- the x scale.scaleY- the y scale.- Returns:
- a reference to this object.
-
ensurePointSize
public float[] ensurePointSize(int size, boolean copy) Ensure that 'points' array can hold the number of points.- Parameters:
size- the number of points to holdcopy- the current data when array is reallocated- Returns:
- the float[] array holding current coordinates
-
ensureIndexSize
public int[] ensureIndexSize(int size, boolean copy) Ensure index size.- Parameters:
size- the sizecopy- the copy- Returns:
- the short[] array holding current index
-
addPoint
Add aPoint.- Parameters:
p- the point.
-
addPoint
Add aPointF.- Parameters:
p- the point.
-
simplify
public void simplify(float minSqDist, boolean keepLines) Remove points with distance less than minSqDist TODO could avoid superfluous copying- Parameters:
minSqDist-keepLines- keep endpoint when line would otherwise collapse into a single point
-
area
public float area()Calculates geometry area, only polygon outer ring is taken into account.- Returns:
- unsigned polygon area, 0 for other geometries
- See Also:
-
isClockwise
public float isClockwise() -
removeLastPoint
public void removeLastPoint()Remove the last point. -
reverse
public void reverse()Reverse the order of points for lines and polygons. -
toString
-
makeCircle
-
makeCircle
public static GeometryBuffer makeCircle(GeometryBuffer g, float x, float y, float radius, int segments)
-