vtm-core: reorder Box code (#615)

This commit is contained in:
Gustl22 2018-12-09 21:27:10 +01:00 committed by Emux
parent 0271e9df23
commit 357ec99b44
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3

View File

@ -57,6 +57,28 @@ public class Box {
this.ymax = bbox.ymax;
}
public void add(double x, double y) {
if (x < xmin)
xmin = x;
if (y < ymin)
ymin = y;
if (x > xmax)
xmax = x;
if (y > ymax)
ymax = y;
}
public void add(Box bbox) {
if (bbox.xmin < xmin)
xmin = bbox.xmin;
if (bbox.ymin < ymin)
ymin = bbox.ymin;
if (bbox.xmax > xmax)
xmax = bbox.xmax;
if (bbox.ymax > ymax)
ymax = bbox.ymax;
}
/**
* Check if Box contains point defined by coordinates x and y.
*
@ -81,6 +103,21 @@ public class Box {
&& p.y <= ymax);
}
public static Box createSafe(double x1, double y1, double x2, double y2) {
return new Box(x1 < x2 ? x1 : x2,
y1 < y2 ? y1 : y2,
x1 > x2 ? x1 : x2,
y1 > y2 ? y1 : y2);
}
public double getHeight() {
return ymax - ymin;
}
public double getWidth() {
return xmax - xmin;
}
/**
* Check if this Box is inside box.
*/
@ -91,12 +128,18 @@ public class Box {
&& ymax <= box.ymax;
}
public double getWidth() {
return xmax - xmin;
}
public double getHeight() {
return ymax - ymin;
/**
* convrt map coordinates to lat/lon.
*/
public void map2mercator() {
double minLon = MercatorProjection.toLongitude(xmin);
double maxLon = MercatorProjection.toLongitude(xmax);
double minLat = MercatorProjection.toLatitude(ymax);
double maxLat = MercatorProjection.toLatitude(ymin);
xmin = minLon;
xmax = maxLon;
ymin = minLat;
ymax = maxLat;
}
public boolean overlap(Box other) {
@ -106,16 +149,11 @@ public class Box {
|| ymax < other.ymin);
}
@Override
public String toString() {
return "[" + xmin + ',' + ymin + ',' + xmax + ',' + ymax + ']';
}
public static Box createSafe(double x1, double y1, double x2, double y2) {
return new Box(x1 < x2 ? x1 : x2,
y1 < y2 ? y1 : y2,
x1 > x2 ? x1 : x2,
y1 > y2 ? y1 : y2);
public void scale(double d) {
xmin *= d;
xmax *= d;
ymin *= d;
ymax *= d;
}
public void setExtents(float[] points) {
@ -142,26 +180,9 @@ public class Box {
this.ymax = y2;
}
public void add(Box bbox) {
if (bbox.xmin < xmin)
xmin = bbox.xmin;
if (bbox.ymin < ymin)
ymin = bbox.ymin;
if (bbox.xmax > xmax)
xmax = bbox.xmax;
if (bbox.ymax > ymax)
ymax = bbox.ymax;
}
public void add(double x, double y) {
if (x < xmin)
xmin = x;
if (y < ymin)
ymin = y;
if (x > xmax)
xmax = x;
if (y > ymax)
ymax = y;
@Override
public String toString() {
return "[" + xmin + ',' + ymin + ',' + xmax + ',' + ymax + ']';
}
public void translate(double dx, double dy) {
@ -170,25 +191,4 @@ public class Box {
ymin += dy;
ymax += dy;
}
public void scale(double d) {
xmin *= d;
xmax *= d;
ymin *= d;
ymax *= d;
}
/**
* convrt map coordinates to lat/lon.
*/
public void map2mercator() {
double minLon = MercatorProjection.toLongitude(xmin);
double maxLon = MercatorProjection.toLongitude(xmax);
double minLat = MercatorProjection.toLatitude(ymax);
double maxLat = MercatorProjection.toLatitude(ymin);
xmin = minLon;
xmax = maxLon;
ymin = minLat;
ymax = maxLat;
}
}