Class Envelope

Hierarchy: Object , Envelope
All Implemented Interfaces: Comparable , Serializable
public class Envelope
implements Serializable , Comparable
Defines a rectangular region of the 2D coordinate plane. It is often used to represent the bounding box of a Geometry, e.g. the minimum and maximum x and y values of the Coordinates.

Envelopes support infinite or half-infinite regions, by using the values of Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY. Envelope objects may have a null value.

When Envelope objects are created or initialized, the supplies extent values are automatically sorted into the correct order.

Other

  • version: 1.7
public Envelope()
Creates a null Envelope.
public Envelope(double x1, double x2, double y1, double y2)
Creates an Envelope for a region defined by maximum and minimum values.
Parameters:
x1 - x1 the first x-value
x2 - x2 the second x-value
y1 - y1 the first y-value
y2 - y2 the second y-value
public Envelope(Coordinate p1, Coordinate p2)
Creates an Envelope for a region defined by two Coordinates.
Parameters:
p1 - p1 the first Coordinate
p2 - p2 the second Coordinate
public Envelope(Coordinate p)
Creates an Envelope for a region defined by a single Coordinate.
Parameters:
p - p the Coordinate
public Envelope(Envelope env)
Create an Envelope from an existing Envelope.
Parameters:
env - env the Envelope to initialize from
public int hashCode()
public static boolean intersects(Coordinate p1, Coordinate p2, Coordinate q)
Test the point q to see whether it intersects the Envelope defined by p1-p2
Parameters:
p1 - p1 one extremal point of the envelope
p2 - p2 another extremal point of the envelope
q - q the point to test for intersection
Returns:
true if q intersects the envelope p1-p2
public static boolean intersects(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2)
Tests whether the envelope defined by p1-p2 and the envelope defined by q1-q2 intersect.
Parameters:
p1 - p1 one extremal point of the envelope P
p2 - p2 another extremal point of the envelope P
q1 - q1 one extremal point of the envelope Q
q2 - q2 another extremal point of the envelope Q
Returns:
true if Q intersects P
public void init()
Initialize to a null Envelope.
public void init(double x1, double x2, double y1, double y2)
Initialize an Envelope for a region defined by maximum and minimum values.
Parameters:
x1 - x1 the first x-value
x2 - x2 the second x-value
y1 - y1 the first y-value
y2 - y2 the second y-value
public Envelope copy()
Creates a copy of this envelope object.
Returns:
a copy of this envelope
public void init(Coordinate p1, Coordinate p2)
Initialize an Envelope to a region defined by two Coordinates.
Parameters:
p1 - p1 the first Coordinate
p2 - p2 the second Coordinate
public void init(Coordinate p)
Initialize an Envelope to a region defined by a single Coordinate.
Parameters:
p - p the coordinate
public void init(Envelope env)
Initialize an Envelope from an existing Envelope.
Parameters:
env - env the Envelope to initialize from
public void setToNull()
Makes this Envelope a "null" envelope, that is, the envelope of the empty geometry.
public boolean isNull()
Returns true if this Envelope is a "null" envelope.
Returns:
true if this Envelope is uninitialized or is the envelope of the empty geometry.
public double getWidth()
Returns the difference between the maximum and minimum x values.
Returns:
max x - min x, or 0 if this is a null Envelope
public double getHeight()
Returns the difference between the maximum and minimum y values.
Returns:
max y - min y, or 0 if this is a null Envelope
public double getDiameter()
Gets the length of the diameter (diagonal) of the envelope.
Returns:
the diameter length
public double getMinX()
Returns the Envelopes minimum x-value. min x > max x indicates that this is a null Envelope.
Returns:
the minimum x-coordinate
public double getMaxX()
Returns the Envelopes maximum x-value. min x > max x indicates that this is a null Envelope.
Returns:
the maximum x-coordinate
public double getMinY()
Returns the Envelopes minimum y-value. min y > max y indicates that this is a null Envelope.
Returns:
the minimum y-coordinate
public double getMaxY()
Returns the Envelopes maximum y-value. min y > max y indicates that this is a null Envelope.
Returns:
the maximum y-coordinate
public double getArea()
Gets the area of this envelope.
Returns:
the area of the envelope
0.0 if the envelope is null
public double minExtent()
Gets the minimum extent of this envelope across both dimensions.
Returns:
the minimum extent of this envelope
public double maxExtent()
Gets the maximum extent of this envelope across both dimensions.
Returns:
the maximum extent of this envelope
public void expandToInclude(Coordinate p)
Enlarges this Envelope so that it contains the given Coordinate. Has no effect if the point is already on or within the envelope.
Parameters:
p - p the Coordinate to expand to include
public void expandBy(double distance)
Expands this envelope by a given distance in all directions. Both positive and negative distances are supported.
Parameters:
distance - distance the distance to expand the envelope
public void expandBy(double deltaX, double deltaY)
Expands this envelope by a given distance in all directions. Both positive and negative distances are supported.
Parameters:
deltaX - deltaX the distance to expand the envelope along the the X axis
deltaY - deltaY the distance to expand the envelope along the the Y axis
public void expandToInclude(double x, double y)
Enlarges this Envelope so that it contains the given point. Has no effect if the point is already on or within the envelope.
Parameters:
x - x the value to lower the minimum x to or to raise the maximum x to
y - y the value to lower the minimum y to or to raise the maximum y to
public void expandToInclude(Envelope other)
Enlarges this Envelope so that it contains the other Envelope. Has no effect if other is wholly on or within the envelope.
Parameters:
other - other the Envelope to expand to include
public void translate(double transX, double transY)
Translates this envelope by given amounts in the X and Y direction.
Parameters:
transX - transX the amount to translate along the X axis
transY - transY the amount to translate along the Y axis
public Coordinate centre()
Computes the coordinate of the centre of this envelope (as long as it is non-null
Returns:
the centre coordinate of this envelope null if the envelope is null
public Envelope intersection(Envelope env)
Computes the intersection of two Envelopes.
Parameters:
env - env the envelope to intersect with
Returns:
a new Envelope representing the intersection of the envelopes (this will be the null envelope if either argument is null, or they do not intersect
public boolean intersects(Envelope other)
Tests if the region defined by other intersects the region of this Envelope.
Parameters:
other - other the Envelope which this Envelope is being checked for intersecting
Returns:
true if the Envelopes intersect
public boolean intersects(Coordinate a, Coordinate b)
Tests if the extent defined by two extremal points intersects the extent of this Envelope.
Parameters:
a - a a point
b - b another point
Returns:
true if the extents intersect
public boolean disjoint(Envelope other)
Tests if the region defined by other is disjoint from the region of this Envelope.
Parameters:
other - other the Envelope being checked for disjointness
See also:
#intersects(Envelope)
Returns:
true if the Envelopes are disjoint
public boolean overlaps(Envelope other)
Deprecation:
Use #intersects instead. In the future, #overlaps may be changed to be a true overlap check; that is, whether the intersection is two-dimensional.
public boolean intersects(Coordinate p)
Tests if the point p intersects (lies inside) the region of this Envelope.
Parameters:
p - p the Coordinate to be tested
Returns:
true if the point intersects this Envelope
public boolean overlaps(Coordinate p)
Deprecation:
Use #intersects instead.
public boolean intersects(double x, double y)
Check if the point (x, y) intersects (lies inside) the region of this Envelope.
Parameters:
x - x the x-ordinate of the point
y - y the y-ordinate of the point
Returns:
true if the point overlaps this Envelope
public boolean overlaps(double x, double y)
Deprecation:
Use #intersects instead.
public boolean contains(Envelope other)
Tests if the Envelope other lies wholely inside this Envelope (inclusive of the boundary).

Note that this is not the same definition as the SFS contains, which would exclude the envelope boundary.

Parameters:
other - other the Envelope to check
See also:
#covers(Envelope)
Returns:
true if other is contained in this Envelope
public boolean contains(Coordinate p)
Tests if the given point lies in or on the envelope.

Note that this is not the same definition as the SFS contains, which would exclude the envelope boundary.

Parameters:
p - p the point which this Envelope is being checked for containing
See also:
#covers(Coordinate)
Returns:
true if the point lies in the interior or on the boundary of this Envelope.
public boolean contains(double x, double y)
Tests if the given point lies in or on the envelope.

Note that this is not the same definition as the SFS contains, which would exclude the envelope boundary.

Parameters:
x - x the x-coordinate of the point which this Envelope is being checked for containing
y - y the y-coordinate of the point which this Envelope is being checked for containing
See also:
#covers(double, double)
Returns:
true if (x, y) lies in the interior or on the boundary of this Envelope.
public boolean covers(double x, double y)
Tests if the given point lies in or on the envelope.
Parameters:
x - x the x-coordinate of the point which this Envelope is being checked for containing
y - y the y-coordinate of the point which this Envelope is being checked for containing
Returns:
true if (x, y) lies in the interior or on the boundary of this Envelope.
public boolean covers(Coordinate p)
Tests if the given point lies in or on the envelope.
Parameters:
p - p the point which this Envelope is being checked for containing
Returns:
true if the point lies in the interior or on the boundary of this Envelope.
public boolean covers(Envelope other)
Tests if the Envelope other lies wholely inside this Envelope (inclusive of the boundary).
Parameters:
other - other the Envelope to check
Returns:
true if this Envelope covers the other
public double distance(Envelope env)
Computes the distance between this and another Envelope. The distance between overlapping Envelopes is 0. Otherwise, the distance is the Euclidean distance between the closest points.
public boolean equals(Object other)
public String toString()
public int compareTo(Object o)
Compares two envelopes using lexicographic ordering. The ordering comparison is based on the usual numerical comparison between the sequence of ordinates. Null envelopes are less than all non-null envelopes.
Parameters:
o - o an Envelope object