src/worley.js
function distanceToNearest(coords, points, distanceType) {
        var color = Infinity,
            distanceFunc = 'distanceTo' + distanceType;
        for (var k = 0; k < points.length; k++) {
            var d = points[k][distanceFunc](coords);
            if (d < color) {
                color = d;
            }
        }
        return color;
    }
function distanceToNearest(coords, points, distanceType) {
        var color = Infinity,
            distanceFunc = 'distanceTo' + distanceType;
        for (var k = 0; k < points.length; k++) {
            var d = points[k][distanceFunc](coords);
            if (d < color) {
                color = d;
            }
        }
        return color;
    }
function distanceToNearest ( coords , points , distanceType ) { var color = Infinity , distanceFunc = 'distanceTo' + distanceType ; for ( var k = 0 ; k < points . length ; k ++ ) { var d = points [ k ] [ distanceFunc ] ( coords ) ; if ( d < color ) { color = d ; } } return color ; }
Find the Voronoi centroid closest to the current terrain vertex.

This approach is naive, but since the number of cells isn't typically
very big, it's plenty fast enough.

Alternatives approaches include using Fortune's algorithm or tracking
cells based on a grid.
Find the Voronoi centroid closest to the current terrain vertex .