summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--derelict.js35
1 files changed, 18 insertions, 17 deletions
diff --git a/derelict.js b/derelict.js
index 9a28f07..739bbfa 100644
--- a/derelict.js
+++ b/derelict.js
@@ -85,24 +85,25 @@ function loadWreckIcon() {
})
}
+function vec3FromXYZ({x, y, z}) {
+ return new THREE.Vector3(x, y, z)
+}
+
+function splitKillmails(clusters, killmail) {
+ const vec3 = vec3FromXYZ(killmail.victim.position)
+ const found = clusters.find(cluster => cluster[0].victim.position.distanceTo(vec3) < 100 * SCALE)
+ killmail.victim.position = vec3
+ if (found === undefined) {
+ clusters.push([killmail])
+ }
+ else {
+ found.push(killmail)
+ }
+ return clusters
+}
+
function processKillmails(grid, killmails, icon) {
- let clusters = []
- killmails.forEach(km => {
- const pos = km.victim.position
- km.victim.position = new THREE.Vector3(pos.x, pos.y, pos.z)
- const vec3 = km.victim.position
- let added = false
- for (const cluster of clusters) {
- if (cluster[0].victim.position.distanceTo(vec3) < 100 * SCALE) {
- cluster.push(km)
- added = true
- break
- }
- }
- if (!added) {
- clusters.push([km])
- }
- })
+ 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)))