fix nearest aetheryte finder

This commit is contained in:
2024-07-15 21:09:14 +02:00
parent f7ac1725f9
commit c00e4178c5
+4 -4
View File
@@ -67,18 +67,18 @@ 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) {
if (aetheryte.position.zone !== zone) continue;
const a = aetheryte.position.x - x;
const b = aetheryte.position.y - y;
const distanceToAetheryte = Math.sqrt((a * a) + (b * b));
const distanceToAetheryte = Math.hypot(a, b);
if (distanceToAetheryte < distance) {
`Aetheryte ${aetheryte.name.en} (${distance}) is new nearest aetheryte`;
distance = distanceToAetheryte;
result = aetheryte;
}
}
}
return result;
}
},