fix: LineClipper for multilinestrings
This commit is contained in:
parent
27b9294a36
commit
6c830575c9
@ -199,8 +199,10 @@ public class LineClipper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int clipLine(GeometryBuffer in, GeometryBuffer out) {
|
public int clipLine(GeometryBuffer in, GeometryBuffer out) {
|
||||||
|
out.clear();
|
||||||
int pointPos = 0;
|
int pointPos = 0;
|
||||||
int numLines = 0;
|
int numLines = 0;
|
||||||
|
|
||||||
for (int i = 0, n = in.index.length; i < n; i++) {
|
for (int i = 0, n = in.index.length; i < n; i++) {
|
||||||
int len = in.index[i];
|
int len = in.index[i];
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
@ -218,47 +220,44 @@ public class LineClipper {
|
|||||||
int inPos = pointPos;
|
int inPos = pointPos;
|
||||||
int end = inPos + len;
|
int end = inPos + len;
|
||||||
|
|
||||||
float prevX = in.points[inPos + 0];
|
float x = in.points[inPos++];
|
||||||
float prevY = in.points[inPos + 1];
|
float y = in.points[inPos++];
|
||||||
|
|
||||||
boolean inside = clipStart(prevX, prevY);
|
boolean inside = clipStart(x, y);
|
||||||
|
|
||||||
if (inside) {
|
if (inside) {
|
||||||
out.startLine();
|
out.startLine();
|
||||||
out.addPoint(prevX, prevY);
|
out.addPoint(x, y);
|
||||||
numLines++;
|
numLines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (inPos += 2; inPos < end; inPos += 2) {
|
while (inPos < end) {
|
||||||
/* get the current way point coordinates */
|
/* get the current way point coordinates */
|
||||||
float curX = in.points[inPos];
|
x = in.points[inPos++];
|
||||||
float curY = in.points[inPos + 1];
|
y = in.points[inPos++];
|
||||||
|
|
||||||
int clip;
|
int clip = clipNext(x, y);
|
||||||
if ((clip = clipNext(curX, curY)) != 0) {
|
if (clip == 0) {
|
||||||
if (clip < 0) {
|
/* current segment is fully outside */
|
||||||
if (inside) {
|
inside = false; // needed?
|
||||||
/* previous was inside */
|
} else if (clip == 1) {
|
||||||
out.addPoint(outX2, outY2);
|
/* current segment is fully within */
|
||||||
inside = false;
|
out.addPoint(x, y);
|
||||||
|
} else { /* clip == -1 */
|
||||||
} else {
|
if (inside) {
|
||||||
/* previous was outside */
|
/* previous was inside */
|
||||||
out.startLine();
|
out.addPoint(outX2, outY2);
|
||||||
numLines++;
|
|
||||||
out.addPoint(outX1, outY1);
|
|
||||||
out.addPoint(outX2, outY2);
|
|
||||||
|
|
||||||
inside = clipStart(curX, curY);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
out.addPoint(curX, curY);
|
/* previous was outside */
|
||||||
|
out.startLine();
|
||||||
|
numLines++;
|
||||||
|
out.addPoint(outX1, outY1);
|
||||||
|
out.addPoint(outX2, outY2);
|
||||||
}
|
}
|
||||||
} else {
|
inside = clipStart(x, y);
|
||||||
inside = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pointPos += len;
|
pointPos = end;
|
||||||
}
|
}
|
||||||
return numLines;
|
return numLines;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user