GeometryBuffer: (#453)
+ renamed buffer positions + update docs + expand toString for meshes/tris
This commit is contained in:
parent
72b72b8029
commit
e3b137e3c4
@ -269,8 +269,8 @@ public class GeoJsonTileDecoder implements ITileDecoder {
|
||||
}
|
||||
|
||||
private void removeLastPoint() {
|
||||
mMapElement.pointPos -= 2;
|
||||
mMapElement.index[mMapElement.indexPos] -= 2;
|
||||
mMapElement.pointNextPos -= 2;
|
||||
mMapElement.index[mMapElement.indexCurrentPos] -= 2;
|
||||
}
|
||||
|
||||
private void parseLineString(JsonParser jp)
|
||||
|
@ -484,8 +484,8 @@ public class TileDecoder extends PbfDecoder {
|
||||
|
||||
// only add last point if it is di
|
||||
int ppos = cnt * 2;
|
||||
if (elem.points[elem.pointPos - ppos] != curX
|
||||
|| elem.points[elem.pointPos - ppos + 1] != curY)
|
||||
if (elem.points[elem.pointNextPos - ppos] != curX
|
||||
|| elem.points[elem.pointNextPos - ppos + 1] != curY)
|
||||
elem.addPoint(curX / mScale, curY / mScale);
|
||||
|
||||
lastClip = false;
|
||||
@ -525,10 +525,10 @@ public class TileDecoder extends PbfDecoder {
|
||||
if (isPoly && isOuter && simplify && !testBBox(xmax - xmin, ymax - ymin)) {
|
||||
//log.debug("skip small poly "+ elem.indexPos + " > "
|
||||
// + (xmax - xmin) * (ymax - ymin));
|
||||
elem.pointPos -= elem.index[elem.indexPos];
|
||||
if (elem.indexPos > 0) {
|
||||
elem.indexPos -= 2;
|
||||
elem.index[elem.indexPos + 1] = -1;
|
||||
elem.pointNextPos -= elem.index[elem.indexCurrentPos];
|
||||
if (elem.indexCurrentPos > 0) {
|
||||
elem.indexCurrentPos -= 2;
|
||||
elem.index[elem.indexCurrentPos + 1] = -1;
|
||||
} else {
|
||||
elem.type = GeometryType.NONE;
|
||||
}
|
||||
|
@ -266,8 +266,8 @@ public class TileDecoder implements ITileDecoder {
|
||||
}
|
||||
|
||||
private void removeLastPoint() {
|
||||
mMapElement.pointPos -= 2;
|
||||
mMapElement.index[mMapElement.indexPos] -= 2;
|
||||
mMapElement.pointNextPos -= 2;
|
||||
mMapElement.index[mMapElement.indexCurrentPos] -= 2;
|
||||
}
|
||||
|
||||
private void parseLineString(JsonParser jp) throws IOException {
|
||||
|
@ -56,23 +56,35 @@ public class GeometryBuffer {
|
||||
|
||||
/**
|
||||
* The points.
|
||||
* <p>
|
||||
* POLY/LINE: store point in order of polygon with
|
||||
* points[2 * n + 0] = x; points[2 * n + 1] = y; n is a N.
|
||||
* <p>
|
||||
* MESH: store points anywhere with
|
||||
* points[3 * n + 0] = x; points[3 * n + 1] = y; points[3 * n + 2] = z; n ∈ ℕ0.
|
||||
*/
|
||||
public float[] points;
|
||||
|
||||
/**
|
||||
* The indexes.
|
||||
* <p>
|
||||
* POLY/LINE: store 2 * number of points of each polygon / line. Point is (x, y).
|
||||
* <p>
|
||||
* 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).
|
||||
*/
|
||||
public int[] index;
|
||||
|
||||
/**
|
||||
* The current index position.
|
||||
*/
|
||||
public int indexPos;
|
||||
public int indexCurrentPos;
|
||||
|
||||
/**
|
||||
* The current position in points array.
|
||||
* The next position to insert a point in points array (equal to array size).
|
||||
*/
|
||||
public int pointPos;
|
||||
public int pointNextPos;
|
||||
|
||||
/**
|
||||
* The current geometry type.
|
||||
@ -111,8 +123,8 @@ public class GeometryBuffer {
|
||||
this.points = points;
|
||||
this.index = index;
|
||||
this.type = GeometryType.NONE;
|
||||
this.indexPos = 0;
|
||||
this.pointPos = 0;
|
||||
this.indexCurrentPos = 0;
|
||||
this.pointNextPos = 0;
|
||||
this.pointLimit = points.length - 2;
|
||||
}
|
||||
|
||||
@ -145,7 +157,7 @@ public class GeometryBuffer {
|
||||
}
|
||||
|
||||
public int getNumPoints() {
|
||||
return pointPos >> 1;
|
||||
return pointNextPos >> 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,8 +165,8 @@ public class GeometryBuffer {
|
||||
*/
|
||||
public GeometryBuffer clear() {
|
||||
index[0] = 0;
|
||||
indexPos = 0;
|
||||
pointPos = 0;
|
||||
indexCurrentPos = 0;
|
||||
pointNextPos = 0;
|
||||
type = GeometryType.NONE;
|
||||
return this;
|
||||
}
|
||||
@ -166,13 +178,13 @@ public class GeometryBuffer {
|
||||
* @param y the y ordinate
|
||||
*/
|
||||
public GeometryBuffer addPoint(float x, float y) {
|
||||
if (pointPos > pointLimit)
|
||||
ensurePointSize((pointPos >> 1) + 1, true);
|
||||
if (pointNextPos > pointLimit)
|
||||
ensurePointSize((pointNextPos >> 1) + 1, true);
|
||||
|
||||
points[pointPos++] = x;
|
||||
points[pointPos++] = y;
|
||||
points[pointNextPos++] = x;
|
||||
points[pointNextPos++] = y;
|
||||
|
||||
index[indexPos] += 2;
|
||||
index[indexCurrentPos] += 2;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -188,6 +200,10 @@ public class GeometryBuffer {
|
||||
return type == GeometryType.POINT;
|
||||
}
|
||||
|
||||
public boolean isTris() {
|
||||
return type == GeometryType.TRIS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the point x,y at position pos.
|
||||
*
|
||||
@ -214,19 +230,19 @@ public class GeometryBuffer {
|
||||
setOrCheckMode(GeometryType.LINE);
|
||||
|
||||
/* ignore */
|
||||
if (index[indexPos] > 0) {
|
||||
if (index[indexCurrentPos] > 0) {
|
||||
|
||||
/* start next */
|
||||
if ((index[0] >= 0) && (++indexPos >= index.length))
|
||||
ensureIndexSize(indexPos, true);
|
||||
if ((index[0] >= 0) && (++indexCurrentPos >= index.length))
|
||||
ensureIndexSize(indexCurrentPos, true);
|
||||
|
||||
/* initialize with zero points */
|
||||
index[indexPos] = 0;
|
||||
index[indexCurrentPos] = 0;
|
||||
}
|
||||
|
||||
/* set new end marker */
|
||||
if (index.length > indexPos + 1)
|
||||
index[indexPos + 1] = -1;
|
||||
if (index.length > indexCurrentPos + 1)
|
||||
index[indexCurrentPos + 1] = -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -237,23 +253,23 @@ public class GeometryBuffer {
|
||||
boolean start = (type == GeometryType.NONE);
|
||||
setOrCheckMode(GeometryType.POLY);
|
||||
|
||||
if ((indexPos + 3) > index.length)
|
||||
ensureIndexSize(indexPos + 2, true);
|
||||
if ((indexCurrentPos + 3) > index.length)
|
||||
ensureIndexSize(indexCurrentPos + 2, true);
|
||||
|
||||
if (!start && index[indexPos] != 0) {
|
||||
if (!start && index[indexCurrentPos] != 0) {
|
||||
/* end polygon */
|
||||
index[++indexPos] = 0;
|
||||
index[++indexCurrentPos] = 0;
|
||||
|
||||
/* next polygon start */
|
||||
indexPos++;
|
||||
indexCurrentPos++;
|
||||
}
|
||||
|
||||
/* initialize with zero points */
|
||||
index[indexPos] = 0;
|
||||
index[indexCurrentPos] = 0;
|
||||
|
||||
/* set new end marker */
|
||||
if (index.length > indexPos + 1)
|
||||
index[indexPos + 1] = -1;
|
||||
if (index.length > indexCurrentPos + 1)
|
||||
index[indexCurrentPos + 1] = -1;
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -264,19 +280,19 @@ public class GeometryBuffer {
|
||||
public void startHole() {
|
||||
checkMode(GeometryType.POLY);
|
||||
|
||||
if ((indexPos + 2) > index.length)
|
||||
ensureIndexSize(indexPos + 1, true);
|
||||
if ((indexCurrentPos + 2) > index.length)
|
||||
ensureIndexSize(indexCurrentPos + 1, true);
|
||||
|
||||
/* initialize with zero points */
|
||||
index[++indexPos] = 0;
|
||||
index[++indexCurrentPos] = 0;
|
||||
|
||||
/* set new end marker */
|
||||
if (index.length > indexPos + 1)
|
||||
index[indexPos + 1] = -1;
|
||||
if (index.length > indexCurrentPos + 1)
|
||||
index[indexCurrentPos + 1] = -1;
|
||||
}
|
||||
|
||||
public GeometryBuffer translate(float dx, float dy) {
|
||||
for (int i = 0; i < pointPos; i += 2) {
|
||||
for (int i = 0; i < pointNextPos; i += 2) {
|
||||
points[i] += dx;
|
||||
points[i + 1] += dy;
|
||||
}
|
||||
@ -284,7 +300,7 @@ public class GeometryBuffer {
|
||||
}
|
||||
|
||||
public GeometryBuffer scale(float scaleX, float scaleY) {
|
||||
for (int i = 0; i < pointPos; i += 2) {
|
||||
for (int i = 0; i < pointNextPos; i += 2) {
|
||||
points[i] *= scaleX;
|
||||
points[i + 1] *= scaleY;
|
||||
}
|
||||
@ -439,24 +455,43 @@ public class GeometryBuffer {
|
||||
for (int i = 0; i < index.length; i++) {
|
||||
if (index[i] < 0)
|
||||
break;
|
||||
if (index[i] == 0)
|
||||
continue;
|
||||
sb.append(":");
|
||||
sb.append(index[i]);
|
||||
sb.append('\n');
|
||||
|
||||
for (int j = 0; j < index[i]; j += 2) {
|
||||
sb.append('[')
|
||||
.append(points[o + j])
|
||||
.append(',')
|
||||
.append(points[o + j + 1])
|
||||
if (!isTris()) {
|
||||
if (index[i] == 0)
|
||||
continue;
|
||||
sb.append("POLY (")
|
||||
.append(i)
|
||||
.append(") { ");
|
||||
|
||||
for (int j = 0; j < index[i]; j += 2) {
|
||||
sb.append('[')
|
||||
.append(points[o + j])
|
||||
.append(", ")
|
||||
.append(points[o + j + 1])
|
||||
.append(']');
|
||||
|
||||
if (j % 4 == 0)
|
||||
sb.append('\n');
|
||||
}
|
||||
sb.append(" } \tnumPoints:")
|
||||
.append(index[i])
|
||||
.append('\n');
|
||||
o += index[i];
|
||||
} else {
|
||||
if (i % 3 == 0)
|
||||
sb.append("TRIS { ");
|
||||
sb.append('\t')
|
||||
.append(index[i])
|
||||
.append('[')
|
||||
.append(points[3 * index[i]])
|
||||
.append(", ")
|
||||
.append(points[3 * index[i] + 1])
|
||||
.append(", ")
|
||||
.append(points[3 * index[i] + 2])
|
||||
.append(']');
|
||||
|
||||
if (j % 4 == 0)
|
||||
sb.append('\n');
|
||||
if (i % 3 == 2)
|
||||
sb.append(" }\n");
|
||||
}
|
||||
sb.append('\n');
|
||||
o += index[i];
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -77,22 +77,22 @@ public class MapElement extends GeometryBuffer {
|
||||
* @return a deep copy of this MapElement
|
||||
*/
|
||||
public MapElement clone() {
|
||||
int indexSize = this.indexPos + 1;
|
||||
int indexSize = this.indexCurrentPos + 1;
|
||||
for (int i = 0; i < this.index.length; i++) {
|
||||
if (this.index[i] == -1) {
|
||||
indexSize = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
float[] copyPoints = Arrays.copyOf(this.points, this.pointPos);
|
||||
float[] copyPoints = Arrays.copyOf(this.points, this.pointNextPos);
|
||||
int[] copyIndex = Arrays.copyOf(this.index, indexSize);
|
||||
|
||||
MapElement copy = new MapElement(copyPoints, copyIndex);
|
||||
copy.tags.set(this.tags.asArray());
|
||||
copy.pointPos = this.pointPos;
|
||||
copy.pointNextPos = this.pointNextPos;
|
||||
copy.labelPosition = this.labelPosition;
|
||||
copy.setLayer(this.layer);
|
||||
copy.indexPos = this.indexPos;
|
||||
copy.indexCurrentPos = this.indexCurrentPos;
|
||||
copy.type = this.type;
|
||||
return copy;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class MeshBucket extends RenderBucket {
|
||||
}
|
||||
|
||||
public void addMesh(GeometryBuffer geom) {
|
||||
numPoints += geom.pointPos;
|
||||
numPoints += geom.pointNextPos;
|
||||
if (tess == null)
|
||||
tess = new TessJNI(8);
|
||||
|
||||
|
@ -244,7 +244,7 @@ public abstract class PbfDecoder implements ITileDecoder {
|
||||
|
||||
bufferPos = pos;
|
||||
|
||||
geom.pointPos = cnt;
|
||||
geom.pointNextPos = cnt;
|
||||
|
||||
// return number of points read
|
||||
return (cnt >> 1);
|
||||
|
@ -723,8 +723,8 @@ public class MapDatabase implements ITileDataSource {
|
||||
int[] buffer = mIntBuffer;
|
||||
mReadBuffer.readSignedInt(buffer, length);
|
||||
|
||||
float[] outBuffer = e.ensurePointSize(e.pointPos + length, true);
|
||||
int outPos = e.pointPos;
|
||||
float[] outBuffer = e.ensurePointSize(e.pointNextPos + length, true);
|
||||
int outPos = e.pointNextPos;
|
||||
int lat, lon;
|
||||
|
||||
/* first node latitude single-delta offset */
|
||||
@ -772,7 +772,7 @@ public class MapDatabase implements ITileDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
e.pointPos = outPos;
|
||||
e.pointNextPos = outPos;
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ public class TileDecoder extends PbfDecoder {
|
||||
Integer.valueOf(cnt));
|
||||
fail = true;
|
||||
}
|
||||
mElem.pointPos = cnt;
|
||||
mElem.pointNextPos = cnt;
|
||||
} else {
|
||||
mElem.ensurePointSize(coordCnt, false);
|
||||
int cnt = decodeInterleavedPoints(mElem, mScaleFactor);
|
||||
|
@ -54,12 +54,12 @@ public class SimplifyVW {
|
||||
|
||||
size = 0;
|
||||
|
||||
if (heap.length < geom.pointPos >> 1)
|
||||
heap = new Item[geom.pointPos >> 1];
|
||||
if (heap.length < geom.pointNextPos >> 1)
|
||||
heap = new Item[geom.pointNextPos >> 1];
|
||||
|
||||
first = prev = push(0, Float.MAX_VALUE);
|
||||
|
||||
for (int i = 2; i < geom.pointPos - 2; i += 2) {
|
||||
for (int i = 2; i < geom.pointNextPos - 2; i += 2) {
|
||||
it = push(i, area(geom.points, i - 2, i, i + 2));
|
||||
prev.next = it;
|
||||
it.prev = prev;
|
||||
@ -67,7 +67,7 @@ public class SimplifyVW {
|
||||
prev = it;
|
||||
}
|
||||
|
||||
Item last = push(geom.pointPos - 2, Float.MAX_VALUE);
|
||||
Item last = push(geom.pointNextPos - 2, Float.MAX_VALUE);
|
||||
|
||||
// sorter.doSort(heap, DistanceComparator, 0, size);
|
||||
// for (int i = 0; i < size; i++)
|
||||
@ -102,8 +102,8 @@ public class SimplifyVW {
|
||||
first.prev = null;
|
||||
it = first;
|
||||
|
||||
float[] points = new float[geom.pointPos];
|
||||
System.arraycopy(geom.points, 0, points, 0, geom.pointPos);
|
||||
float[] points = new float[geom.pointNextPos];
|
||||
System.arraycopy(geom.points, 0, points, 0, geom.pointNextPos);
|
||||
|
||||
geom.clear();
|
||||
geom.startPolygon();
|
||||
|
@ -68,7 +68,7 @@ public class TileClipper {
|
||||
|
||||
clipEdge(out, geom, LineClipper.BOTTOM);
|
||||
|
||||
if ((geom.indexPos == 0) && (geom.index[0] < 6))
|
||||
if ((geom.indexCurrentPos == 0) && (geom.index[0] < 6))
|
||||
return false;
|
||||
} else if (geom.isLine()) {
|
||||
|
||||
@ -81,12 +81,12 @@ public class TileClipper {
|
||||
System.arraycopy(out.index, 0, idx, 0, numLines);
|
||||
geom.index[numLines] = -1;
|
||||
|
||||
float pts[] = geom.ensurePointSize(out.pointPos >> 1, false);
|
||||
System.arraycopy(out.points, 0, pts, 0, out.pointPos);
|
||||
geom.indexPos = out.indexPos;
|
||||
geom.pointPos = out.pointPos;
|
||||
float pts[] = geom.ensurePointSize(out.pointNextPos >> 1, false);
|
||||
System.arraycopy(out.points, 0, pts, 0, out.pointNextPos);
|
||||
geom.indexCurrentPos = out.indexCurrentPos;
|
||||
geom.pointNextPos = out.pointNextPos;
|
||||
|
||||
if ((geom.indexPos == 0) && (geom.index[0] < 4))
|
||||
if ((geom.indexCurrentPos == 0) && (geom.index[0] < 4))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user