PamGram/modules/gacha/utils.py
洛水居室 233e7ab58d
♻️ PaiGram V4
Co-authored-by: luoshuijs <luoshuijs@outlook.com>
Co-authored-by: Karako <karakohear@gmail.com>
Co-authored-by: xtaodada <xtao@xtaolink.cn>
2023-03-14 09:27:22 +08:00

27 lines
986 B
Python

import contextlib
from typing import List
def lerp(x: int, x_y_array) -> int:
with contextlib.suppress(KeyError, IndexError):
if x <= x_y_array[0][0]:
return x_y_array[0][1]
if x >= x_y_array[-1][0]:
return x_y_array[-1][1]
for index, _ in enumerate(x_y_array):
if x == x_y_array[index + 1][0]:
return x_y_array[index + 1][1]
if x < x_y_array[index + 1][0]:
position = x - x_y_array[index][0]
full_dist = x_y_array[index + 1][0] - x_y_array[index][0]
if full_dist == 0:
return position
prev_value = x_y_array[index][1]
full_delta = x_y_array[index + 1][1] - prev_value
return int(prev_value + ((position * full_delta) / full_dist))
return 0
def set_subtract(minuend: List[int], subtrahend: List[int]) -> List[int]:
return [i for i in minuend if i not in subtrahend]