API: GeometryBuffer add getNumPoints(), getPoint():PointF

- ignore start of new geometry when the current is empty
This commit is contained in:
Hannes Janetzek 2013-09-19 23:44:54 +02:00
parent 1a4e3b4c7c
commit 949ebb5d8e
2 changed files with 67 additions and 6 deletions

View File

@ -21,6 +21,8 @@ public class GeometryBuffer {
private final static int GROW_INDICES = 64; private final static int GROW_INDICES = 64;
private final static int GROW_POINTS = 512; private final static int GROW_POINTS = 512;
private PointF mTmpPoint = new PointF();
/** /**
* The Enum GeometryType. * The Enum GeometryType.
*/ */
@ -72,6 +74,16 @@ public class GeometryBuffer {
this.pointPos = 0; this.pointPos = 0;
} }
public PointF getPoint(int i) {
mTmpPoint.x = points[(i << 1)];
mTmpPoint.y = points[(i << 1) + 1];
return mTmpPoint;
}
public int getNumPoints() {
return index[0] >> 1;
}
/** /**
* Instantiates a new geometry buffer. * Instantiates a new geometry buffer.
* *
@ -146,6 +158,10 @@ public class GeometryBuffer {
public void startLine() { public void startLine() {
setOrCheckMode(GeometryType.LINE); setOrCheckMode(GeometryType.LINE);
// ignore
if (index[indexPos] == 0)
return;
// start next // start next
if ((index[0] >= 0) && (++indexPos >= index.length)) if ((index[0] >= 0) && (++indexPos >= index.length))
ensureIndexSize(indexPos, true); ensureIndexSize(indexPos, true);
@ -165,6 +181,10 @@ public class GeometryBuffer {
boolean start = (type == GeometryType.NONE); boolean start = (type == GeometryType.NONE);
setOrCheckMode(GeometryType.POLY); setOrCheckMode(GeometryType.POLY);
// ignore
if (index[indexPos] == 0)
return;
if ((indexPos + 3) > index.length) if ((indexPos + 3) > index.length)
ensureIndexSize(indexPos + 2, true); ensureIndexSize(indexPos + 2, true);

View File

@ -0,0 +1,41 @@
/*
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.core;
public class PointF {
public float x;
public float y;
public PointF() {
}
public PointF(float x, float y) {
this.x = x;
this.y = y;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
@Override
public String toString() {
return x + " " + y;
}
}