خرید بک لینک

Vote count: 0

I'm trying to print out locations of center dots. Compared dots must be in radius of 16. Printing out only if there is more than 5 dots in one place calculating from center.

Center dot is, which is nearest to all nearby dots

My code is giving me fale positives and duplicates. Methods:

HashMap<Location, HashSet<Location>> map = new HashMap<Location, HashSet<Location>>();
for (LocationCopy loc : locs) {
        HashSet<LocationCopy> locsCopy = new HashSet<LocationCopy>(locs);
        locsCopy.remove(loc);
        for (LocationCopy loc2 : locsCopy) {
            if (distance(loc2.getX(),loc.getX(),loc2.getZ(),loc.getZ()) <= 16) {
                if (!map.containsKey(loc.getLoc())) {
                    HashSet<Location> hs = new HashSet<Location>();
                    hs.add(loc2.getLoc());
                    map.put(loc2.getLoc(), hs);
                } else {
                    HashSet<Location> hs = map.get(loc.getLoc());
                    hs.add(loc2.getLoc());
                    map.put(loc2.getLoc(), hs);
                }
            }
        }

    }

    for (Location loc : map.keySet()) {
        if (map.get(loc).size() > 5) {
            write("More than " + map.get(loc).size() + locToString(loc) + ": " + getLocs(map.get(loc)) + "<br>", fileName, beta);
        }
    }

private double distance(double x1, double x2, double z1, double z2){
    retu Math.sqrt(Math.pow(x2-x1,2)+Math.pow(z2-z1,2));
}

Class:

public class LocationCopy {
private int x, y, z;
private String world;

public LocationCopy(int x, int y, int z, String world) {
    this.x = x;
    this.y = y;
    this.z = z;
    this.world = world;
}

public LocationCopy(Location spawner) {
    this.x = spawner.getBlockX();
    this.y = spawner.getBlockY();
    this.z = spawner.getBlockZ();
    this.world = spawner.getWorld().getName();
}

public int getX(){
    retu x;
}

public int getZ(){
    retu z;
}

public Location getLoc() {
    retu new Location(Bukkit.getWorld(world), x, y, z);
}

}

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 16 فروردين 1395 ساعت: 19:52

صفحه بندی