Skip to content

Commit 11ca32b

Browse files
committed
add suggested changes
1 parent 89201ea commit 11ca32b

File tree

1 file changed

+50
-19
lines changed

1 file changed

+50
-19
lines changed

core/test/processing/core/PShapeSVGPathTest.java

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public class PShapeSVGPathTest {
88

99
@Test
1010
public void testCompactPathNotation() {
11-
// Test the failing SVG from issue #1244
1211
String svgContent = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\" viewBox=\"0 0 29 29\">" +
1312
"<path d=\"m0 6 3-2 15 4 7-7a2 2 0 013 3l-7 7 4 15-2 3-7-13-5 5v4l-2 2-2-5-5-2 2-2h4l5-5z\"/>" +
1413
"</svg>";
@@ -17,6 +16,11 @@ public void testCompactPathNotation() {
1716
XML xml = XML.parse(svgContent);
1817
PShapeSVG shape = new PShapeSVG(xml);
1918
Assert.assertNotNull(shape);
19+
Assert.assertTrue(shape.getChildCount() > 0);
20+
21+
PShape path = shape.getChild(0);
22+
Assert.assertNotNull(path);
23+
Assert.assertTrue(path.getVertexCount() > 5);
2024
} catch (Exception e) {
2125
Assert.fail("Encountered exception " + e);
2226
}
@@ -40,38 +44,65 @@ public void testWorkingPathNotation() {
4044

4145
@Test
4246
public void testCompactArcNotationVariations() {
43-
// Test various compact arc notations
44-
String[] testCases = {
45-
// Flags only concatenated (e.g., "01")
46-
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\"><path d=\"M10 10 A30 30 0 0110 50\"/></svg>",
47-
// Flags and coordinate concatenated (e.g., "013")
48-
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\"><path d=\"M10 10 A30 30 0 013 50\"/></svg>",
49-
// Standard notation (should still work)
50-
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\"><path d=\"M10 10 A30 30 0 0 1 10 50\"/></svg>"
51-
};
47+
String svgContent1 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\">" +
48+
"<path d=\"M10 10 A30 30 0 013 50\"/></svg>";
5249

5350
try {
54-
for (String svgContent : testCases) {
55-
XML xml = XML.parse(svgContent);
56-
PShapeSVG shape = new PShapeSVG(xml);
57-
Assert.assertNotNull(shape);
58-
}
51+
XML xml = XML.parse(svgContent1);
52+
PShapeSVG shape = new PShapeSVG(xml);
53+
PShape path = shape.getChild(0);
54+
int vertexCount = path.getVertexCount();
55+
PVector lastVertex = path.getVertex(vertexCount - 1);
56+
Assert.assertEquals(3.0f, lastVertex.x, 0.0001f);
57+
Assert.assertEquals(50.0f, lastVertex.y, 0.0001f);
58+
} catch (Exception e) {
59+
Assert.fail("Encountered exception " + e);
60+
}
61+
62+
String svgContent2 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\">" +
63+
"<path d=\"M10 10 A30 30 0 0110 50\"/></svg>";
64+
65+
try {
66+
XML xml = XML.parse(svgContent2);
67+
PShapeSVG shape = new PShapeSVG(xml);
68+
PShape path = shape.getChild(0);
69+
int vertexCount = path.getVertexCount();
70+
PVector lastVertex = path.getVertex(vertexCount - 1);
71+
Assert.assertEquals(10.0f, lastVertex.x, 0.0001f);
72+
Assert.assertEquals(50.0f, lastVertex.y, 0.0001f);
73+
} catch (Exception e) {
74+
Assert.fail("Encountered exception " + e);
75+
}
76+
77+
String svgContent3 = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\">" +
78+
"<path d=\"M10 10 A30 30 0 0 1 10 50\"/></svg>";
79+
80+
try {
81+
XML xml = XML.parse(svgContent3);
82+
PShapeSVG shape = new PShapeSVG(xml);
83+
PShape path = shape.getChild(0);
84+
int vertexCount = path.getVertexCount();
85+
PVector lastVertex = path.getVertex(vertexCount - 1);
86+
Assert.assertEquals(10.0f, lastVertex.x, 0.0001f);
87+
Assert.assertEquals(50.0f, lastVertex.y, 0.0001f);
5988
} catch (Exception e) {
6089
Assert.fail("Encountered exception " + e);
6190
}
6291
}
6392

6493
@Test
6594
public void testCompactArcWithNegativeCoordinates() {
66-
// Test compact arc notation with negative coordinates
6795
String svgContent = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\">" +
68-
"<path d=\"M50 50 a20 20 0 01-10 20\"/>" +
69-
"</svg>";
96+
"<path d=\"M50 50 a20 20 0 01-10 20\"/></svg>";
7097

7198
try {
7299
XML xml = XML.parse(svgContent);
73100
PShapeSVG shape = new PShapeSVG(xml);
74-
Assert.assertNotNull(shape);
101+
PShape path = shape.getChild(0);
102+
int vertexCount = path.getVertexCount();
103+
PVector lastVertex = path.getVertex(vertexCount - 1);
104+
Assert.assertEquals(40.0f, lastVertex.x, 0.0001f);
105+
Assert.assertEquals(70.0f, lastVertex.y, 0.0001f);
75106
} catch (Exception e) {
76107
Assert.fail("Encountered exception " + e);
77108
}

0 commit comments

Comments
 (0)