1
0

feat: add fps module in sonnet

This commit is contained in:
2026-01-19 11:14:13 +08:00
parent 5323617ca6
commit 84897a409b
3 changed files with 48 additions and 89 deletions

View File

@@ -0,0 +1,47 @@
import math
def to_fps(delta_time: float) -> float:
"""
Convert delta time to FPS value.
:param delta_time: The delta time.
:return: The FPS in float value.
"""
if delta_time <= 0.0:
raise RuntimeError("delta time should not be zero or negative")
else:
return 1.0 / delta_time
def to_int_fps(delta_time: float) -> int:
"""
Convert delta time to integer FPS value.
:param delta_time: The delta time.
:return: The integer FPS (rounded down).
"""
return int(math.floor(to_fps(delta_time)))
def from_fps(fps: float) -> float:
"""
Convert FPS value to delta time.
:param fps: The FPS value.
:return: The delta time.
"""
if fps <= 0.0:
raise RuntimeError("fps should not be zero or negative")
else:
return 1.0 / fps
def from_int_fps(fps: int) -> float:
"""
Convert integer FPS value to delta time.
:param fps: The integer FPS value.
:return: The delta time.
"""
return from_fps(float(fps))