mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: improve canvas search scroll behavior further (#8491)
This commit is contained in:
parent
b46ca0192b
commit
fd39712ba6
8 changed files with 165 additions and 99 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue