mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Make gesture.pointers a Map instead of an array of pointers (#877)
This commit is contained in:
parent
92ba401da8
commit
8d8f9f23bd
3 changed files with 25 additions and 30 deletions
|
@ -1,14 +1,15 @@
|
|||
import { Pointer } from "./types";
|
||||
import { PointerCoords } from "./types";
|
||||
import { normalizeScroll } from "./scene";
|
||||
|
||||
export function getCenter(pointers: readonly Pointer[]) {
|
||||
export function getCenter(pointers: Map<number, PointerCoords>) {
|
||||
const allCoords = Array.from(pointers.values());
|
||||
return {
|
||||
x: normalizeScroll(sum(pointers, pointer => pointer.x) / pointers.length),
|
||||
y: normalizeScroll(sum(pointers, pointer => pointer.y) / pointers.length),
|
||||
x: normalizeScroll(sum(allCoords, coords => coords.x) / allCoords.length),
|
||||
y: normalizeScroll(sum(allCoords, coords => coords.y) / allCoords.length),
|
||||
};
|
||||
}
|
||||
|
||||
export function getDistance([a, b]: readonly Pointer[]) {
|
||||
export function getDistance([a, b]: readonly PointerCoords[]) {
|
||||
return Math.hypot(a.x - b.x, a.y - b.y);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue