tapspace
Version:
A zoomable user interface lib for web apps
28 lines (23 loc) • 723 B
JavaScript
const BasisComponent = require('../../components/BasisComponent')
const findAffineAncestor = BasisComponent.findAffineAncestor
module.exports = (pointers) => {
// Find affine target for the given set of sensed pointers.
// Basically picks the first target.
//
// Parameters:
// pointers
// a map from pointer id to {x,y,target}
//
// Return
// a BasisComponent
//
const ids = Object.keys(pointers)
if (ids.length > 0) {
const firstId = ids[0]
const firstPointer = pointers[firstId]
const firstTarget = firstPointer.target
return findAffineAncestor(firstTarget)
}
// If no pointers, it is an error
throw new Error('cannot find target from empty set of pointers.')
}