Jump to content

Get bounding tiles of Area


Polymorphism

Recommended Posts

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;

    }

}

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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