Jump to content

ArrayList to Area


Recommended Posts

Posted

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 :)

Posted (edited)

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
Posted

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.

Posted

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)

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