UNPKG

744 BJavaScriptView Raw
1const euclideanDistance = require('./euclidean_distance');
2
3const FINE_TOLERANCE = 4;
4const GROSS_TOLERANCE = 12;
5const INTERVAL = 500;
6
7module.exports = function isClick(start, end, options = {}) {
8 const fineTolerance = (options.fineTolerance != null) ? options.fineTolerance : FINE_TOLERANCE;
9 const grossTolerance = (options.grossTolerance != null) ? options.grossTolerance : GROSS_TOLERANCE;
10 const interval = (options.interval != null) ? options.interval : INTERVAL;
11
12 start.point = start.point || end.point;
13 start.time = start.time || end.time;
14 const moveDistance = euclideanDistance(start.point, end.point);
15
16 return moveDistance < fineTolerance ||
17 (moveDistance < grossTolerance && (end.time - start.time) < interval);
18};