Skip to content
New issue

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

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

Already on GitHub? # to your account

RoundingMethod.FLOOR doesn't actually work for the TimeType.EXACT #2

Closed
moi15moi opened this issue Aug 21, 2024 · 0 comments · Fixed by #4
Closed

RoundingMethod.FLOOR doesn't actually work for the TimeType.EXACT #2

moi15moi opened this issue Aug 21, 2024 · 0 comments · Fixed by #4

Comments

@moi15moi
Copy link
Owner

I realised that the RoundingMethod.FLOOR doesn't actually work for the TimeType.EXACT.
To explain why it doesn't work, let's see an example:

Ex without any rounding/flooring

Timestamps
Frame 0: 0 ms
Frame 1: 33.333333 ms
Frame 2: 66.666666 ms
Frame 3: 100 ms
Frame 4: 133.333333 ms
Frame 5: 166.666666 ms

EXACT
Frame 0: [0, 33] ms
Frame 1: [34, 66] ms
Frame 2: [67, 99] ms
Frame 3: [100, 133] ms
Frame 4: [134, 166] ms

START
Frame 0: 0 ms
Frame 1: [1, 33] ms
Frame 2: [34, 66] ms
Frame 3: [67, 100] ms
Frame 4: [101, 133] ms

END
Frame 0: [1, 33] ms
Frame 1: [34, 66] ms
Frame 2: [67, 100] ms
Frame 3: [101, 133] ms

Ex with FLOOR

Timestamps
Frame 0: 0 ms
Frame 1: 33 ms
Frame 2: 66 ms
Frame 3: 100 ms
Frame 4: 133 ms
Frame 5: 166 ms

EXACT
Frame 0: [0, 32] ms
Frame 1: [33, 65] ms
Frame 2: [66, 99] ms
Frame 3: [100, 132] ms
Frame 4: [133, 165] ms

START
Frame 0: 0 ms
Frame 1: [1, 33] ms
Frame 2: [34, 66] ms
Frame 3: [67, 100] ms
Frame 4: [101, 133] ms

END
Frame 0: [1, 33] ms
Frame 1: [34, 66] ms
Frame 2: [67, 100] ms
Frame 3: [101, 133] ms

Remember, this is the interval for each type of timing:
EXACT: $[CurrentFrameTime, NextFrameTime[$
START: $]PreviousFrameTime , CurrentFrameTime]$
END: $]CurrentFrameTime, NextFrameTime]$

But, for our case, the interval are always integer, so it gives:
EXACT: $[\lceil CurrentFrameTime \rceil, \lceil NextFrameTime \rceil - 1]$
START: $[\lfloor PreviousFrameTime \rfloor + 1, \lfloor CurrentFrameTime \rfloor]$
END: $[\lfloor CurrentFrameTime \rfloor + 1, \lfloor NextFrameTime \rfloor]$

Currently, the program always output the timestamps in milliseconds, but actually, I would want to give the user a choice where he could select the precision from seconds to nanoseconds. I choosed a maximum of nanoseconds, because I highly doubt a user would need more precision than that.
Since I want the program to support maximum nanoseconds AND EXACT use ceil VS START/END use floor, it means that the timestamps would need to be stored with a precision just higher than nanoseconds $10^{-9}$ which means the timestamps would need to be stored with a unit of $10^{-10}$ and they would be floored.

With those change, def ms_to_frames(self, ms: int, time_type: TimeType) -> int would be replaced with def time_to_frame(self, time: int, input_precision: int, time_type: TimeType) -> int AND def frames_to_ms(self, frame: int, time_type: TimeType) -> int would be replaced with
def frame_to_time(self, frame: int, output_precision: int, time_type: TimeType, middle_time: bool) -> int.

@moi15moi moi15moi mentioned this issue Oct 12, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant