summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-04-06 23:48:02 +0200
committerAki <please@ignore.pl>2021-04-06 23:48:02 +0200
commit860da5f151357831db92a2be64c2edb829b9a953 (patch)
treed1533e280917ce23cde47c8bd9cf4a121cf80f0a
parent2dff3184ba302216ce89fb4ca2b5581e471bbdce (diff)
downloadderelict-prototype-860da5f151357831db92a2be64c2edb829b9a953.zip
derelict-prototype-860da5f151357831db92a2be64c2edb829b9a953.tar.gz
derelict-prototype-860da5f151357831db92a2be64c2edb829b9a953.tar.bz2
Refactored center calculation
-rw-r--r--derelict.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/derelict.js b/derelict.js
index 739bbfa..573e7f9 100644
--- a/derelict.js
+++ b/derelict.js
@@ -102,12 +102,14 @@ function splitKillmails(clusters, killmail) {
return clusters
}
+function averagePosition(positions) {
+ const sum = positions.reduce((sum, pos) => sum.add(pos), new THREE.Vector3())
+ return sum.divideScalar(positions.length)
+}
+
function processKillmails(grid, killmails, icon) {
let clusters = killmails.reduce(splitKillmails, new Array())
- let center = new THREE.Vector3()
- let positions = clusters[0].map(km => km.victim.position)
- positions.forEach(pos => center.add(new THREE.Vector3(pos.x, pos.y, pos.z)))
- center.divideScalar(positions.length)
+ let center = averagePosition(clusters[0].map(km => km.victim.position))
clusters[0].sort((a, b) => a.killmail_time.localeCompare(b.killmail_time))
let elements = []
clusters[0].forEach(killmail => {