Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion about the description of this algorithm listed in SMIL Animation doc. #838

Closed
krave1986 opened this issue Apr 15, 2021 · 11 comments

Comments

@krave1986
Copy link

SMIL Animation spec:
https://www.w3.org/TR/smil-animation/

I quote the algorithm here:

Let o be the offset value of a given begin value,
d be the associated simple duration,
AD be the associated active duration.
Let rAt be the time when the begin time becomes resolved.
Let rTo be the resolved sync-base or event-base time without the offset
Let rD be rTo - rAt. If rD < 0 then rD is set to 0.

If AD is indefinite, it compares greater than any value of o or ABS(o).
REM( x, y ) is defined as x - (y * floor( x/y )).
If y is indefinite, REM( x, y ) is just x.

Let mb = REM( ABS(o), d ) - rD

If ABS(o) >= AD then the element does not begin.
Else if mb >= 0 then the media begins at mb.
Else the media begins at mb + d.

I have some questions to hopefully find some relief here:

  1. In which situations, the time when the begin time becomes resolved and the resolved sync-base or event-base time without the offset are not same? Please note without the offset.
  2. Is offset included in simple duration or not?
  3. May I that REM( x, y ) can be defined as x % y ?
  4. Can anyone helps to explain the reasons for last 3 sentences? I can not get the point here.

Thank you very much in advance! I really not able to figure that out by myself.

@fsoder
Copy link

fsoder commented Apr 16, 2021

  1. Being triggered by another sync/event-base is the simplest case I can think of. So if you have foo, bar and baz and something like foo.begin+M for bar and bar.begin-N for baz. Also note that any beginEvent dispatched for an element can have a time stamp in the past. I guess some systems could perhaps also have some latency in event dispatch and use the time the event is dispatched as the event-base time, and not the time is received (and resolved).
  2. No it isn't.
  3. You can probably use a % operator (or similar) to implement it.
  4. The first sentence basically says that if the element would end before 'current time' (offset magnitude is greater than the active duration) it shouldn't begin (be ignored). The last two define an offset into the interval at which point the 'media' actually begins - you can refer to the example that follows where you get: mb = REM(ABS(-8), 3) - 0 = 2

@krave1986
Copy link
Author

Hi, @fsoder . Thank you for your explaination.
In order to figure it out, I also have done some drawings about the timeline to make every pieces reasonable.

I'd like to express my understanding to collect some corrections if I made any mistakes.
So please correct me if any.

So, as a conclusion, the algorithm is trying to find a specific time point within d - the simple duration. This spcific time point will be exactly at which the animation starts visibly. It could be any time point inside simple duration not the "zero" point of simple duration.

I think rD means resolved delay which refers to the delay between rAt and rTo.
Assumes that rAt is now. rTo could be in the future or in the past.
If rTo is in the past, there is no delay, same as If rD < 0 then rD is set to 0.
Otherwise, it means the beginning of animation is not yet. We need to wait or it may also start right away if negative offset is considered.

Imagine a horizontal timeline axis which directs right as its positive direction. Acitve duration lay on this axis and its start point is rTo. Negative offset will pull the whole active duation left along the axis.

Considering repeat behavior applied on the active duration, there would be serveral intervals included in it.
Imagine there is one of the intervals which is most close to rTo.
And the distance between the left end of the interval and rTo is REM.

If rD is shorter than REM, then the animation beginning should be at REM - rD within d.
If rD is longer than REM, the the animation beginning should be at d + REM - rD within d.

Hmm... I think it's better to illustrate the concept by images.

@krave1986
Copy link
Author

krave1986 commented Apr 22, 2021

With that saying, I think the algorithm only applies when the offset is negative and the resolved sync-base or event-base time with the offset is earlier than rAt.

Futhermore, ABS(rD) is not allowed to be larger than d.

Here is an example, please bear with me:

If
offset - o: -8s
simple duration - d: 3s
repeatCount: 3
rAt: 7s
rTo: 13s

thus we will have
active duration - AD: 9s
rD = rTo - rAt = 6s
REM( ABS(-8s), 3s) = 2s

mb = REM - rD = -4s < 0

According to the algorithm, the media should begin at mb + d = -1s , which is obviously wrong.
Actually the media should begin at 2s.

In order to make sure that mb is shorter than d, if mb < 0, the media begins at REM(mb, d) + d.

What do you think?

@fsoder
Copy link

fsoder commented Apr 23, 2021

I'd agree that it appears to be bug in the spec that mb can/will only be adjusted with a single simple duration. I also suspect that this algorithm may be more complicated than it needs to be, and that there might be simpler ways of expressing it. (Perhaps something like mb = REM(rAt - (rTo + o), d) with the additional constraints on rAt, rTo and that the interval is active.)

@krave1986
Copy link
Author

I have try to understand your suggestion: mb = REM(rAt - (rTo + o), d) and did some validations.
I think that'll work.

If we follow your algorithm, there is no need to determine if mb is positive or negative. That would be better I think.

But I am not sure whether it will cover all repeat behaviors or not.

So as to the constaints, as far as I can think of, could be:
ABS(o) > rD

Besides, I think we can optimise the first conclusion in the original algorithm from
If ABS(o) >= AD then the element does not begin. to
If (rD + AD) <= ABS(o) < rD, then the element does not begin.

For situation ABS(o) < rD, the animation will begin after rD + o at zero point of d.

By the way, I guess mb means media begin, right?

@fsoder
Copy link

fsoder commented Apr 26, 2021

As I mentioned previously, I suspect this algorithm is more complicated than it need be. It also feels like it's making this out as more of a special case than it ought to be. I think that the rejection of the relevant interval would follow from the regular interval resolution process, and determining the time within the interval (and simple duration) isn't any different than what'd be needed for any other syncbase (or really any other time value). 'Starting' (potentially) in the middle of an interval will also be the case for example when seeking the timeline, so this logic will be required there as well.

@krave1986
Copy link
Author

What do you mean by rejection of the relevant interval?

@fsoder
Copy link

fsoder commented Apr 26, 2021

That would be what the algorithm refers to as 'If ABS(o) >= AD then the element does not begin'.

@krave1986
Copy link
Author

Got it. I have got your point that the algorithm we are discussing is a very illustrative one.
Thank you very much for your response to help me clear my mind!

By the way, is SMIL animation around svg still relavent in near future?

It seems that Google was going to deprecate it.

@fsoder
Copy link

fsoder commented Apr 27, 2021

It's no longer deprecated in Chrome (read the whole thread that you reference! ;-)), and last time I checked usage was increasing.

@krave1986
Copy link
Author

Glad to know that!

I have no more questions.

Going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants