GeometryBuffer:
- add getPoint(i, point) - addPoint(PointF) - getPointX/Y GeomBuffer: api
This commit is contained in:
parent
d6cf845fef
commit
7be8155939
@ -16,11 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.core;
|
package org.oscim.core;
|
||||||
|
|
||||||
// TODO
|
/* TODO
|
||||||
// - getter methods!
|
* - check indexPos < Short.Max
|
||||||
// - check indexPos < Short.Max
|
* - should make internals private, maybe
|
||||||
// - should make internals private, maybe
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The GeometryBuffer class holds temporary geometry data for processing.
|
* The GeometryBuffer class holds temporary geometry data for processing.
|
||||||
* Only One geometry type can be set at a time. Use 'clear()' to reset the
|
* Only One geometry type can be set at a time. Use 'clear()' to reset the
|
||||||
@ -91,10 +90,32 @@ public class GeometryBuffer {
|
|||||||
this.pointLimit = points.length - 2;
|
this.pointLimit = points.length - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param out PointF to set coordinates to.
|
||||||
|
* @return when out is null a temporary PointF is
|
||||||
|
* returned which belongs to GeometryBuffer.
|
||||||
|
*/
|
||||||
|
public void getPoint(int i, PointF out) {
|
||||||
|
out.x = points[(i << 1)];
|
||||||
|
out.y = points[(i << 1) + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPointX(int i) {
|
||||||
|
return points[(i << 1)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPointY(int i) {
|
||||||
|
return points[(i << 1) + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PointF belongs to GeometryBuffer.
|
||||||
|
*/
|
||||||
public PointF getPoint(int i) {
|
public PointF getPoint(int i) {
|
||||||
mTmpPoint.x = points[(i << 1)];
|
PointF out = mTmpPoint;
|
||||||
mTmpPoint.y = points[(i << 1) + 1];
|
out.x = points[(i << 1)];
|
||||||
return mTmpPoint;
|
out.y = points[(i << 1) + 1];
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumPoints() {
|
public int getNumPoints() {
|
||||||
@ -111,7 +132,6 @@ public class GeometryBuffer {
|
|||||||
this(new float[numPoints * 2], new short[numIndices]);
|
this(new float[numPoints * 2], new short[numIndices]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- API ----
|
|
||||||
/**
|
/**
|
||||||
* Reset buffer.
|
* Reset buffer.
|
||||||
*/
|
*/
|
||||||
@ -176,18 +196,18 @@ public class GeometryBuffer {
|
|||||||
public GeometryBuffer startLine() {
|
public GeometryBuffer startLine() {
|
||||||
setOrCheckMode(GeometryType.LINE);
|
setOrCheckMode(GeometryType.LINE);
|
||||||
|
|
||||||
// ignore
|
/* ignore */
|
||||||
if (index[indexPos] > 0) {
|
if (index[indexPos] > 0) {
|
||||||
|
|
||||||
// start next
|
/* start next */
|
||||||
if ((index[0] >= 0) && (++indexPos >= index.length))
|
if ((index[0] >= 0) && (++indexPos >= index.length))
|
||||||
ensureIndexSize(indexPos, true);
|
ensureIndexSize(indexPos, true);
|
||||||
|
|
||||||
// initialize with zero points
|
/* initialize with zero points */
|
||||||
index[indexPos] = 0;
|
index[indexPos] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set new end marker
|
/* set new end marker */
|
||||||
if (index.length > indexPos + 1)
|
if (index.length > indexPos + 1)
|
||||||
index[indexPos + 1] = -1;
|
index[indexPos + 1] = -1;
|
||||||
return this;
|
return this;
|
||||||
@ -204,17 +224,17 @@ public class GeometryBuffer {
|
|||||||
ensureIndexSize(indexPos + 2, true);
|
ensureIndexSize(indexPos + 2, true);
|
||||||
|
|
||||||
if (!start && index[indexPos] != 0) {
|
if (!start && index[indexPos] != 0) {
|
||||||
// end polygon
|
/* end polygon */
|
||||||
index[++indexPos] = 0;
|
index[++indexPos] = 0;
|
||||||
|
|
||||||
// next polygon start
|
/* next polygon start */
|
||||||
indexPos++;
|
indexPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize with zero points
|
/* initialize with zero points */
|
||||||
index[indexPos] = 0;
|
index[indexPos] = 0;
|
||||||
|
|
||||||
// set new end marker
|
/* set new end marker */
|
||||||
if (index.length > indexPos + 1)
|
if (index.length > indexPos + 1)
|
||||||
index[indexPos + 1] = -1;
|
index[indexPos + 1] = -1;
|
||||||
|
|
||||||
@ -230,10 +250,10 @@ public class GeometryBuffer {
|
|||||||
if ((indexPos + 2) > index.length)
|
if ((indexPos + 2) > index.length)
|
||||||
ensureIndexSize(indexPos + 1, true);
|
ensureIndexSize(indexPos + 1, true);
|
||||||
|
|
||||||
// initialize with zero points
|
/* initialize with zero points */
|
||||||
index[++indexPos] = 0;
|
index[++indexPos] = 0;
|
||||||
|
|
||||||
// set new end marker
|
/* set new end marker */
|
||||||
if (index.length > indexPos + 1)
|
if (index.length > indexPos + 1)
|
||||||
index[indexPos + 1] = -1;
|
index[indexPos + 1] = -1;
|
||||||
}
|
}
|
||||||
@ -316,6 +336,10 @@ public class GeometryBuffer {
|
|||||||
addPoint((float) p.x, (float) p.y);
|
addPoint((float) p.x, (float) p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPoint(PointF p) {
|
||||||
|
addPoint(p.x, p.y);
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
int o = 0;
|
int o = 0;
|
||||||
@ -324,6 +348,9 @@ public class GeometryBuffer {
|
|||||||
break;
|
break;
|
||||||
if (index[i] == 0)
|
if (index[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
sb.append(":");
|
||||||
|
sb.append(index[i]);
|
||||||
|
sb.append('\n');
|
||||||
|
|
||||||
for (int j = 0; j < index[i]; j += 2) {
|
for (int j = 0; j < index[i]; j += 2) {
|
||||||
sb.append('[')
|
sb.append('[')
|
||||||
@ -331,6 +358,9 @@ public class GeometryBuffer {
|
|||||||
.append(',')
|
.append(',')
|
||||||
.append(points[o + j + 1])
|
.append(points[o + j + 1])
|
||||||
.append(']');
|
.append(']');
|
||||||
|
|
||||||
|
if (j % 4 == 0)
|
||||||
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
o += index[i];
|
o += index[i];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user