UNPKG

db-lgtv-focus-engine

Version:

the Best TV focus engine

26 lines (23 loc) 667 B
function dbPoint(x, y) { this.x = x this.y = y } dbPoint.prototype.getDistance = function (_p) { let øx = Math.abs(_p.x - this.x) let øy = Math.abs(_p.y - this.y) let distance = Math.sqrt(Math.pow(øx, 2) + Math.pow(øy, 2)) return distance } dbPoint.prototype.getWeightDistance = function (_p, direction) { let øx = Math.abs(_p.x - this.x) let øy = Math.abs(_p.y - this.y) if (['top', 'bottom'].includes(direction)) { øy *= 4 } if (['left', 'right'].includes(direction)) { øx *= 2 } let distance = Math.sqrt(Math.pow(øx, 2) + Math.pow(øy, 2)) return distance } export default dbPoint