add LineLayer.setDropDistance() for point reduction by distance

This commit is contained in:
Hannes Janetzek 2014-02-07 14:13:20 +01:00
parent e80eae230c
commit 91d99c0efb

View File

@ -33,23 +33,31 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
*
* Note:
* Coordinates must be in range [-4096..4096] and the maximum
* resolution for coordinates is 0.25 as points will be converted
* to fixed point values.
*/ */
public final class LineLayer extends RenderElement { public final class LineLayer extends RenderElement {
static final Logger log = LoggerFactory.getLogger(LineLayer.class); static final Logger log = LoggerFactory.getLogger(LineLayer.class);
private static final float COORD_SCALE = MapRenderer.COORD_SCALE; private static final float COORD_SCALE = MapRenderer.COORD_SCALE;
// scale factor mapping extrusion vector to short values /** scale factor mapping extrusion vector to short values */
public static final float DIR_SCALE = 2048; public static final float DIR_SCALE = 2048;
// mask for packing last two bits of extrusion vector with texture /**
// coordinates * mask for packing last two bits of extrusion vector with texture
* coordinates
*/
private static final int DIR_MASK = 0xFFFFFFFC; private static final int DIR_MASK = 0xFFFFFFFC;
// lines referenced by this outline layer /* lines referenced by this outline layer */
public LineLayer outlines; public LineLayer outlines;
public Line line; public Line line;
public float width; public float width;
public boolean roundCap; public boolean roundCap;
private float mMinDist = 1 / 4f;
LineLayer(int layer) { LineLayer(int layer) {
super(RenderElement.LINE); super(RenderElement.LINE);
@ -65,6 +73,13 @@ public final class LineLayer extends RenderElement {
outlines = link; outlines = link;
} }
/**
* For point reduction by minimal distance. Default is 1/4.
*/
public void setDropDistance(float minDist) {
mMinDist = minDist < 1 / 4f ? 1 / 4f : minDist;
}
public void addLine(GeometryBuffer geom) { public void addLine(GeometryBuffer geom) {
if (geom.isPoly()) if (geom.isPoly())
addLine(geom.points, geom.index, -1, true); addLine(geom.points, geom.index, -1, true);
@ -101,12 +116,10 @@ public final class LineLayer extends RenderElement {
short v[] = si.vertices; short v[] = si.vertices;
int opos = si.used; int opos = si.used;
// FIXME: remove this when switching to oscimap MapDatabase /*
//if (!MapView.enableClosePolygons) * Note: just a hack to save some vertices, when there are
// closed = false; * more than 200 lines per type. FIXME make optional!
*/
// Note: just a hack to save some vertices, when there are more than 200 lines
// per type
if (rounded && index != null) { if (rounded && index != null) {
int cnt = 0; int cnt = 0;
for (int i = 0, n = index.length; i < n; i++, cnt++) { for (int i = 0, n = index.length; i < n; i++, cnt++) {
@ -340,7 +353,7 @@ public final class LineLayer extends RenderElement {
wy = nextY - y; wy = nextY - y;
a = (float) Math.sqrt(wx * wx + wy * wy); a = (float) Math.sqrt(wx * wx + wy * wy);
// skip too short segmets // skip too short segmets
if (a < 1) { if (a < mMinDist) {
numVertices -= 2; numVertices -= 2;
continue; continue;
} }