Re: Tricky Data Type Needed
"Brian Bagnall" <bbagnall@mts.net> wrote in message
news:kTJhh.14766$gj2.5136@newsfe23.lga...
Hi,
I'm writing a program that will store map data. Basically a 2-dimensional
array with values for x, y coordinates:
byte [][] pos
So to access data as perhaps x=90 and y=35, I would use:
int val = pos[90][35];
However, in a coordinate system, there are -ve and +ve values for x and
y. So an array really doesn't work too good here since I can't use -ve
values to access points on the map.
Also, the array needs to grow dynamically. Say it starts out as a map with
100 x 100, but later it finds other areas to map, it could grow to 100 x
120, or perhaps 120 x 100 (depending if the x axis or y axis needs to
grow).
Furthermore, the robot will start at 0,0 (origin) and needs to be able to
expand in either direction, either -ve or +ve.
Anyone have any suggestions for a good way to store this data in an
orderly, efficient manner while giving easy access/storage for data?
If you know the limit of growth goes up to 120, then just set the array
size to be [120][120], and ignore the extra space. If it can grow
arbitrarily large, consider a DataStructure like Hendrik Maryns suggested
(though I'd probably use Map<Pair<Integer,Integer>,Byte> rather than
List<List>).
Not sure I understand the -ve, +ve thing, but if you're just saying that
the center of a 100x100 grid is located at 0,0 (as opposed to 50,50), and so
the top left corner is at coordinate -50,-50, then the easy fix is to just
add 50 to any coordinates you receive.
getDataAtCoordinate(int x, int y) {
return myArray[x + 50][y + 50];
}
foo = getDataAtCoordinate(-50,-50);
- Oliver