SVGPath icon indicating copy to clipboard operation
SVGPath copied to clipboard

SVGPath coordinate parse issue

Open chenyunguiMilook opened this issue 3 years ago • 10 comments

let pathString = "M301 162L307 154L315 149L325 139.5L332.5 135.5L341 128.5L357.5 117.5L364.5 114.5L368.5 110.5L380 105.5L390.5 102L404 96L410.5 96L415 97.5L421 104L425.5 113.5L428.5 126L429.5 134L429.5 141L429.5 148L425.5 161.5L425.5 169L414 184.5L409.5 191L401 201L395 209L386 214.5L378.5 217L368 220L348 219.5L338 218L323.5 212.5L312 205.5L302.5 197.5L295.5 189L291.5 171.5L294 168L298 165.5L301 162z" for this path string, the result shape coordinate y seems flipped. 截屏2022-07-27 10 03 17

chenyunguiMilook avatar Jul 27 '22 02:07 chenyunguiMilook

@chenyunguiMilook how are you rendering the output - with CoreGraphics? On iOS or macOS?

nicklockwood avatar Jul 27 '22 06:07 nicklockwood

the rendering is OK, and I found the code issue: func moveTo() throws -> SVGCommand { let numbers = try assertArgs(2) return .moveTo(SVGPoint(x: numbers[0], y: -numbers[1])) }

the y coordinate all using -numbers[1]

chenyunguiMilook avatar Jul 27 '22 06:07 chenyunguiMilook

@chenyunguiMilook this is intentional because CoreGraphics uses inverted Y axis relative to SVG, but that's why I was wondering how you are getting the flipped output?

nicklockwood avatar Jul 27 '22 06:07 nicklockwood

em, I see! I think it's better not to change the Y value in the parse phase, but to multiply the corresponding transformation matrix according to different coordinate systems, do you agree?

chenyunguiMilook avatar Jul 27 '22 06:07 chenyunguiMilook

@chenyunguiMilook yes, that makes sense

nicklockwood avatar Jul 27 '22 06:07 nicklockwood

Great!

chenyunguiMilook avatar Jul 27 '22 06:07 chenyunguiMilook

@chenyunguiMilook I've pushed a minor update that fixes output serialization and adds a note about the flipped coordinates. Changing the values at parsing time is a significant breaking change so I'll need to think about how best to approach it.

nicklockwood avatar Jul 27 '22 07:07 nicklockwood

got it thanks!

chenyunguiMilook avatar Jul 27 '22 07:07 chenyunguiMilook