From 4d7f9f815085302467a9bcaceee57856fb92cb19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Proch=C3=A1zka?= <david@prochazka.dev>
Date: Fri, 26 Feb 2021 16:39:28 +0100
Subject: [PATCH] FIX: updated addition of an object to the closest node

---
 src/mhtree/BuildTree.java | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/mhtree/BuildTree.java b/src/mhtree/BuildTree.java
index cf0e98c..b8b7c9f 100644
--- a/src/mhtree/BuildTree.java
+++ b/src/mhtree/BuildTree.java
@@ -127,14 +127,9 @@ class BuildTree {
     private void addObjectToClosestNode(int objectIndex) throws BucketStorageException {
         LocalAbstractObject object = objectDistances.getObject(objectIndex);
 
-        Function<Node, Float> getMinHullObjectDistance = node -> node.getHullObjects().stream()
-                .map(object::getDistance)
-                .reduce(Float.MAX_VALUE, Math::min);
+        Map<Node, Double> nodeToObjectDistance = Arrays.stream(nodes)
+                .collect(Collectors.toMap(Function.identity(), node -> node.getDistance(object)));
 
-        Map<Node, Float> nodeToObjectDistance = Arrays.stream(nodes)
-                .collect(Collectors.toMap(Function.identity(), getMinHullObjectDistance));
-
-        // Add object to the node with minimal distance to this object
         Collections.min(nodeToObjectDistance.entrySet(), Map.Entry.comparingByValue()).getKey().addObject(object);
     }
 
-- 
GitLab