Make gesture.pointers a Map instead of an array of pointers (#877)

This commit is contained in:
Pete Hunt 2020-03-08 19:25:16 -07:00 committed by GitHub
parent 92ba401da8
commit 8d8f9f23bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 30 deletions

View file

@ -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);
}