Skip to content
Snippets Groups Projects
Commit 1f9713e3 authored by Powers, Peter M.'s avatar Powers, Peter M.
Browse files

added bounds() to region; removed min/max lat/lon methods and refactored

parent bb755fb6
No related branches found
No related tags found
1 merge request!96Bounds addition to location based objects
...@@ -471,9 +471,10 @@ public class GriddedRegion extends Region implements Iterable<Location> { ...@@ -471,9 +471,10 @@ public class GriddedRegion extends Region implements Iterable<Location> {
* Locations would coincide with grid nodes. * Locations would coincide with grid nodes.
*/ */
private void setAnchor(Location anchor) { private void setAnchor(Location anchor) {
if (anchor == null) anchor = Location.create(getMinLat(), getMinLon()); Bounds bounds = bounds();
double lat = computeAnchor(getMinLat(), anchor.lat(), latSpacing); if (anchor == null) anchor = Location.create(bounds.min().lat(), bounds.min().lon());
double lon = computeAnchor(getMinLon(), anchor.lon(), lonSpacing); double lat = computeAnchor(bounds.min().lat(), anchor.lat(), latSpacing);
double lon = computeAnchor(bounds.min().lon(), anchor.lon(), lonSpacing);
this.anchor = Location.create(lat, lon); this.anchor = Location.create(lat, lon);
} }
...@@ -491,13 +492,15 @@ public class GriddedRegion extends Region implements Iterable<Location> { ...@@ -491,13 +492,15 @@ public class GriddedRegion extends Region implements Iterable<Location> {
/* Initilize the grid index, node edge, and Location arrays */ /* Initilize the grid index, node edge, and Location arrays */
private void initNodes() { private void initNodes() {
Bounds bounds = bounds();
// temp node center arrays // temp node center arrays
double[] lonNodes = initNodeCenters(anchor.lon(), getMaxLon(), lonSpacing); double[] lonNodes = initNodeCenters(anchor.lon(), bounds.max().lon(), lonSpacing);
double[] latNodes = initNodeCenters(anchor.lat(), getMaxLat(), latSpacing); double[] latNodes = initNodeCenters(anchor.lat(), bounds.max().lat(), latSpacing);
// node edge arrays // node edge arrays
lonEdges = initNodeEdges(anchor.lon(), getMaxLon(), lonSpacing); lonEdges = initNodeEdges(anchor.lon(), bounds.max().lon(), lonSpacing);
latEdges = initNodeEdges(anchor.lat(), getMaxLat(), latSpacing); latEdges = initNodeEdges(anchor.lat(), bounds.max().lat(), latSpacing);
// range data // range data
latSize = latNodes.length; latSize = latNodes.length;
......
...@@ -283,35 +283,15 @@ public class Region implements Named { ...@@ -283,35 +283,15 @@ public class Region implements Named {
} }
/** /**
* Returns the minimum latitude in this {@code Region}'s border. * Lazily create the bounds of this region.
* @return the minimum latitude
*/ */
public double getMinLat() { public Bounds bounds() {
return area.getBounds2D().getMinY(); Rectangle2D bounds = area.getBounds2D();
} return new Bounds(
bounds.getMinY(),
/** bounds.getMinX(),
* Returns the maximum latitude in this {@code Region}'s border. bounds.getMaxY(),
* @return the maximum latitude bounds.getMaxX());
*/
public double getMaxLat() {
return area.getBounds2D().getMaxY();
}
/**
* Returns the minimum longitude in this {@code Region}'s border.
* @return the minimum longitude
*/
public double getMinLon() {
return area.getBounds2D().getMinX();
}
/**
* Returns the maximum longitude in this {@code Region}'s border.
* @return the maximum longitude
*/
public double getMaxLon() {
return area.getBounds2D().getMaxX();
} }
/** /**
...@@ -343,9 +323,10 @@ public class Region implements Named { ...@@ -343,9 +323,10 @@ public class Region implements Named {
} }
@Override public String toString() { @Override public String toString() {
String str = "Region\n" + "\tMinLat: " + this.getMinLat() + "\n" + "\tMinLon: " + Bounds b = bounds();
this.getMinLon() + "\n" + "\tMaxLat: " + this.getMaxLat() + "\n" + "\tMaxLon: " + String str = "Region\n" + "\tMinLat: " + b.min().lat() + "\n" + "\tMinLon: " +
this.getMaxLon(); b.min().lon() + "\n" + "\tMaxLat: " + b.max().lat() + "\n" + "\tMaxLon: " +
b.max().lon();
return str; return str;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment