snapshot of https://github.com/excalidraw/excalidraw.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Tests / test (push) Failing after 15s
Some checks failed
Tests / test (push) Failing after 15s
This commit is contained in:
15
packages/excalidraw/gesture.ts
Normal file
15
packages/excalidraw/gesture.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { PointerCoords } from "./types";
|
||||
|
||||
export const getCenter = (pointers: Map<number, PointerCoords>) => {
|
||||
const allCoords = Array.from(pointers.values());
|
||||
return {
|
||||
x: sum(allCoords, (coords) => coords.x) / allCoords.length,
|
||||
y: sum(allCoords, (coords) => coords.y) / allCoords.length,
|
||||
};
|
||||
};
|
||||
|
||||
export const getDistance = ([a, b]: readonly PointerCoords[]) =>
|
||||
Math.hypot(a.x - b.x, a.y - b.y);
|
||||
|
||||
const sum = <T>(array: readonly T[], mapper: (item: T) => number): number =>
|
||||
array.reduce((acc, item) => acc + mapper(item), 0);
|
||||
Reference in New Issue
Block a user