From 080cb3de757bfbaf081a9d36804763925b826129 Mon Sep 17 00:00:00 2001 From: Brian Sapozhnikov Date: Sun, 29 Jan 2023 21:22:54 -0500 Subject: [PATCH] address issue 515 --- core/src/processing/core/PShapeSVG.java | 8 +++++ core/test/processing/core/PShapeSVGTest.java | 32 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 core/test/processing/core/PShapeSVGTest.java diff --git a/core/src/processing/core/PShapeSVG.java b/core/src/processing/core/PShapeSVG.java index 39cbf0c11..e85389f02 100644 --- a/core/src/processing/core/PShapeSVG.java +++ b/core/src/processing/core/PShapeSVG.java @@ -515,6 +515,7 @@ public class PShapeSVG extends PShape { StringBuilder pathBuffer = new StringBuilder(); boolean lastSeparate = false; + boolean isOnDecimal = false; for (int i = 0; i < pathDataChars.length; i++) { char c = pathDataChars[i]; @@ -539,6 +540,13 @@ public class PShapeSVG extends PShape { if (c == 'Z' || c == 'z') { separate = false; } + if (c == '.' && !isOnDecimal) { + isOnDecimal = true; + } + else if (isOnDecimal && (c < '0' || c > '9')) { + pathBuffer.append("|"); + isOnDecimal = c == '.'; + } if (c == '-' && !lastSeparate) { // allow for 'e' notation in numbers, e.g. 2.10e-9 // https://download.processing.org/bugzilla/1408.html diff --git a/core/test/processing/core/PShapeSVGTest.java b/core/test/processing/core/PShapeSVGTest.java new file mode 100644 index 000000000..2b9ddd96c --- /dev/null +++ b/core/test/processing/core/PShapeSVGTest.java @@ -0,0 +1,32 @@ +package processing.core; + +import org.junit.Assert; +import org.junit.Test; +import processing.data.XML; +import processing.core.PImage; + +import java.awt.*; + + +public class PShapeSVGTest { + + private static final String TEST_CONTENT = ""; + + @Test + public void testDecimals() { + try { + XML xml = XML.parse(TEST_CONTENT); + PShapeSVG shape = new PShapeSVG(xml); + PShape[] children = shape.getChildren(); + Assert.assertEquals(1, children.length); + PShape[] grandchildren = children[0].getChildren(); + Assert.assertEquals(1, grandchildren.length); + Assert.assertEquals(0, grandchildren[0].getChildCount()); + Assert.assertEquals(2, grandchildren[0].getVertexCount()); + } + catch (Exception e) { + Assert.fail("Encountered exception " + e); + } + } + +}