utils/map/cluster.js
function clusterByNeighbor(points) {
    const sorted = points.slice().sort((a, b) => {
        if (a.y < b.y) {
            return -1;
        } else if (a.y > b.y) {
            return 1;
        } else {
            if (a.x < b.x) {
                return -1;
            } else if (a.x > b.x) {
                return 1;
            } else {
                return 0;
            }
        }
    });

    const cluster = sorted.reduce((sets, point) => {
        const setContainingNeighbors = sets.find(set => set.some((setPoint) => {
            return getNeighbors(setPoint).some(spn => areEqual(spn, point));
        }));

        if (setContainingNeighbors) {
            setContainingNeighbors.push(point);
        } else {
            sets.push([point]);
        }

        return sets;
    }, []);

    return cluster;
}
function clusterByNeighbor(points) {
    const sorted = points.slice().sort((a, b) => {
        if (a.y < b.y) {
            return -1;
        } else if (a.y > b.y) {
            return 1;
        } else {
            if (a.x < b.x) {
                return -1;
            } else if (a.x > b.x) {
                return 1;
            } else {
                return 0;
            }
        }
    });

    const cluster = sorted.reduce((sets, point) => {
        const setContainingNeighbors = sets.find(set => set.some((setPoint) => {
            return getNeighbors(setPoint).some(spn => areEqual(spn, point));
        }));

        if (setContainingNeighbors) {
            setContainingNeighbors.push(point);
        } else {
            sets.push([point]);
        }

        return sets;
    }, []);

    return cluster;
}
function clusterByNeighbor ( points ) { const sorted = points . slice ( ) . sort ( ( a , b ) => { if ( a . y < b . y ) { return - 1 ; } else if ( a . y > b . y ) { return 1 ; } else { if ( a . x < b . x ) { return - 1 ; } else if ( a . x > b . x ) { return 1 ; } else { return 0 ; } } } ) ; const cluster = sorted . reduce ( ( sets , point ) => { const setContainingNeighbors = sets . find ( set => set . some ( ( setPoint ) => { return getNeighbors ( setPoint ) . some ( spn => areEqual ( spn , point ) ) ; } ) ) ; if ( setContainingNeighbors ) { setContainingNeighbors . push ( point ) ; } else { sets . push ( [ point ] ) ; } return sets ; } , [ ] ) ; return cluster ; }
returns a cluster set where each cluster contains neighbor chains
@param {Array<Point2D>} points
@returns {Point2D[][]}
returns a cluster set where each cluster contains neighbor chains