2013-04-18 23:35:02 +02:00
|
|
|
package net.osmand.map;
|
|
|
|
|
|
|
|
import gnu.trove.list.array.TIntArrayList;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class RegionCountry {
|
|
|
|
public String continentName;
|
|
|
|
public int left, right, top, bottom;
|
2013-05-29 17:56:26 +02:00
|
|
|
public boolean subregionsVerified = true;
|
2013-04-18 23:35:02 +02:00
|
|
|
public String name;
|
|
|
|
public RegionCountry parent;
|
|
|
|
|
2013-05-29 17:12:28 +02:00
|
|
|
private TIntArrayList singleTiles = new TIntArrayList();
|
|
|
|
private TIntArrayList boxTiles = new TIntArrayList();
|
|
|
|
|
|
|
|
private TIntArrayList allTiles;
|
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
private List<RegionCountry> regions = new ArrayList<RegionCountry>();
|
2013-05-29 17:12:28 +02:00
|
|
|
|
|
|
|
public TIntArrayList getSingleTiles() {
|
|
|
|
return singleTiles;
|
|
|
|
}
|
|
|
|
public TIntArrayList getBoxTiles() {
|
|
|
|
return boxTiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String serializeTilesArray(){
|
|
|
|
StringBuilder bld = new StringBuilder();
|
|
|
|
for(int j = 0; j<boxTiles.size(); j+=4) {
|
|
|
|
if (j > 0) {
|
|
|
|
bld.append(";");
|
|
|
|
}
|
|
|
|
bld.append(boxTiles.get(j)).append(" ").append(boxTiles.get(j + 1));
|
|
|
|
bld.append(" x ");
|
|
|
|
bld.append(boxTiles.get(j + 2)).append(" ").append(boxTiles.get(j + 3));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < singleTiles.size(); i += 2) {
|
|
|
|
if (i > 0 || boxTiles.size() > 0) {
|
|
|
|
bld.append(";");
|
|
|
|
}
|
|
|
|
bld.append(singleTiles.get(i)).append(" ").append(singleTiles.get(i + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bld.toString();
|
|
|
|
}
|
2013-06-16 22:54:19 +02:00
|
|
|
|
|
|
|
public String serializeFlatTilesArray(){
|
|
|
|
TIntArrayList tiles = calcAllTiles();
|
|
|
|
StringBuilder bld = new StringBuilder();
|
|
|
|
for (int i = 0; i < tiles.size(); i += 2) {
|
|
|
|
if (i > 0) {
|
|
|
|
bld.append(";");
|
|
|
|
}
|
|
|
|
bld.append(tiles.get(i)).append(" ").append(tiles.get(i + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bld.toString();
|
|
|
|
}
|
2013-04-18 23:35:02 +02:00
|
|
|
|
2013-05-29 17:12:28 +02:00
|
|
|
|
|
|
|
public void removeSingle(int x, int y) {
|
|
|
|
for (int i = 0; i < singleTiles.size(); i += 2) {
|
|
|
|
if (singleTiles.get(i) == x && singleTiles.get(i + 1) == y) {
|
|
|
|
singleTiles.removeAt(i);
|
|
|
|
singleTiles.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
public void add(int xdeg, int ydeg) {
|
2013-05-29 17:12:28 +02:00
|
|
|
if (isEmpty()) {
|
2013-04-18 23:35:02 +02:00
|
|
|
left = right = xdeg;
|
|
|
|
top = bottom = ydeg;
|
|
|
|
}
|
|
|
|
left = Math.min(xdeg, left);
|
|
|
|
right = Math.max(xdeg, right);
|
|
|
|
bottom = Math.min(ydeg, bottom);
|
|
|
|
top = Math.max(ydeg, top);
|
2013-05-29 17:12:28 +02:00
|
|
|
singleTiles.add(xdeg);
|
|
|
|
singleTiles.add(ydeg);
|
|
|
|
allTiles = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void add(int xleft, int ytop, int xright, int ybottom) {
|
|
|
|
if (isEmpty()) {
|
|
|
|
left = xleft;
|
|
|
|
right = xright;
|
|
|
|
top = ytop;
|
|
|
|
bottom = ybottom;
|
|
|
|
}
|
|
|
|
left = Math.min(xleft, left);
|
|
|
|
right = Math.max(xright, right);
|
|
|
|
bottom = Math.min(ybottom, bottom);
|
|
|
|
top = Math.max(ytop, top);
|
|
|
|
boxTiles.add(xleft);
|
|
|
|
boxTiles.add(ytop);
|
|
|
|
boxTiles.add(xright);
|
|
|
|
boxTiles.add(ybottom);
|
|
|
|
allTiles = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEmpty() {
|
|
|
|
return singleTiles.size() == 0 && boxTiles.isEmpty();
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getTileSize() {
|
2013-05-29 17:12:28 +02:00
|
|
|
calcAllTiles();
|
|
|
|
return allTiles.size() / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected TIntArrayList calcAllTiles() {
|
|
|
|
if (allTiles == null) {
|
|
|
|
allTiles = new TIntArrayList(singleTiles);
|
|
|
|
for (int k = 0; k < boxTiles.size(); k += 4) {
|
|
|
|
for (int x = boxTiles.get(k); x <= boxTiles.get(k + 2); x++) {
|
|
|
|
for (int y = boxTiles.get(k + 1); y >= boxTiles.get(k + 3); y--) {
|
|
|
|
allTiles.add(x);
|
|
|
|
allTiles.add(y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return allTiles;
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getLon(int i) {
|
2013-05-29 17:12:28 +02:00
|
|
|
return calcAllTiles().get(i * 2);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getLat(int i) {
|
2013-05-29 17:12:28 +02:00
|
|
|
return calcAllTiles().get(i * 2 + 1);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addSubregion(RegionCountry c) {
|
|
|
|
c.parent = this;
|
|
|
|
regions.add(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<RegionCountry> getSubRegions() {
|
|
|
|
return regions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-11 01:46:38 +01:00
|
|
|
|
2013-05-29 17:12:28 +02:00
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|