MapElement: enhance clone (not copy complete buffer) (#451)
This commit is contained in:
parent
e73ac4acfc
commit
535482025e
@ -43,8 +43,12 @@ public class MapElement extends GeometryBuffer {
|
|||||||
super(1024, 16);
|
super(1024, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapElement(int points, int indices) {
|
public MapElement(int numPoints, int numIndices) {
|
||||||
super(points, indices);
|
super(numPoints, numIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapElement(float[] points, int[] index) {
|
||||||
|
super(points, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabelPosition(float x, float y) {
|
public void setLabelPosition(float x, float y) {
|
||||||
@ -73,13 +77,21 @@ public class MapElement extends GeometryBuffer {
|
|||||||
* @return a deep copy of this MapElement
|
* @return a deep copy of this MapElement
|
||||||
*/
|
*/
|
||||||
public MapElement clone() {
|
public MapElement clone() {
|
||||||
MapElement copy = new MapElement();
|
int indexSize = this.indexPos + 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);
|
||||||
|
int[] copyIndex = Arrays.copyOf(this.index, indexSize);
|
||||||
|
|
||||||
|
MapElement copy = new MapElement(copyPoints, copyIndex);
|
||||||
copy.tags.set(this.tags.asArray());
|
copy.tags.set(this.tags.asArray());
|
||||||
copy.points = Arrays.copyOf(this.points, this.points.length);
|
|
||||||
copy.pointPos = this.pointPos;
|
copy.pointPos = this.pointPos;
|
||||||
copy.labelPosition = this.labelPosition;
|
copy.labelPosition = this.labelPosition;
|
||||||
copy.setLayer(this.layer);
|
copy.setLayer(this.layer);
|
||||||
copy.index = Arrays.copyOf(this.index, this.index.length);
|
|
||||||
copy.indexPos = this.indexPos;
|
copy.indexPos = this.indexPos;
|
||||||
copy.type = this.type;
|
copy.type = this.type;
|
||||||
return copy;
|
return copy;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user