w3c / svgwg

SVG Working Group specifications
Other
710 stars 133 forks source link

Define path interpolation when relative and absolute segment types are used. #947

Open emilio opened 4 months ago

emilio commented 4 months ago

https://svgwg.org/svg2-draft/paths.html says how to interpolate paths:

For animation, two d property values can only be interpolated smoothly when the path data strings contain have the same structure, (i.e. exactly the same number and types of path data commands which are in the same order). If an animation is specified and the lists of path data commands do not have the same structure, then the values must be interpolated using the discrete animation type.

However browsers support interpolating relative with non-relative paths, and currently behavior diverges across browsers...

https://wpt.fyi/results/svg/animations/animate-path-animation-Mm-Aa-Z.tentative.html?label=experimental&label=master&aligned

What is the correct behavior? Should paths always be normalized (absolutized) before interpolation? Or should paths try to preserve relativeness, and if so what's the right way to deal with mismatches?

Doktorchen commented 4 months ago

Hmmm, both the SVG 1.1 recommendation and the 2.0 draft define for relative and absolute only two letters for the same command to destinguish between relative and absolute. And it is mentioned explicitely, which (absolute) points is meant, if relative coordinates are used. Therefore obviously one has always to interpolate between the given points, not the given numbers, without taking into account, what they mean.

But I agree, that it is better to note this explicitely to avoid confusion between different implementations.

emilio commented 4 months ago

And it is mentioned explicitely, which (absolute) points is meant, if relative coordinates are used.

Therefore obviously one has always to interpolate between the given points, not the given numbers, without taking into account, what they mean.

Sure, but the point is that there are two ways to represent the same point, so you can interpolate the same points and give two different answers which are both correct, right? So it's not so much about confusion but undefinedness in the spec...

Doktorchen commented 4 months ago

It is a simple addition of coordinates as operation, affine, therefore no problem, same result. This is because ab = a(b+c-c) = a(b+c) -ac = ab + ac -ac = ab, with a scalar and b, c vectors. Effectively a(t), t time represents some animate animation interpolations, acting always on the complete path in a d attribute.

Just to have some pastime, I created a simple example using two paths with M,C and m,c and the same graphical result - interpolates in the same way. Even the third path with MC in the path d attribute and m,c in the animate values does not result in a different animation, as expected (in firefox and vivaldi).

This would be different, if one tries to interpolate between absolute and relative coordinates, all points just need the same coordinate system (origin) to get it right.

emilio commented 4 months ago

It is a simple addition of coordinates as operation, affine, therefore no problem, same result.

Same result, but since the difference is observable via DOM APIs it should be defined to avoid gratuitous behaviour differences between browsers.