Hey all,
Today I had a sketch like this:
PShape s;
void setup() {
size(400, 300);
s = loadShape("shape.svg");
}
void draw() {
background(255);
shape(s);
}
And the Processing IDE tells me
shape command not handled: e-4
I figured out what this means! It means that there is something in the XML of the SVG that Processing doesn’t like.
And what is that? It is e-4
. It occurred in a string like this
-0.35022 -2.1e-4,-0.71185 0.14827
This may look like some SVG command or a problem with commas or white space, but is much simpler than that. It is a case of Scientific_notation. And Processing doesn’t like it.
This -2.1e-4
should be this -0.00021
. Do that and the error is gone.
How to convert scientific notation in Processing-friendly notation? Python and regex to the rescue!
import re
def scientific_to_float(match):
return str(float(match.group()))
pattern = r'\b\d+(\.\d+)?e-4\b'
with open('input.svg', 'r') as file:
content = file.read()
updated_content = re.sub(pattern, scientific_to_float, content)
with open('output.svg', 'w') as file:
file.write(updated_content)
Hope this helps!