Class Envelope
java.lang.Object
org.locationtech.jts.geom.Envelope
- All Implemented Interfaces:
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.
- Version:
- 1.7
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionEnvelope()Creates a nullEnvelope.Envelope(double x1, double x2, double y1, double y2) Creates anEnvelopefor a region defined by maximum and minimum values.Creates anEnvelopefor a region defined by a single Coordinate.Envelope(Coordinate p1, Coordinate p2) Creates anEnvelopefor a region defined by two Coordinates.Create anEnvelopefrom an existing Envelope. -
Method Summary
Modifier and TypeMethodDescriptioncentre()Computes the coordinate of the centre of this envelope (as long as it is non-nullintCompares two envelopes using lexicographic ordering.booleancontains(double x, double y) Tests if the given point lies in or on the envelope.booleanTests if the given point lies in or on the envelope.booleanTests if theEnvelope otherlies wholely inside thisEnvelope(inclusive of the boundary).booleancontainsProperly(Envelope other) Tests if an envelope is properly contained in this one.copy()Creates a copy of this envelope object.booleancovers(double x, double y) Tests if the given point lies in or on the envelope.booleancovers(Coordinate p) Tests if the given point lies in or on the envelope.booleanTests if theEnvelope otherlies wholely inside thisEnvelope(inclusive of the boundary).booleanTests if the region defined byotheris disjoint from the region of thisEnvelope.doubleComputes the distance between this and anotherEnvelope.booleanvoidexpandBy(double distance) Expands this envelope by a given distance in all directions.voidexpandBy(double deltaX, double deltaY) Expands this envelope by a given distance in all directions.voidexpandToInclude(double x, double y) Enlarges thisEnvelopeso that it contains the given point.voidEnlarges thisEnvelopeso that it contains the givenCoordinate.voidexpandToInclude(Envelope other) Enlarges thisEnvelopeso that it contains theotherEnvelope.doublegetArea()Gets the area of this envelope.doubleGets the length of the diameter (diagonal) of the envelope.doubleReturns the difference between the maximum and minimum y values.doublegetMaxX()Returns theEnvelopes maximum x-value. min x > max x indicates that this is a nullEnvelope.doublegetMaxY()Returns theEnvelopes maximum y-value. min y > max y indicates that this is a nullEnvelope.doublegetMinX()Returns theEnvelopes minimum x-value. min x > max x indicates that this is a nullEnvelope.doublegetMinY()Returns theEnvelopes minimum y-value. min y > max y indicates that this is a nullEnvelope.doublegetWidth()Returns the difference between the maximum and minimum x values.inthashCode()voidinit()Initialize to a nullEnvelope.voidinit(double x1, double x2, double y1, double y2) Initialize anEnvelopefor a region defined by maximum and minimum values.voidinit(Coordinate p) Initialize anEnvelopeto a region defined by a single Coordinate.voidinit(Coordinate p1, Coordinate p2) Initialize anEnvelopeto a region defined by two Coordinates.voidInitialize anEnvelopefrom an existing Envelope.intersection(Envelope env) Computes the intersection of twoEnvelopes.booleanintersects(double x, double y) Check if the point(x, y)intersects (lies inside) the region of thisEnvelope.booleanTests if the pointpintersects (lies inside) the region of thisEnvelope.booleanintersects(Coordinate a, Coordinate b) Tests if the extent defined by two extremal points intersects the extent of thisEnvelope.static booleanintersects(Coordinate p1, Coordinate p2, Coordinate q) Test the point q to see whether it intersects the Envelope defined by p1-p2static booleanintersects(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) Tests whether the envelope defined by p1-p2 and the envelope defined by q1-q2 intersect.booleanintersects(Envelope other) Tests if the region defined byotherintersects the region of thisEnvelope.booleanisNull()Returnstrueif thisEnvelopeis a "null" envelope.doubleGets the maximum extent of this envelope across both dimensions.doubleGets the minimum extent of this envelope across both dimensions.booleanoverlaps(double x, double y) Deprecated.Use #intersects instead.booleanDeprecated.Use #intersects instead.booleanDeprecated.Use #intersects instead.voidMakes thisEnvelopea "null" envelope, that is, the envelope of the empty geometry.toString()voidtranslate(double transX, double transY) Translates this envelope by given amounts in the X and Y direction.
-
Constructor Details
-
Envelope
public Envelope()Creates a nullEnvelope. -
Envelope
public Envelope(double x1, double x2, double y1, double y2) Creates anEnvelopefor a region defined by maximum and minimum values.- Parameters:
x1- the first x-valuex2- the second x-valuey1- the first y-valuey2- the second y-value
-
Envelope
Creates anEnvelopefor a region defined by two Coordinates.- Parameters:
p1- the first Coordinatep2- the second Coordinate
-
Envelope
Creates anEnvelopefor a region defined by a single Coordinate.- Parameters:
p- the Coordinate
-
Envelope
Create anEnvelopefrom an existing Envelope.- Parameters:
env- the Envelope to initialize from
-
-
Method Details
-
hashCode
-
intersects
Test the point q to see whether it intersects the Envelope defined by p1-p2- Parameters:
p1- one extremal point of the envelopep2- another extremal point of the envelopeq- the point to test for intersection- Returns:
trueif q intersects the envelope p1-p2
-
intersects
Tests whether the envelope defined by p1-p2 and the envelope defined by q1-q2 intersect.- Parameters:
p1- one extremal point of the envelope Pp2- another extremal point of the envelope Pq1- one extremal point of the envelope Qq2- another extremal point of the envelope Q- Returns:
trueif Q intersects P
-
init
public void init()Initialize to a nullEnvelope. -
init
public void init(double x1, double x2, double y1, double y2) Initialize anEnvelopefor a region defined by maximum and minimum values.- Parameters:
x1- the first x-valuex2- the second x-valuey1- the first y-valuey2- the second y-value
-
copy
-
init
Initialize anEnvelopeto a region defined by two Coordinates.- Parameters:
p1- the first Coordinatep2- the second Coordinate
-
init
Initialize anEnvelopeto a region defined by a single Coordinate.- Parameters:
p- the coordinate
-
init
Initialize anEnvelopefrom an existing Envelope.- Parameters:
env- the Envelope to initialize from
-
setToNull
public void setToNull()Makes thisEnvelopea "null" envelope, that is, the envelope of the empty geometry. -
isNull
public boolean isNull()Returnstrueif thisEnvelopeis a "null" envelope.- Returns:
trueif thisEnvelopeis uninitialized or is the envelope of the empty geometry.
-
getWidth
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
-
getHeight
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
-
getDiameter
public double getDiameter()Gets the length of the diameter (diagonal) of the envelope.- Returns:
- the diameter length
-
getMinX
public double getMinX()Returns theEnvelopes minimum x-value. min x > max x indicates that this is a nullEnvelope.- Returns:
- the minimum x-coordinate
-
getMaxX
public double getMaxX()Returns theEnvelopes maximum x-value. min x > max x indicates that this is a nullEnvelope.- Returns:
- the maximum x-coordinate
-
getMinY
public double getMinY()Returns theEnvelopes minimum y-value. min y > max y indicates that this is a nullEnvelope.- Returns:
- the minimum y-coordinate
-
getMaxY
public double getMaxY()Returns theEnvelopes maximum y-value. min y > max y indicates that this is a nullEnvelope.- Returns:
- the maximum y-coordinate
-
getArea
public double getArea()Gets the area of this envelope.- Returns:
- the area of the envelope
-
minExtent
public double minExtent()Gets the minimum extent of this envelope across both dimensions.- Returns:
- the minimum extent of this envelope
-
maxExtent
public double maxExtent()Gets the maximum extent of this envelope across both dimensions.- Returns:
- the maximum extent of this envelope
-
expandToInclude
Enlarges thisEnvelopeso that it contains the givenCoordinate. Has no effect if the point is already on or within the envelope.- Parameters:
p- the Coordinate to expand to include
-
expandBy
public void expandBy(double distance) Expands this envelope by a given distance in all directions. Both positive and negative distances are supported.- Parameters:
distance- the distance to expand the envelope
-
expandBy
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- the distance to expand the envelope along the the X axisdeltaY- the distance to expand the envelope along the the Y axis
-
expandToInclude
public void expandToInclude(double x, double y) Enlarges thisEnvelopeso that it contains the given point. Has no effect if the point is already on or within the envelope.- Parameters:
x- the value to lower the minimum x to or to raise the maximum x toy- the value to lower the minimum y to or to raise the maximum y to
-
expandToInclude
Enlarges thisEnvelopeso that it contains theotherEnvelope. Has no effect ifotheris wholly on or within the envelope.- Parameters:
other- theEnvelopeto expand to include
-
translate
public void translate(double transX, double transY) Translates this envelope by given amounts in the X and Y direction.- Parameters:
transX- the amount to translate along the X axistransY- the amount to translate along the Y axis
-
centre
Computes the coordinate of the centre of this envelope (as long as it is non-null- Returns:
- the centre coordinate of this envelope
nullif the envelope is null
-
intersection
-
intersects
Tests if the region defined byotherintersects the region of thisEnvelope.A null envelope never intersects.
- Parameters:
other- theEnvelopewhich thisEnvelopeis being checked for intersecting- Returns:
trueif theEnvelopes intersect
-
intersects
Tests if the extent defined by two extremal points intersects the extent of thisEnvelope.- Parameters:
a- a pointb- another point- Returns:
trueif the extents intersect
-
disjoint
Tests if the region defined byotheris disjoint from the region of thisEnvelope.A null envelope is always disjoint.
- Parameters:
other- theEnvelopebeing checked for disjointness- Returns:
trueif theEnvelopes are disjoint- See Also:
-
overlaps
Deprecated.Use #intersects instead. In the future, #overlaps may be changed to be a true overlap check; that is, whether the intersection is two-dimensional. -
intersects
Tests if the pointpintersects (lies inside) the region of thisEnvelope.- Parameters:
p- theCoordinateto be tested- Returns:
trueif the point intersects thisEnvelope
-
overlaps
Deprecated.Use #intersects instead. -
intersects
public boolean intersects(double x, double y) Check if the point(x, y)intersects (lies inside) the region of thisEnvelope.- Parameters:
x- the x-ordinate of the pointy- the y-ordinate of the point- Returns:
trueif the point overlaps thisEnvelope
-
overlaps
public boolean overlaps(double x, double y) Deprecated.Use #intersects instead. -
contains
Tests if theEnvelope otherlies wholely inside thisEnvelope(inclusive of the boundary).Note that this is not the same definition as the SFS contains, which would exclude the envelope boundary.
- Parameters:
other- theEnvelopeto check- Returns:
- true if
otheris contained in thisEnvelope - See Also:
-
contains
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- the point which thisEnvelopeis being checked for containing- Returns:
trueif the point lies in the interior or on the boundary of thisEnvelope.- See Also:
-
contains
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- the x-coordinate of the point which thisEnvelopeis being checked for containingy- the y-coordinate of the point which thisEnvelopeis being checked for containing- Returns:
trueif(x, y)lies in the interior or on the boundary of thisEnvelope.- See Also:
-
containsProperly
Tests if an envelope is properly contained in this one. The envelope is properly contained if it is contained by this one but not equal to it.- Parameters:
other- the envelope to test- Returns:
- true if the envelope is properly contained
-
covers
public boolean covers(double x, double y) Tests if the given point lies in or on the envelope.- Parameters:
x- the x-coordinate of the point which thisEnvelopeis being checked for containingy- the y-coordinate of the point which thisEnvelopeis being checked for containing- Returns:
trueif(x, y)lies in the interior or on the boundary of thisEnvelope.
-
covers
Tests if the given point lies in or on the envelope.- Parameters:
p- the point which thisEnvelopeis being checked for containing- Returns:
trueif the point lies in the interior or on the boundary of thisEnvelope.
-
covers
Tests if theEnvelope otherlies wholely inside thisEnvelope(inclusive of the boundary).- Parameters:
other- theEnvelopeto check- Returns:
- true if this
Envelopecovers theother
-
distance
Computes the distance between this and anotherEnvelope. The distance between overlapping Envelopes is 0. Otherwise, the distance is the Euclidean distance between the closest points. -
equals
-
toString
-
compareTo
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.- Specified by:
compareToin interfaceComparable- Parameters:
o- an Envelope object
-