SimpleNode closestTo(final SimpleNode from, final double length) {
		// Check if the link lengths have already been computed, and if not compute them.
		if (linkLengths.get(from.index).isEmpty()) {
			final ArrayList<DistanceEntry> distances = linkLengths.get(from.index);
			for (SimpleNode peer : nodes) {
				if (peer == from) continue;
				distances.add(new DistanceEntry(from.distanceTo(peer), peer));
			}
			Collections.sort(distances);
		}

		final ArrayList<DistanceEntry> distances = linkLengths.get(from.index);
		assert !distances.isEmpty();
		int index = Collections.binarySearch(distances, new DistanceEntry(length, null));
		// Choose closest match. If not found index = -(insertion point) - 1, so insertion point = -1 - index.
		if (index < 0) index = -1 - index;
		if (index == distances.size()) index = distances.size() - 1;

		return distances.get(index).node;
	}