src/main/java/Kata.java
/**
     * The heart of the filtering: remove all lonely points.
     *
     * For each point, create a map of occupied grid places.
     * For any occupied grid places, if they only contain one
     * point check if they are really alone by checking for
     * non-empty grid places in their "Moore neighborhood".
     * If it's lonely remove it.
     *
     * Grid size (gs) is sqrt(shortest) / 2
     * Coordinate is [round((x-minX)/gs), round((y-minY)/gs)] (rounded to nearest ints)
     */
The heart of the filtering: remove all lonely points.
For each point, create a map of occupied grid places.
For any occupied grid places, if they only contain one
point check if they are really alone by checking for
non-empty grid places in their "Moore neighborhood".
If it's lonely remove it.


The heart of the filtering : remove all lonely points . For each point create a map of occupied grid places . For any occupied grid places if they only contain one point check if they are really alone by checking for non - empty grid places in their " Moore neighborhood " . If it ' s lonely remove it .
private void removeLoneOnes() {
        /* create map points to coordinate
         * create map of coordinates with counts of neighbours
         * for each point
         *    add its coordinate
         *    inc its neighbour counts (including itself)
         */
        double gs = Math.sqrt(shortest) / FACTOR;
        int gw = (int) Math.ceil((boxLx - boxSx) / gs);
        Map<Point, Integer> coordinates = new HashMap<>();
        Set<Integer> neighbours = new HashSet<>();
        for (Point p : points) {
            int key = (int) Math.round(p.x / gs) + gw * (int) Math.round(p.y / gs);
            coordinates.put(p, key);
            for (int i = -1; i <= 1; i++) {
                for (int j = -1; j <= 1; j++) {
                    if (i != 0 && j != 0){
                        int neighbour = key + i + j * gw;
                        neighbours.add(neighbour);
                    }
                }
            }
        }
        for (Point p: coordinates.keySet()) {
            int key = coordinates.get(p);
            if (!neighbours.contains(key)) { 
                points.remove(p);
            }
        }
    }
private void removeLoneOnes ( ) { /* create map points to coordinate
         * create map of coordinates with counts of neighbours
         * for each point
         *    add its coordinate
         *    inc its neighbour counts (including itself)
         */ double gs = Math . sqrt ( shortest ) / FACTOR ; int gw = ( int ) Math . ceil ( ( boxLx - boxSx ) / gs ) ; Map < Point , Integer > coordinates = new HashMap < > ( ) ; Set < Integer > neighbours = new HashSet < > ( ) ; for ( Point p : points ) { int key = ( int ) Math . round ( p . x / gs ) + gw * ( int ) Math . round ( p . y / gs ) ; coordinates . put ( p , key ) ; for ( int i = - 1 ; i <= 1 ; i ++ ) { for ( int j = - 1 ; j <= 1 ; j ++ ) { if ( i != 0 && j != 0 ) { int neighbour = key + i + j * gw ; neighbours . add ( neighbour ) ; } } } } for ( Point p : coordinates . keySet ( ) ) { int key = coordinates . get ( p ) ; if ( ! neighbours . contains ( key ) ) { points . remove ( p ) ; } } }
The heart of the filtering: remove all lonely points.
The heart of the filtering : remove all lonely points .
// convert point into an integer "coordinate" // convert "coordinate" into neighbour "coordinate" // no neighbours so remove it