  }

            var distance = neighbor.distance;
            if (distance <= maxThreshold) {
                neighbors.push(neighbor);
            }
        }
        return neighbors;
    }

    function seg_distance(seg1, seg2, field, weighted) {
        if (weighted) {
            return weighted_euclidean_distance(seg1[field], seg2[field]);
        } else {
            return euclidean_distance(seg1[field], seg2[field]);
        }
    }

    function euclidean_distance(v1, v2) {
        var sum = 0;

