vtm-core: reorder Box code (#615)
This commit is contained in:
parent
0271e9df23
commit
357ec99b44
@ -57,6 +57,28 @@ public class Box {
|
|||||||
this.ymax = bbox.ymax;
|
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.
|
* Check if Box contains point defined by coordinates x and y.
|
||||||
*
|
*
|
||||||
@ -81,6 +103,21 @@ public class Box {
|
|||||||
&& p.y <= ymax);
|
&& 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.
|
* Check if this Box is inside box.
|
||||||
*/
|
*/
|
||||||
@ -91,12 +128,18 @@ public class Box {
|
|||||||
&& ymax <= box.ymax;
|
&& ymax <= box.ymax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getWidth() {
|
/**
|
||||||
return xmax - xmin;
|
* convrt map coordinates to lat/lon.
|
||||||
}
|
*/
|
||||||
|
public void map2mercator() {
|
||||||
public double getHeight() {
|
double minLon = MercatorProjection.toLongitude(xmin);
|
||||||
return ymax - ymin;
|
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) {
|
public boolean overlap(Box other) {
|
||||||
@ -106,16 +149,11 @@ public class Box {
|
|||||||
|| ymax < other.ymin);
|
|| ymax < other.ymin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void scale(double d) {
|
||||||
public String toString() {
|
xmin *= d;
|
||||||
return "[" + xmin + ',' + ymin + ',' + xmax + ',' + ymax + ']';
|
xmax *= d;
|
||||||
}
|
ymin *= d;
|
||||||
|
ymax *= d;
|
||||||
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 setExtents(float[] points) {
|
public void setExtents(float[] points) {
|
||||||
@ -142,26 +180,9 @@ public class Box {
|
|||||||
this.ymax = y2;
|
this.ymax = y2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Box bbox) {
|
@Override
|
||||||
if (bbox.xmin < xmin)
|
public String toString() {
|
||||||
xmin = bbox.xmin;
|
return "[" + xmin + ',' + ymin + ',' + xmax + ',' + ymax + ']';
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void translate(double dx, double dy) {
|
public void translate(double dx, double dy) {
|
||||||
@ -170,25 +191,4 @@ public class Box {
|
|||||||
ymin += dy;
|
ymin += dy;
|
||||||
ymax += 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user