jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.7k stars 518 forks source link

svg deserializer ignores pathSelfClosed #1052

Open ssendev opened 2 years ago

ssendev commented 2 years ago

Expected Behavior

svg is imported without error

Actual Behavior

Error: Malformed svg path at 2:46. Path closed itself with command #1

but that branch should never be reached

https://github.com/jscad/OpenJSCAD.org/blob/56f572518c85d767ac680aa2da1af46c4847e63c/packages/io/svg-deserializer/src/shapesMapGeometry.js#L438-L441

Steps to Reproduce the Problem

go to https://openjscad.xyz and paste

const { primitives, extrusions, colors, transforms } = require('@jscad/modeling')
const { deserializers } = require('@jscad/io')

const getParameterDefinitions = () => [
  { name: 'text', type: 'text', caption: 'SVG', initial: `
  <svg>
    <g>
      <path d="m 56.5,120.6 c -0.6,0.4 -0.8,1.3 -0.4,2 0.4,0.8 1.3,1.1 2,0.7 0.6,-0.4 0.8,-1.3 0.4,-2 -0.5,-0.8 -1.3,-1.1 -2,-0.7"/>
      <path d="m 31.60037,127.19088 c 16.378943,-22.02726 39.373546,-22.61884 48.399996,-27.9 l -2.8,-3.399999 C 40.772278,46.646651 31.634174,85.216887 31.60037,127.19088 Z m 1.3,-2.1 c -21.533333,6.4 -10.766667,3.2 0,0 z"/>
    </g>
  </svg>
  ` },
  { name: 'height', type: 'float', initial: 1, caption: 'Höhe [mm]' },
  { name: 'groundlevel', type: 'float', initial: 0, caption: 'Abstand zum boden [mm]' },
]

const main = (params) => {
  let svg = deserializers.svg({ output: "geometry", target: "geom2", pathSelfClosed: "split" }, params.text || '')
  svg = extrusions.extrudeLinear({ height: params.height || 1 }, svg)
  svg = transforms.translate([0,0,params.groundlevel || 0],svg)
  svg = colors.colorize(colors.hexToRgb('#000080'), svg)
  return svg
}

module.exports = { main, getParameterDefinitions }

Specifications

z3dev commented 2 years ago

@ssendev thanks for the nice example. we will take a look at this.