Package ucar.unidata.geoloc
Class ProjectionRect
- java.lang.Object
-
- ucar.unidata.geoloc.ProjectionRect
-
@Immutable public class ProjectionRect extends Object
Bounding box for ProjectionPoints.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProjectionRect.Builder
-
Constructor Summary
Constructors Constructor Description ProjectionRect()
default constructor, initialized to center (0,0) and width (10000, 10000)ProjectionRect(double x1, double y1, double x2, double y2)
construct a ProjectionRect from any two opposite corner pointsProjectionRect(ProjectionPoint minimum, double width, double height)
Construct a ProjectionRect from any two opposite corner points.ProjectionRect(ProjectionPoint corner1, ProjectionPoint corner2)
Construct a ProjectionRect from any two opposite corner points.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ProjectionRect.Builder
builder()
static ProjectionRect.Builder
builder(double x1, double y1, double x2, double y2)
boolean
contains(ProjectionPoint point)
Returnstrue
if this bounding box containspoint
.boolean
contains(ProjectionRect rect)
Returnstrue
if this bounding box containsrect
.boolean
equals(Object o)
static ProjectionRect
fromSpec(String spec)
Construct a bounding box from a string, or null if incorrect format.double
getCenterX()
double
getCenterY()
double
getHeight()
ProjectionPoint
getLowerLeftPoint()
Get the Lower Right Point (same as getMinPoint)ProjectionPoint
getLowerRightPoint()
Get the Lower Right PointProjectionPoint
getMaxPoint()
Get the maximum corner of the bounding box.double
getMaxX()
double
getMaxY()
ProjectionPoint
getMinPoint()
Get the minimum corner of the bounding box.double
getMinX()
double
getMinY()
ProjectionPoint
getUpperLeftPoint()
Get the Upper Left PointProjectionPoint
getUpperRightPoint()
Get the Upper Left Point (same as getMaxPoint)double
getWidth()
int
hashCode()
static ProjectionRect
intersect(ProjectionRect src1, ProjectionRect src2)
Intersects the pair of specified sourceRectangle2D
objects and puts the result into the specified destinationRectangle2D
object.boolean
intersects(double x, double y, double w, double h)
boolean
intersects(ProjectionRect r)
boolean
isEmpty()
boolean
nearlyEquals(ProjectionRect other)
Returns the result ofnearlyEquals(ProjectionRect, double)
, withMisc.defaultMaxRelativeDiffFloat
.boolean
nearlyEquals(ProjectionRect other, double maxRelDiff)
Returnstrue
if this rectangle is nearly equal toother
.ProjectionRect.Builder
toBuilder()
Turn into a mutable Builder.String
toString()
Return a String representation of this ProjectionRect that can be used in new ProjectionRect(String): "x, y, width, height"String
toStringNDec(int ndec)
Get a String representation of this object, with user settable number of decomal places.
-
-
-
Constructor Detail
-
ProjectionRect
public ProjectionRect()
default constructor, initialized to center (0,0) and width (10000, 10000)
-
ProjectionRect
public ProjectionRect(ProjectionPoint corner1, ProjectionPoint corner2)
Construct a ProjectionRect from any two opposite corner points.- Parameters:
corner1
- a corner.corner2
- the opposite corner.
-
ProjectionRect
public ProjectionRect(ProjectionPoint minimum, double width, double height)
Construct a ProjectionRect from any two opposite corner points.- Parameters:
minimum
- lower left corner, ie the minimum x and ywidth
- x width.height
- y height
-
ProjectionRect
public ProjectionRect(double x1, double y1, double x2, double y2)
construct a ProjectionRect from any two opposite corner points- Parameters:
x1
- x coord of any corner of the bounding boxy1
- y coord of the same corner as x1x2
- x coord of opposite corner from x1,y1y2
- y coord of same corner as x2
-
-
Method Detail
-
fromSpec
@Nullable public static ProjectionRect fromSpec(String spec)
Construct a bounding box from a string, or null if incorrect format.- Parameters:
spec
- "startx, starty, width, height"
-
getWidth
public double getWidth()
-
getHeight
public double getHeight()
-
getMinX
public double getMinX()
-
getMinY
public double getMinY()
-
getMaxX
public double getMaxX()
-
getMaxY
public double getMaxY()
-
getCenterX
public double getCenterX()
-
getCenterY
public double getCenterY()
-
isEmpty
public boolean isEmpty()
-
intersects
public boolean intersects(ProjectionRect r)
-
intersects
public boolean intersects(double x, double y, double w, double h)
-
intersect
public static ProjectionRect intersect(ProjectionRect src1, ProjectionRect src2)
Intersects the pair of specified sourceRectangle2D
objects and puts the result into the specified destinationRectangle2D
object. One of the source rectangles can also be the destination to avoid creating a third Rectangle2D object, but in this case the original points of this source rectangle will be overwritten by this method.- Parameters:
src1
- the first of a pair ofRectangle2D
objects to be intersected with each othersrc2
- the second of a pair ofRectangle2D
objects to be intersected with each other- Returns:
- the
ProjectionRect
that holds the results of the intersection ofsrc1
andsrc2
- Since:
- 1.2
-
contains
public boolean contains(ProjectionPoint point)
Returnstrue
if this bounding box containspoint
.- Parameters:
point
- a point in projection coordinates.- Returns:
true
if this bounding box containspoint
.
-
contains
public boolean contains(ProjectionRect rect)
Returnstrue
if this bounding box containsrect
.- Parameters:
rect
- a bounding box in projection coordinates- Returns:
true
if this bounding box containsrect
.
-
getLowerRightPoint
public ProjectionPoint getLowerRightPoint()
Get the Lower Right Point- Returns:
- the Lower Right Point
-
getUpperRightPoint
public ProjectionPoint getUpperRightPoint()
Get the Upper Left Point (same as getMaxPoint)- Returns:
- the Upper Left Point
-
getLowerLeftPoint
public ProjectionPoint getLowerLeftPoint()
Get the Lower Right Point (same as getMinPoint)- Returns:
- the Lower Right Point
-
getUpperLeftPoint
public ProjectionPoint getUpperLeftPoint()
Get the Upper Left Point- Returns:
- the Upper Left Point
-
getMinPoint
public ProjectionPoint getMinPoint()
Get the minimum corner of the bounding box.- Returns:
- minimum corner of the bounding box
-
getMaxPoint
public ProjectionPoint getMaxPoint()
Get the maximum corner of the bounding box.- Returns:
- maximum corner of the bounding box
-
toStringNDec
public String toStringNDec(int ndec)
Get a String representation of this object, with user settable number of decomal places.
-
toString
public String toString()
Return a String representation of this ProjectionRect that can be used in new ProjectionRect(String): "x, y, width, height"
-
nearlyEquals
public boolean nearlyEquals(ProjectionRect other)
Returns the result ofnearlyEquals(ProjectionRect, double)
, withMisc.defaultMaxRelativeDiffFloat
.
-
nearlyEquals
public boolean nearlyEquals(ProjectionRect other, double maxRelDiff)
Returnstrue
if this rectangle is nearly equal toother
. The "near equality" of corners is determined usingProjectionPoint.nearlyEquals(ProjectionPoint, double)
, with the specified maxRelDiff.- Parameters:
other
- the other rectangle to check.maxRelDiff
- the maximumrelative difference
that two corners may have.- Returns:
true
if this rectangle is nearly equal toother
.
-
toBuilder
public ProjectionRect.Builder toBuilder()
Turn into a mutable Builder. Can use toBuilder().build() to copy.
-
builder
public static ProjectionRect.Builder builder()
-
builder
public static ProjectionRect.Builder builder(double x1, double y1, double x2, double y2)
-
-