22#include <geos/export.h>
23#include <geos/geom/Coordinate.h>
38GEOS_DLL std::ostream& operator<< (std::ostream& os,
const Envelope& o);
62 friend std::ostream& operator<< (std::ostream& os,
const Envelope& o);
64 typedef std::unique_ptr<Envelope> Ptr;
70 : minx(DoubleNotANumber)
71 , maxx(DoubleNotANumber)
72 , miny(DoubleNotANumber)
73 , maxy(DoubleNotANumber)
84 Envelope(
double x1,
double x2,
double y1,
double y2)
143 double minq = std::min(q1.
x, q2.
x);
144 double maxq = std::max(q1.
x, q2.
x);
145 double minp = std::min(p1.
x, p2.
x);
146 double maxp = std::max(p1.
x, p2.
x);
153 minq = std::min(q1.
y, q2.
y);
154 maxq = std::max(q1.
y, q2.
y);
155 minp = std::min(p1.
y, p2.
y);
156 maxp = std::max(p1.
y, p2.
y);
192 void init(
double x1,
double x2,
double y1,
double y2)
220 init(p1.
x, p2.
x, p1.
y, p2.
y);
230 init(p.
x, p.
x, p.
y, p.
y);
239 minx = maxx = miny = maxy = DoubleNotANumber;
250 return std::isnan(maxx);
288 return getWidth() * getHeight();
341 double w = getWidth();
342 double h = getHeight();
343 return std::sqrt(w*w + h*h);
393 expandBy(p_distance, p_distance);
404 expandToInclude(p.
x, p.
y);
457 if(std::isless(other->minx, minx)) {
460 if(std::isgreater(other->maxx, maxx)) {
463 if(std::isless(other->miny, miny)) {
466 if(std::isgreater(other->maxy, maxy)) {
472 void expandToInclude(
const Envelope& other)
474 return expandToInclude(&other);
492 return covers(other);
496 contains(
const Envelope* other)
const
498 return contains(*other);
511 return covers(p.
x, p.
y);
538 return (std::islessequal(other.
x, maxx) && std::isgreaterequal(other.
x, minx) &&
539 std::islessequal(other.
y, maxy) && std::isgreaterequal(other.
y, miny));
551 return std::islessequal(x, maxx) &&
552 std::isgreaterequal(x, minx) &&
553 std::islessequal(y, maxy) &&
554 std::isgreaterequal(y, miny);
565 return std::islessequal(other->minx, maxx) &&
566 std::isgreaterequal(other->maxx, minx) &&
567 std::islessequal(other->miny, maxy) &&
568 std::isgreaterequal(other->maxy, miny);
571 bool intersects(
const Envelope& other)
const
573 return intersects(&other);
585 return !intersects(other);
588 bool disjoint(
const Envelope* other)
const
590 return !intersects(other);
610 return covers(p->
x, p->
y);
624 return covers(*other);
658 return std::sqrt(distanceSquared(env));
669 double dx = std::max(0.0,
670 std::max(maxx, env.maxx) - std::min(minx, env.minx) - (maxx - minx) -
671 (env.maxx - env.minx));
672 double dy = std::max(0.0,
673 std::max(maxy, env.maxy) - std::min(miny, env.miny) - (maxy - miny) -
674 (env.maxy - env.miny));
676 return dx * dx + dy * dy;
693 return std::sqrt(distanceSquaredToCoordinate(c, p0, p1));
710 double xa = c.
x - p0.
x;
711 double xb = c.
x - p1.
x;
712 double ya = c.
y - p0.
y;
713 double yb = c.
y - p1.
y;
716 double dx = (std::signbit(xa) == std::signbit(xb)) * std::min(std::abs(xa), std::abs(xb));
717 double dy = (std::signbit(ya) == std::signbit(yb)) * std::min(std::abs(ya), std::abs(yb));
719 return dx*dx + dy*dy;
722 std::size_t hashCode()
const;
752 static std::vector<std::string> split(
const std::string& str,
753 const std::string& delimiters =
" ");
755 static double distance(
double x0,
double y0,
double x1,
double y1)
759 return std::sqrt(dx * dx + dy * dy);
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:58
double y
y-coordinate
Definition Coordinate.h:81
double x
x-coordinate
Definition Coordinate.h:78
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:58
double getMinX() const
Returns the Envelope minimum x-value. min x > max x indicates that this is a null Envelope.
Definition Envelope.h:325
bool intersection(const Envelope &env, Envelope &result) const
Computes the intersection of two Envelopes.
Envelope(const Coordinate &p)
Creates an Envelope for a region defined by a single Coordinate.
Definition Envelope.h:105
double distanceSquared(const Envelope &env) const
Computes the square of the distance between this and another Envelope.
Definition Envelope.h:667
bool contains(const Envelope &other) const
Tests if the Envelope other lies wholly inside this Envelope (inclusive of the boundary).
Definition Envelope.h:490
void expandToInclude(double x, double y)
Enlarges the boundary of the Envelope so that it contains (x,y).
Definition Envelope.h:417
bool intersects(double x, double y) const
Check if the point (x, y) intersects (lies inside) the region of this Envelope.
Definition Envelope.h:549
double getDiameter() const
Definition Envelope.h:336
bool intersects(const Coordinate &a, const Coordinate &b) const
Check if the extent defined by two extremal points intersects the extent of this Envelope.
bool equals(const Envelope *other) const
Returns true if the Envelope other spatially equals this Envelope.
void setToNull()
Makes this Envelope a "null" envelope, that is, the envelope of the empty geometry.
Definition Envelope.h:237
bool centre(Coordinate ¢re) const
Computes the coordinate of the centre of this envelope (as long as it is non-null).
bool covers(double x, double y) const
Tests if the given point lies in or on the envelope.
double distance(const Envelope &env) const
Computes the distance between this and another Envelope.
Definition Envelope.h:656
void init(const Coordinate &p1, const Coordinate &p2)
Initialize an Envelope to a region defined by two Coordinates.
Definition Envelope.h:218
double getArea() const
Gets the area of this envelope.
Definition Envelope.h:286
static double distanceSquaredToCoordinate(const Coordinate &c, const Coordinate &p0, const Coordinate &p1)
Computes the squared distance between one Coordinate and an Envelope defined by two other Coordinates...
Definition Envelope.h:705
void expandToInclude(const Coordinate &p)
Enlarges the boundary of the Envelope so that it contains p. Does nothing if p is already on or withi...
Definition Envelope.h:402
void expandBy(double deltaX, double deltaY)
Expands this envelope by a given distance in all directions. Both positive and negative distances are...
void init(double x1, double x2, double y1, double y2)
Initialize an Envelope for a region defined by maximum and minimum values.
Definition Envelope.h:192
bool contains(double x, double y) const
Returns true if the given point lies in or on the envelope.
Definition Envelope.h:525
double getHeight() const
Returns the difference between the maximum and minimum y values.
Definition Envelope.h:271
Envelope()
Creates a null Envelope.
Definition Envelope.h:69
Envelope(const std::string &str)
Create an Envelope from an Envelope string representation produced by Envelope::toString()
double getWidth() const
Returns the difference between the maximum and minimum x values.
Definition Envelope.h:258
void init(const Coordinate &p)
Initialize an Envelope to a region defined by a single Coordinate.
Definition Envelope.h:228
bool intersects(const Coordinate &other) const
Check if the point p intersects (lies inside) the region of this Envelope.
Definition Envelope.h:536
double getMaxX() const
Returns the Envelope maximum x-value. min x > max x indicates that this is a null Envelope.
Definition Envelope.h:305
double getMaxY() const
Returns the Envelope maximum y-value. min y > max y indicates that this is a null Envelope.
Definition Envelope.h:295
static bool intersects(const Coordinate &p1, const Coordinate &p2, const Coordinate &q)
Test the point q to see whether it intersects the Envelope defined by p1-p2.
bool isNull(void) const
Returns true if this Envelope is a "null" envelope.
Definition Envelope.h:248
Envelope(const Coordinate &p1, const Coordinate &p2)
Creates an Envelope for a region defined by two Coordinates.
Definition Envelope.h:95
void expandBy(double p_distance)
Expands this envelope by a given distance in all directions.
Definition Envelope.h:391
void expandToInclude(const Envelope *other)
Enlarges the boundary of the Envelope so that it contains other.
Definition Envelope.h:448
bool contains(const Coordinate &p) const
Returns true if the given point lies in or on the envelope.
Definition Envelope.h:509
bool disjoint(const Envelope &other) const
Definition Envelope.h:583
void init()
Initialize to a null Envelope.
Definition Envelope.h:179
static double distanceToCoordinate(const Coordinate &c, const Coordinate &p0, const Coordinate &p1)
Computes the distance between one Coordinate and an Envelope defined by two other Coordinates....
Definition Envelope.h:688
static bool intersects(const Coordinate &p1, const Coordinate &p2, const Coordinate &q1, const Coordinate &q2)
Test the envelope defined by p1-p2 for intersection with the envelope defined by q1-q2.
Definition Envelope.h:139
friend bool operator==(const Envelope &a, const Envelope &b)
Checks if two Envelopes are equal (2D only check)
Definition Envelope.h:727
bool covers(const Coordinate *p) const
Tests if the given point lies in or on the envelope.
Definition Envelope.h:608
std::string toString() const
Returns a string of the form Env[minx:maxx,miny:maxy].
bool intersects(const Envelope *other) const
Check if the region defined by other Envelope intersects the region of this Envelope.
Definition Envelope.h:563
void translate(double transX, double transY)
Translates this envelope by given amounts in the X and Y direction.
bool covers(const Envelope &other) const
Tests if the Envelope other lies wholly inside this Envelope (inclusive of the boundary).
double getMinY() const
Returns the Envelope minimum y-value. min y > max y indicates that this is a null Envelope.
Definition Envelope.h:315
Envelope(double x1, double x2, double y1, double y2)
Creates an Envelope for a region defined by maximum and minimum values.
Definition Envelope.h:84
Basic namespace for all GEOS functionalities.
Definition geos.h:39