Skip to content

Commit

Permalink
Fixed the star tesselator only respecting the last shape when it find…
Browse files Browse the repository at this point in the history
…s a non-star shape.
  • Loading branch information
Michael Zangl committed Aug 19, 2015
1 parent b2e28dd commit 04f1a06
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static Clockwise isClockwise(float x1, float y1, float x2,
* @author Michael Zangl
*/
private static class RecordingStarOrTesselatorVisitor extends
SimplePathVisitor {
SimplePathVisitor {
/**
* Most simple shapes should not have more than 16 corners. XXX:
* Confirm.
Expand Down Expand Up @@ -86,8 +86,7 @@ public RecordingStarOrTesselatorVisitor(
RecordingColorHelper colorHelper, Recorder recorder) {
colorRecorder = colorHelper;
this.recorder = recorder;
fallback = new RecordingTesselatorVisitor(colorHelper,
recorder);
fallback = new RecordingTesselatorVisitor(colorHelper, recorder);
}

@Override
Expand All @@ -106,7 +105,6 @@ public void moveTo(float[] vertex) {
// We send a moveTo to force closing the current loop.
fallback.moveTo(vertex);
}
commitIfRequired();
startPointX = lastPointX = vertex[0];
startPointY = lastPointY = vertex[1];
inDraw = false;
Expand All @@ -131,8 +129,9 @@ && closeTo(lastPointY, vertex[1])) {
vBuffer.addVertex(startPointX, startPointY);
vBuffer.addVertex(lastPointX, lastPointY);
vBuffer.addVertex(vertex[0], vertex[1]);
final Clockwise cw = Clockwise.isClockwise(startPointX, startPointY,
lastPointX, lastPointY, vertex[0], vertex[1]);
final Clockwise cw = Clockwise.isClockwise(startPointX,
startPointY, lastPointX, lastPointY, vertex[0],
vertex[1]);
if (cw != Clockwise.NOT_SURE
&& isClockwise != Clockwise.NOT_SURE
&& cw != isClockwise) {
Expand All @@ -154,15 +153,25 @@ private void switchToFallback() {
}
buffer.rewind();
final float[] vertex = new float[2];
buffer.get(vertex);
fallback.moveTo(vertex);
buffer.get(vertex);
fallback.lineTo(vertex);
for (int vertexPosition = 4; vertexPosition < count; vertexPosition += 6) {
buffer.position(vertexPosition);
float lastStartX = Float.NaN, lastStartY = Float.NaN;
// read all triangles.
for (int i = 0; i < count; i += 6) {
buffer.get(vertex);
if (lastStartX != vertex[0] || lastStartY != vertex[1]) {
// a new start started.
lastStartX = vertex[0];
lastStartY = vertex[1];
fallback.moveTo(vertex);
buffer.get(vertex);
fallback.lineTo(vertex);
} else {
// fake get
buffer.get(vertex);
}
buffer.get(vertex);
fallback.lineTo(vertex);
}

buffer.rewind();
failed = true;
}
Expand All @@ -176,8 +185,7 @@ public void closeLine() {
if (failed) {
fallback.closeLine();
}
commitIfRequired();
// triangle is auto-closed.
// triangle is auto-closed when not using fallback.
}

@Override
Expand Down

0 comments on commit 04f1a06

Please sign in to comment.