pixi-svg icon indicating copy to clipboard operation
pixi-svg copied to clipboard

[Bug]: closePath command should set the current point to the initial point in the subpath

Open ShukantPal opened this issue 3 years ago • 5 comments

I used your code in @pixi-essentials/svg @bigtimebuddy. Haha, and got this strange bug that messed up my client's figures.

I realized it occurred at 'm' (relative) commands after 'Z' (closePath). It was because you aren't updating the current point after closing the path.

In the SVG specification (section 8.3.3), it says:

At the end of the command, the new current point is set to the initial point of the current subpath.

Just wanted to forward this fix from @pixi-essentials/svg to here.

x = this.currentPath.points[0] || 0;
y = this.currentPath.points[1] || 0;

this.closePath();

(here https://github.com/bigtimebuddy/pixi-svg/blob/89e4ab834fa4ef05b64741596516c732eae34daa/src/SVG.js#L351)

ShukantPal avatar Nov 29 '20 19:11 ShukantPal

I'm also okay sun-setting this module in favor of your SVG. Does it do the same stuff?

bigtimebuddy avatar Nov 29 '20 22:11 bigtimebuddy

@pixi-essentials/svg generates a scene graph instead of generating a single large Graphics object. It supports a much wider (the widest?) feature set and is larger. But yeah, the base SVG concept is the same.

ShukantPal avatar Nov 29 '20 22:11 ShukantPal

Could you make a mode where is combines/flattens In addition to exploded graph? I see both as being useful and that actually was a feature request someone made here. If you flatten it avoids all the transforms but at the expense of flexibility, exploded view is much better for animation.

bigtimebuddy avatar Nov 29 '20 23:11 bigtimebuddy

A flattening mode would be severely limited w.r.t. the exploded view. It is impossible to support (which otherwise @pixi-essentials/svg already has):

  • text, image, defs, use elements
  • masking
  • transforms
  • culling (yea, @pixi-essentials/svg automatically culls its internal scene graph)

From outside, however, SVGScene is a DisplayObject and has no children. Its scene graph is kept totally disconnected from the user's scene graph (i.e is internal & hidden).

From an API standpoint, I don't see how a flattened mode wouldn't be useful b/c @pixi-essentials/svg exposes a SVGScene, which is not a Graphics object. Why do think a flattened mode is useful?

ShukantPal avatar Nov 29 '20 23:11 ShukantPal

Maybe it's not that useful. What you describe would still allow users to do RenderTexture or cacheAsBitmap for performance, which is good. The only advantage of flattening is if you have a very complex SVG and then you'd need to allocate a large pixi scene graph. Whereas, representing it as pure geometry is probably more memory efficient as complexity scales. Overall, I like your approach better. What I'm describing is probably more of an edge-case and could be added later if there's a need.

bigtimebuddy avatar Nov 30 '20 00:11 bigtimebuddy