From c00e4178c5d1464a1094b098c803572dce5826f9 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Mon, 15 Jul 2024 21:09:14 +0200 Subject: [PATCH] fix nearest aetheryte finder --- src/App.vue | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/App.vue b/src/App.vue index fbaf5fd..347d953 100644 --- a/src/App.vue +++ b/src/App.vue @@ -67,16 +67,16 @@ export default defineComponent({ methods: { findNearestAetheryte(zone: string, x: number, y: number): Aetheryte | null { let result = null; + let distance = Number.MAX_SAFE_INTEGER; for (const aetheryte of this.aetherytes) { - let distance = Number.MAX_VALUE; - if (aetheryte.position.zone === zone) { - const a = aetheryte.position.x - x; - const b = aetheryte.position.y - y; - const distanceToAetheryte = Math.sqrt((a * a) + (b * b)); - if (distanceToAetheryte < distance) { - distance = distanceToAetheryte; - result = aetheryte; - } + if (aetheryte.position.zone !== zone) continue; + const a = aetheryte.position.x - x; + const b = aetheryte.position.y - y; + const distanceToAetheryte = Math.hypot(a, b); + if (distanceToAetheryte < distance) { + `Aetheryte ${aetheryte.name.en} (${distance}) is new nearest aetheryte`; + distance = distanceToAetheryte; + result = aetheryte; } } return result;