Jump to content

Get bounding tiles of Area


Recommended Posts

Posted

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;

    }

}

Posted
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. 

Posted

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);
		}

 

Posted
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

Posted
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...