No crashes anymore :3
This commit is contained in:
@@ -25,6 +25,23 @@ def get_nearest_pot(value: int) -> int:
|
||||
else:
|
||||
return upper_pot
|
||||
|
||||
def get_nearest_power_of_two_downscale(value: int) -> int:
|
||||
"""
|
||||
Finds the nearest power of two that is less than or equal to the given value.
|
||||
If the value is already a power of two, it returns the value itself.
|
||||
Returns 1 if the value is less than 1.
|
||||
"""
|
||||
if value < 1:
|
||||
return 1
|
||||
if is_power_of_two(value):
|
||||
return value
|
||||
# Find the largest power of two strictly less than value,
|
||||
# unless value itself is POT.
|
||||
# (1 << (value.bit_length() - 1)) achieves this.
|
||||
# Example: value=7 (0111, bl=3), 1<<2 = 4.
|
||||
# Example: value=8 (1000, bl=4), 1<<3 = 8.
|
||||
# Example: value=9 (1001, bl=4), 1<<3 = 8.
|
||||
return 1 << (value.bit_length() - 1)
|
||||
# --- Dimension Calculation ---
|
||||
|
||||
def calculate_target_dimensions(
|
||||
|
||||
Reference in New Issue
Block a user