/**
 * @文件说明: 判断是否为Click单击操作
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-05-22 14:27:14
 */

import euclideanDistance from './euclidean_distance';

var FINE_TOLERANCE = 4;
var GROSS_TOLERANCE = 12;
var INTERVAL = 500;

export default function isClick(start, end) {
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

  var fineTolerance = options.fineTolerance != null ? options.fineTolerance : FINE_TOLERANCE;
  var grossTolerance = options.grossTolerance != null ? options.grossTolerance : GROSS_TOLERANCE;
  var interval = options.interval != null ? options.interval : INTERVAL;

  start.point = start.point || end.point;
  start.time = start.time || end.time;
  var moveDistance = euclideanDistance(start.point, end.point);

  return moveDistance < fineTolerance || moveDistance < grossTolerance && end.time - start.time < interval;
}