use floats in LineClipper

This commit is contained in:
Hannes Janetzek 2013-11-26 13:37:20 +01:00
parent 215d1261ca
commit 104a9c689f
3 changed files with 24 additions and 22 deletions

View File

@ -163,8 +163,8 @@ public class PathLayer extends Layer {
float[] projected = mPPoints; float[] projected = mPPoints;
int i = addPoint(projected, 0, x, y); int i = addPoint(projected, 0, x, y);
int prevX = x; float prevX = x;
int prevY = y; float prevY = y;
for (int j = 2; j < size * 2; j += 2) { for (int j = 2; j < size * 2; j += 2) {
x = (int) ((mPreprojected[j + 0] - mx) * scale); x = (int) ((mPreprojected[j + 0] - mx) * scale);
@ -207,8 +207,8 @@ public class PathLayer extends Layer {
continue; continue;
} }
int dx = x - prevX; float dx = x - prevX;
int dy = y - prevY; float dy = y - prevY;
if ((i == 0) || FastMath.absMaxCmp(dx, dy, MIN_DIST)) { if ((i == 0) || FastMath.absMaxCmp(dx, dy, MIN_DIST)) {
projected[i++] = prevX = x; projected[i++] = prevX = x;
projected[i++] = prevY = y; projected[i++] = prevY = y;

View File

@ -39,16 +39,16 @@ public final class WayDecorator {
// find way segments long enough to draw the way name on them // find way segments long enough to draw the way name on them
for (int i = pos; i < pos + len - 2; i += 2) { for (int i = pos; i < pos + len - 2; i += 2) {
// get the first way point coordinates // get the first way point coordinates
int prevX = (int) coordinates[i + 0]; float prevX = coordinates[i + 0];
int prevY = (int) coordinates[i + 1]; float prevY = coordinates[i + 1];
byte edge = 0; byte edge = 0;
clipper.clipStart(prevX, prevY); clipper.clipStart(prevX, prevY);
// get the current way point coordinates // get the current way point coordinates
int curX = (int) coordinates[i + 2]; float curX = coordinates[i + 2];
int curY = (int) coordinates[i + 3]; float curY = coordinates[i + 3];
int clip; int clip;
if ((clip = clipper.clipNext(curX, curY)) != 0) { if ((clip = clipper.clipNext(curX, curY)) != 0) {
@ -97,8 +97,8 @@ public final class WayDecorator {
// add additional segments if possible // add additional segments if possible
for (int j = i + 4; j < pos + len; j += 2) { for (int j = i + 4; j < pos + len; j += 2) {
int nextX = (int) coordinates[j + 0]; float nextX = coordinates[j + 0];
int nextY = (int) coordinates[j + 1]; float nextY = coordinates[j + 1];
if ((clip = clipper.clipNext(nextX, nextY)) != 0) { if ((clip = clipper.clipNext(nextX, nextY)) != 0) {
if (clip < 0) { if (clip < 0) {

View File

@ -30,7 +30,7 @@ public class LineClipper {
public static final int TOP = 8; // 1000 public static final int TOP = 8; // 1000
private final int xmin, xmax, ymin, ymax; private final int xmin, xmax, ymin, ymax;
public final int[] out; public final float[] out;
public LineClipper(int minx, int miny, int maxx, int maxy) { public LineClipper(int minx, int miny, int maxx, int maxy) {
this.xmin = minx; this.xmin = minx;
@ -46,19 +46,19 @@ public class LineClipper {
this.xmax = maxx; this.xmax = maxx;
this.ymax = maxy; this.ymax = maxy;
if (keepResult) if (keepResult)
this.out = new int[4]; this.out = new float[4];
else else
this.out = null; this.out = null;
} }
private int mPrevOutcode; private int mPrevOutcode;
private int mPrevX; private float mPrevX;
private int mPrevY; private float mPrevY;
public int outX; //public int outX;
public int outY; //public int outY;
public void clipStart(int x0, int y0) { public boolean clipStart(float x0, float y0) {
mPrevX = x0; mPrevX = x0;
mPrevY = y0; mPrevY = y0;
@ -71,6 +71,8 @@ public class LineClipper {
mPrevOutcode |= BOTTOM; mPrevOutcode |= BOTTOM;
else if (y0 > ymax) else if (y0 > ymax)
mPrevOutcode |= TOP; mPrevOutcode |= TOP;
return mPrevOutcode == INSIDE;
} }
/** /**
@ -79,7 +81,7 @@ public class LineClipper {
* @return 0 if not intersection, 1 fully within, -1 clipped (and 'out' set * @return 0 if not intersection, 1 fully within, -1 clipped (and 'out' set
* to new points) * to new points)
*/ */
public int clipNext(int x1, int y1) { public int clipNext(float x1, float y1) {
int accept; int accept;
int outcode = INSIDE; int outcode = INSIDE;
@ -112,8 +114,8 @@ public class LineClipper {
// CohenSutherland clipping algorithm clips a line from // CohenSutherland clipping algorithm clips a line from
// P0 = (x0, y0) to P1 = (x1, y1) against a rectangle with // P0 = (x0, y0) to P1 = (x1, y1) against a rectangle with
// diagonal from (xmin, ymin) to (xmax, ymax). // diagonal from (xmin, ymin) to (xmax, ymax).
private static boolean clip(int x0, int y0, int x1, int y1, private static boolean clip(float x0, float y0, float x1, float y1,
int xmin, int ymin, int xmax, int ymax, int outcode0, int outcode1, int[] out) { int xmin, int ymin, int xmax, int ymax, int outcode0, int outcode1, float[] out) {
boolean accept = false; boolean accept = false;
@ -128,8 +130,8 @@ public class LineClipper {
} else { } else {
// failed both tests, so calculate the line segment to clip // failed both tests, so calculate the line segment to clip
// from an outside point to an intersection with clip edge // from an outside point to an intersection with clip edge
int x = 0; float x = 0;
int y = 0; float y = 0;
// At least one endpoint is outside the clip rectangle; pick it. // At least one endpoint is outside the clip rectangle; pick it.
int outcodeOut = (outcode0 == 0) ? outcode1 : outcode0; int outcodeOut = (outcode0 == 0) ? outcode1 : outcode0;