Jump to content

ArrayList to Area


Iwin

Recommended Posts

I'm currently working on a area plotter.

Simply, you click on the screen.. it adds the location (X, Y, Z) into an ArrayList..

 

	ArrayList<Position> areaList = new ArrayList<>();

But to visually see the area.. you have to convert the arraylist into an Area

Example:

	Area chickenArea = new Area(new Position[] { new Position(3171, 3289, 0), new Position(3169, 3291, 0),
			new Position(3169, 3294, 0), new Position(3170, 3295, 0), new Position(3170, 3298, 0),
			new Position(3169, 3299, 0), new Position(3173, 3303, 0), new Position(3173, 3307, 0),
			new Position(3179, 3307, 0), new Position(3180, 3303, 0), new Position(3182, 3303, 0),
			new Position(3184, 3302, 0), new Position(3185, 3300, 0), new Position(3186, 3298, 0),
			new Position(3186, 3295, 0), new Position(3185, 3290, 0), new Position(3183, 3289, 0),
			new Position(3178, 3289, 0), new Position(3177, 3288, 0), new Position(3174, 3288, 0), });

If you just use the arraylist to draw a tile, it only plots those specific locations.

Any and all help is greatly appreciated :)

Link to comment
Share on other sites

I'm currently working on a area plotter.

Simply, you click on the screen.. it adds the location (X, Y, Z) into an ArrayList..

 

	ArrayList<Position> areaList = new ArrayList<>();

But to visually see the area.. you have to convert the arraylist into an Area

Any and all help is greatly appreciated smile.png

List<Position> posList = new ArrayList<>();
Position[] positions = posList.toArray(new Position[posList.size()]);

Or

List<Position> posList = new ArrayList<>();
Position[] positions = posList.stream().toArray(Position[]::new);
Edited by Explv
  • Like 1
Link to comment
Share on other sites

For some reason I get this result :|

 

d28098daca004fc2aa9d77ba66112ddd.png

 

If you just want to create a rectangular area then you should use the:

Area(int x1, int y1, int x2, int y2)
Constructs a rectangular area using x and y coordinates from two separate positions.

Or

Area(Position southWest, Position northEast)
Constructs a rectangular area using two positions 

Constructors.

Link to comment
Share on other sites

Every time you add or remove a position from that area, you should be reconstructing that Area using the new positions in the list (after converting to an array). Or is your issue converting from a list to an array?

My issue was converting:

 

ArrayList<Position> posList = new ArrayList<>();

To an Area.

but as posted above, my issue was solved. Unless this can be make more efficient (which is more than welcome)

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