Class GeometryBuffer

java.lang.Object
org.oscim.core.GeometryBuffer
Direct Known Subclasses:
MapElement

public class GeometryBuffer extends Object
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.

  • Field Details

    • points

      public float[] points
      The 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[] index
      The 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 indexCurrentPos
      The current index position.
    • pointNextPos

      public int pointNextPos
      The 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 points
      numIndices - the num of expected indices
    • GeometryBuffer

      public GeometryBuffer(float[] points, int[] index)
      Instantiates a new geometry buffer.
      Parameters:
      points - the points
      index - the index
    • GeometryBuffer

      public GeometryBuffer(GeometryBuffer buffer)
      Parameters:
      buffer - the buffer to copy
  • Method Details

    • getPoint

      public void getPoint(int i, PointF out)
      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

      public PointF getPoint(int i)
      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

      public GeometryBuffer clear()
      Reset buffer.
    • addPoint

      public GeometryBuffer addPoint(float x, float y)
      Adds a point with the coordinate x, y.
      Parameters:
      x - the x ordinate
      y - 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 position
      x - the x coordinate (abscissa)
      y - the y coordinate (ordinate)
    • startPoints

      public void startPoints()
      Set geometry type for points.
    • startLine

      public GeometryBuffer startLine()
      Start a new line. Sets geometry type for lines.
    • startPolygon

      public GeometryBuffer startPolygon()
      Start a new polygon. Sets geometry type for polygons.
    • startHole

      public void startHole()
      Starts a new polygon hole (inner ring).
    • translate

      public GeometryBuffer translate(float dx, float dy)
      Translate.
      Parameters:
      dx - the x translation.
      dy - the y translation.
      Returns:
      a reference to this object.
    • scale

      public GeometryBuffer scale(float scaleX, float scaleY)
      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 hold
      copy - 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 size
      copy - the copy
      Returns:
      the short[] array holding current index
    • addPoint

      public void addPoint(Point p)
      Add a Point.
      Parameters:
      p - the point.
    • addPoint

      public void addPoint(PointF p)
      Add a PointF.
      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

      public String toString()
      Overrides:
      toString in class Object
    • makeCircle

      public static GeometryBuffer makeCircle(float x, float y, float radius, int segments)
    • makeCircle

      public static GeometryBuffer makeCircle(GeometryBuffer g, float x, float y, float radius, int segments)