fix multipolygons

git-svn-id: https://osmand.googlecode.com/svn/trunk@876 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2011-01-09 01:09:59 +00:00
parent 8c8cc3b266
commit b6c9e20be2

View file

@ -677,8 +677,6 @@ public class MapRenderRepositories {
int x = (int) (i.get(i.size() - 1) >> 32);
int y = (int) (i.get(i.size() - 1) & mask);
x = (int) (i.get(4) >> 32);
y = (int) (i.get(4) & mask);
// 31 - (zoom + 8)
int EVAL_DELTA = 6 << (23 - zoom);
int UNDEFINED_MIN_DIFF = -1 - EVAL_DELTA;
@ -786,48 +784,85 @@ public class MapRenderRepositories {
/**
* @return -1 if there is no instersection or x<<32 | y
*/
private long calculateIntersection(int x, int y, boolean pinside, int px, int py, int leftX, int rightX,
private long calculateIntersection(int x, int y, int px, int py, int leftX, int rightX,
int bottomY, int topY){
int by = -1;
int bx = -1;
if (by == -1 && py < topY && y >= topY) {
// firstly try to search if the line goes in
if (py < topY && y >= topY) {
int tx = (int) (px + ((double) (x - px) * (topY - py)) / (y - py));
if (leftX <= tx && tx <= rightX) {
bx = tx;
by = topY;
return (((long) bx) << 32) | ((long) by);
}
}
if (by == -1 && py > bottomY && y <= bottomY) {
if (py > bottomY && y <= bottomY) {
int tx = (int) (px + ((double) (x - px) * (py - bottomY)) / (py - y));
if (leftX <= tx && tx <= rightX) {
bx = tx;
by = bottomY;
return (((long) bx) << 32) | ((long) by);
}
}
if (by == -1 && px < leftX && x >= leftX) {
if (px < leftX && x >= leftX) {
int ty = (int) (py + ((double) (y - py) * (leftX - px)) / (x - px));
if (ty >= topY && ty <= bottomY) {
by = ty;
bx = leftX;
return (((long) bx) << 32) | ((long) by);
}
}
if (by == -1 && px > rightX && x <= rightX) {
if (px > rightX && x <= rightX) {
int ty = (int) (py + ((double) (y - py) * (px - rightX)) / (px - x));
if (ty >= topY && ty <= bottomY) {
by = ty;
bx = rightX;
return (((long) bx) << 32) | ((long) by);
}
}
if(by == -1){
if(px == rightX || px == leftX || py == topY || py == bottomY){
bx = px;
by = py;
// try to search if point goes out
if (py > topY && y <= topY) {
int tx = (int) (px + ((double) (x - px) * (topY - py)) / (y - py));
if (leftX <= tx && tx <= rightX) {
bx = tx;
by = topY;
return (((long) bx) << 32) | ((long) by);
}
}
if (by != -1) {
return (((long) bx) << 32) | ((long) by);
if (py < bottomY && y >= bottomY) {
int tx = (int) (px + ((double) (x - px) * (py - bottomY)) / (py - y));
if (leftX <= tx && tx <= rightX) {
bx = tx;
by = bottomY;
return (((long) bx) << 32) | ((long) by);
}
}
if (px > leftX && x <= leftX) {
int ty = (int) (py + ((double) (y - py) * (leftX - px)) / (x - px));
if (ty >= topY && ty <= bottomY) {
by = ty;
bx = leftX;
return (((long) bx) << 32) | ((long) by);
}
}
if (px < rightX && x >= rightX) {
int ty = (int) (py + ((double) (y - py) * (px - rightX)) / (px - x));
if (ty >= topY && ty <= bottomY) {
by = ty;
bx = rightX;
return (((long) bx) << 32) | ((long) by);
}
}
if(px == rightX || px == leftX || py == topY || py == bottomY){
bx = px;
by = py;
}
return -1l;
}
@ -837,7 +872,7 @@ public class MapRenderRepositories {
boolean lineEnded = false;
if (pinside) {
if (!inside) {
long is = calculateIntersection(x, y, pinside, px, py, leftX, rightX, bottomY, topY);
long is = calculateIntersection(x, y, px, py, leftX, rightX, bottomY, topY);
if (is == -1) {
// it is an error (!)
is = (((long) px) << 32) | ((long) py);
@ -848,7 +883,7 @@ public class MapRenderRepositories {
coordinates.add((((long) x) << 32) | ((long) y));
}
} else {
long is = calculateIntersection(x, y, pinside, px, py, leftX, rightX, bottomY, topY);
long is = calculateIntersection(x, y, px, py, leftX, rightX, bottomY, topY);
if(inside){
// assert is != -1;
coordinates.add(is);
@ -857,7 +892,7 @@ public class MapRenderRepositories {
int bx = (int) (is >> 32);
int by = (int) (is & 0xffffffff);
coordinates.add(is);
is = calculateIntersection(x, y, pinside, bx, by, leftX, rightX, bottomY, topY);
is = calculateIntersection(x, y, bx, by, leftX, rightX, bottomY, topY);
coordinates.add(is);
lineEnded = true;
}