fix: improve canvas search scroll behavior further (#8491)

This commit is contained in:
David Luzar 2024-09-11 18:01:18 +02:00 committed by GitHub
parent b46ca0192b
commit fd39712ba6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 165 additions and 99 deletions

View file

@ -1,14 +1,27 @@
export const PRECISION = 10e-5;
export function clamp(value: number, min: number, max: number) {
export const clamp = (value: number, min: number, max: number) => {
return Math.min(Math.max(value, min), max);
}
};
export function round(value: number, precision: number) {
export const round = (
value: number,
precision: number,
func: "round" | "floor" | "ceil" = "round",
) => {
const multiplier = Math.pow(10, precision);
return Math.round((value + Number.EPSILON) * multiplier) / multiplier;
}
return Math[func]((value + Number.EPSILON) * multiplier) / multiplier;
};
export const roundToStep = (
value: number,
step: number,
func: "round" | "floor" | "ceil" = "round",
): number => {
const factor = 1 / step;
return Math[func](value * factor) / factor;
};
export const average = (a: number, b: number) => (a + b) / 2;