devexpress-richedit
Version:
DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.
29 lines (28 loc) • 803 B
JavaScript
export class DoubleTapDetector {
constructor(maxDistance, maxInterval) {
this.maxDistance = maxDistance;
this.maxInterval = maxInterval;
this.lastTime = null;
this.lastX = -1;
this.lastY = -1;
}
isDoubleTap(x, y) {
const now = Date.now();
const result = this.lastTime !== null &&
(now - this.lastTime) < this.maxInterval &&
Math.abs(x - this.lastX) <= this.maxDistance &&
Math.abs(y - this.lastY) <= this.maxDistance;
if (result) {
this.reset();
}
else {
this.lastTime = now;
this.lastX = x;
this.lastY = y;
}
return result;
}
reset() {
this.lastTime = null;
}
}