Polymorphism Posted February 9, 2017 Posted February 9, 2017 (edited) I've tried all sorts of different way to get this. What I'm look for is the outside tiles of an Area or Position[] I hate to ask on here, but I really could use this help if anyone has any input. Thank you ahead of time. Edited February 9, 2017 by Polymorphism
Team Cape Posted February 9, 2017 Posted February 9, 2017 would be easy to do this with a rectangular area, but you'd need a little bit of work with a poly area. This was something that I quickly wrote out, but the idea is there. Would be interested to see other peoples' solvencies. might do something like this: class Rectanglarea extends Area { private final int x1, y1, x2, y2; public Rectanglarea(int x1, int y1, int x2, int y2) { super(x1, y1, x2, y2); this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; } public List<Position> getOuterPositions() { List<Position> outerPositions = new ArrayList<>(); for(int y = y1; y <= y2; y++) { outerPositions.add(new Position(x1, y, getZ())); outerPositions.add(new Position(x2, y, getZ())); } for(int x = x1; x <= x2; x++) { outerPositions.add(new Position(x, y1, getZ())); outerPositions.add(new Position(x, y2, getZ())); } return outerPositions; } }
Polymorphism Posted February 9, 2017 Author Posted February 9, 2017 12 minutes ago, Imateamcape said: would be easy to do this with a rectangular area, but you'd need a little bit of work with a poly area. This was something that I quickly wrote out, but the idea is there. Would be interested to see other peoples' solvencies. might do something like this: class Rectanglarea extends Area { private final int x1, y1, x2, y2; public Rectanglarea(int x1, int y1, int x2, int y2) { super(x1, y1, x2, y2); this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; } public List<Position> getOuterPositions() { List<Position> outerPositions = new ArrayList<>(); for(int y = y1; y <= y2; y++) { outerPositions.add(new Position(x1, y, getZ())); outerPositions.add(new Position(x2, y, getZ())); } for(int x = x1; x <= x2; x++) { outerPositions.add(new Position(x, y1, getZ())); outerPositions.add(new Position(x, y2, getZ())); } return outerPositions; } } Yeah, mine is a variable Polygon area which is dynamically generated based on player position and settings. That's where my issue comes into play.
Polymorphism Posted February 9, 2017 Author Posted February 9, 2017 For my situation this worked, but still looking for something that is universal for Polygon Area. safeArea = new Area(new Position(sX - is.maxDistance, sY - is.maxDistance, sZ), new Position(sX + is.maxDistance, sY + is.maxDistance, sZ)); safeTiles = safeArea.getPositions(); bounding = new Position[safeTiles.size()]; for (int i = 0; i < safeTiles.size(); i++) { if (safeTiles.get(i).distance(startPosition) == is.maxDistance) bounding[i] = safeTiles.get(i); }
Team Cape Posted February 9, 2017 Posted February 9, 2017 13 minutes ago, Polymorphism said: For my situation this worked, but still looking for something that is universal for Polygon Area. safeArea = new Area(new Position(sX - is.maxDistance, sY - is.maxDistance, sZ), new Position(sX + is.maxDistance, sY + is.maxDistance, sZ)); safeTiles = safeArea.getPositions(); bounding = new Position[safeTiles.size()]; for (int i = 0; i < safeTiles.size(); i++) { if (safeTiles.get(i).distance(startPosition) == is.maxDistance) bounding[i] = safeTiles.get(i); } well whats the scenario where you need to get the bounding tiles? there might be a more efficient way around creating this code
Polymorphism Posted February 9, 2017 Author Posted February 9, 2017 11 hours ago, Imateamcape said: well whats the scenario where you need to get the bounding tiles? there might be a more efficient way around creating this code In my case it's simply for drawing the outside of an area vs all tiles of the area. My script uses a max travel distance , so in my case all i gotta do is draw tiles that are so far away. But this will be a bit different if the radius (circles I know, but relative enough) is unknown