summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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 => {