mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 03:55:28 -04:00
#490: Fix for "incomplete" paths with implicit line back to start.
This commit is contained in:
parent
d2b58ed20e
commit
420f78be88
@ -131,9 +131,10 @@ public final class AdobePathWriter {
|
||||
// Replace initial point.
|
||||
AdobePathSegment initial = subpath.get(0);
|
||||
if (initial.apx != prev.apx || initial.apy != prev.apy) {
|
||||
// TODO: Line back to initial if last anchor point does not equal initial anchor?
|
||||
// subpath.add(new AdobePathSegment(CLOSED_SUBPATH_BEZIER_LINKED, prev.cppy, prev.cppx, prev.apy, prev.apx, 0, 0));
|
||||
throw new AssertionError("Not a closed path");
|
||||
// Line back to initial if last anchor point does not equal initial anchor
|
||||
collinear = isCollinear(prev.cppx, prev.cppy, initial.apx, initial.apy, initial.apx, initial.apy);
|
||||
subpath.add(new AdobePathSegment(collinear ? CLOSED_SUBPATH_BEZIER_LINKED : CLOSED_SUBPATH_BEZIER_UNLINKED, prev.cppy, prev.cppx, prev.apy, prev.apx, initial.apy, initial.apx));
|
||||
prev = new AdobePathSegment(CLOSED_SUBPATH_BEZIER_LINKED, initial.apy, initial.apx, initial.apy, initial.apx, 0, 0);
|
||||
}
|
||||
|
||||
collinear = isCollinear(prev.cppx, prev.cppy, initial.apx, initial.apy, initial.cplx, initial.cply);
|
||||
@ -151,6 +152,9 @@ public final class AdobePathWriter {
|
||||
pathIterator.next();
|
||||
}
|
||||
|
||||
// TODO: If subpath is not empty at this point, there was no close segment...
|
||||
// Either wrap up (if coordinates match), or throw exception (otherwise)
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,7 @@ import java.util.Arrays;
|
||||
|
||||
import static com.twelvemonkeys.imageio.path.AdobePathSegment.*;
|
||||
import static com.twelvemonkeys.imageio.path.PathsTest.assertPathEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* AdobePathWriterTest.
|
||||
@ -93,6 +92,46 @@ public class AdobePathWriterTest {
|
||||
new AdobePathWriter(path);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateClosed() {
|
||||
GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD);
|
||||
path.moveTo(.5, .5);
|
||||
path.lineTo(1, .5);
|
||||
path.curveTo(1, 1, 1, 1, .5, 1);
|
||||
path.closePath();
|
||||
|
||||
new AdobePathWriter(path).writePath();
|
||||
|
||||
fail("Test that we have 4 segments");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateImplicitClosed() {
|
||||
GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD);
|
||||
path.moveTo(.5, .5);
|
||||
path.lineTo(1, .5);
|
||||
path.curveTo(1, 1, 1, 1, .5, 1);
|
||||
path.lineTo(.5, .5);
|
||||
|
||||
new AdobePathWriter(path).writePath(); // TODO: Should we allow this?
|
||||
|
||||
fail("Test that we have 4 segments, and that it is equal to the one above");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDoubleClosed() {
|
||||
GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD);
|
||||
path.moveTo(.5, .5);
|
||||
path.lineTo(1, .5);
|
||||
path.curveTo(1, 1, 1, 1, .5, 1);
|
||||
path.lineTo(.5, .5);
|
||||
path.closePath();
|
||||
|
||||
new AdobePathWriter(path).writePath();
|
||||
|
||||
fail("Test that we have 4 segments, and that it is equal to the one above");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteToStream() throws IOException {
|
||||
Path2D path = new GeneralPath(Path2D.WIND_EVEN_ODD);
|
||||
@ -168,7 +207,7 @@ public class AdobePathWriterTest {
|
||||
AdobePathWriter pathCreator = new AdobePathWriter(path);
|
||||
|
||||
byte[] bytes = pathCreator.writePath();
|
||||
System.err.println(Arrays.toString(bytes));
|
||||
// System.err.println(Arrays.toString(bytes));
|
||||
|
||||
assertEquals(12 * 26, bytes.length);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user