22#include <geos/export.h>
23#include <geos/geom/Coordinate.h>
38GEOS_DLL std::ostream& operator<< (std::ostream& os,
const Envelope& o);
63 friend std::ostream& operator<< (std::ostream& os,
const Envelope& o);
65 typedef std::unique_ptr<Envelope> Ptr;
71 : minx(DoubleNotANumber)
72 , maxx(DoubleNotANumber)
73 , miny(DoubleNotANumber)
74 , maxy(DoubleNotANumber)
85 Envelope(
double x1,
double x2,
double y1,
double y2)
96 Envelope(
const CoordinateXY& p1,
const CoordinateXY& p2)
129 static bool intersects(
const CoordinateXY& p1,
const CoordinateXY& p2,
130 const CoordinateXY& q);
144 const CoordinateXY& p1,
const CoordinateXY& p2,
145 const CoordinateXY& q1,
const CoordinateXY& q2)
147 double minq = std::min(q1.x, q2.x);
148 double maxq = std::max(q1.x, q2.x);
149 double minp = std::min(p1.x, p2.x);
150 double maxp = std::max(p1.x, p2.x);
157 minq = std::min(q1.y, q2.y);
158 maxq = std::max(q1.y, q2.y);
159 minp = std::min(p1.y, p2.y);
160 maxp = std::max(p1.y, p2.y);
178 bool intersects(
const CoordinateXY& a,
const CoordinateXY& b)
const;
196 void init(
double x1,
double x2,
double y1,
double y2)
222 void init(
const CoordinateXY& p1,
const CoordinateXY& p2)
224 init(p1.x, p2.x, p1.y, p2.y);
232 void init(
const CoordinateXY& p)
234 init(p.x, p.x, p.y, p.y);
243 minx = maxx = miny = maxy = DoubleNotANumber;
254 return std::isnan(maxx);
292 return getWidth() * getHeight();
304 return 2*getWidth() + 2*getHeight();
313 return std::isfinite(getArea());
366 double w = getWidth();
367 double h = getHeight();
368 return std::sqrt(w*w + h*h);
428 expandBy(p_distance, p_distance);
439 expandToInclude(p.x, p.y);
492 if(std::isless(other->minx, minx)) {
495 if(std::isgreater(other->maxx, maxx)) {
498 if(std::isless(other->miny, miny)) {
501 if(std::isgreater(other->maxy, maxy)) {
507 void expandToInclude(
const Envelope& other)
509 return expandToInclude(&other);
527 return covers(other);
531 contains(
const Envelope* other)
const
533 return contains(*other);
546 return covers(p.x, p.y);
573 return (std::islessequal(other.x, maxx) && std::isgreaterequal(other.x, minx) &&
574 std::islessequal(other.y, maxy) && std::isgreaterequal(other.y, miny));
586 return std::islessequal(x, maxx) &&
587 std::isgreaterequal(x, minx) &&
588 std::islessequal(y, maxy) &&
589 std::isgreaterequal(y, miny);
600 return std::islessequal(other->minx, maxx) &&
601 std::isgreaterequal(other->maxx, minx) &&
602 std::islessequal(other->miny, maxy) &&
603 std::isgreaterequal(other->maxy, miny);
606 bool intersects(
const Envelope& other)
const
608 return intersects(&other);
620 return !intersects(other);
623 bool disjoint(
const Envelope* other)
const
625 return !intersects(other);
636 return std::isgreaterequal(x, minx) &&
637 std::islessequal(x, maxx) &&
638 std::isgreaterequal(y, miny) &&
639 std::islessequal(y, maxy);
650 return covers(p->x, p->y);
664 return covers(*other);
698 return std::sqrt(distanceSquared(env));
706 Coordinate p(std::min(minx, other.minx), std::min(miny, other.miny));
707 Coordinate q(std::max(maxx, other.maxx), std::max(maxy, other.maxy));
708 return p.distance(q);
719 double dx = std::max(0.0,
720 std::max(maxx, env.maxx) - std::min(minx, env.minx) - (maxx - minx) -
721 (env.maxx - env.minx));
722 double dy = std::max(0.0,
723 std::max(maxy, env.maxy) - std::min(miny, env.miny) - (maxy - miny) -
724 (env.maxy - env.miny));
726 return dx * dx + dy * dy;
739 const CoordinateXY& c,
740 const CoordinateXY& p0,
741 const CoordinateXY& p1)
743 return std::sqrt(distanceSquaredToCoordinate(c, p0, p1));
756 const CoordinateXY& c,
757 const CoordinateXY& p0,
758 const CoordinateXY& p1)
760 double xa = c.x - p0.x;
761 double xb = c.x - p1.x;
762 double ya = c.y - p0.y;
763 double yb = c.y - p1.y;
766 double dx = (std::signbit(xa) == std::signbit(xb)) * std::min(std::abs(xa), std::abs(xb));
767 double dy = (std::signbit(ya) == std::signbit(yb)) * std::min(std::abs(ya), std::abs(yb));
769 return dx*dx + dy*dy;
772 std::size_t hashCode()
const
774 auto hash = std::hash<double>{};
777 std::size_t result = 17;
778 result = 37 * result + hash(minx);
779 result = 37 * result + hash(maxx);
780 result = 37 * result + hash(miny);
781 result = 37 * result + hash(maxy);
785 struct GEOS_DLL HashCode
787 std::size_t operator()(
const Envelope& e)
const
821 static std::vector<std::string> split(
const std::string& str,
822 const std::string& delimiters =
" ");
824 static double distance(
double x0,
double y0,
double x1,
double y1)
828 return std::sqrt(dx * dx + dy * dy);
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
double getMinX() const
Returns the Envelope minimum x-value. Null envelopes do not have maximum values.
Definition Envelope.h:350
void expandToInclude(const CoordinateXY &p)
Enlarges the boundary of the Envelope so that it contains p. Does nothing if p is already on or withi...
Definition Envelope.h:437
bool contains(const CoordinateXY &p) const
Returns true if the given point lies in or on the envelope.
Definition Envelope.h:544
bool intersection(const Envelope &env, Envelope &result) const
Computes the intersection of two Envelopes.
double distanceSquared(const Envelope &env) const
Computes the square of the distance between this and another Envelope.
Definition Envelope.h:717
bool contains(const Envelope &other) const
Tests if the Envelope other lies wholly inside this Envelope (inclusive of the boundary).
Definition Envelope.h:525
void expandToInclude(double x, double y)
Enlarges the boundary of the Envelope so that it contains (x,y).
Definition Envelope.h:452
bool intersects(double x, double y) const
Check if the point (x, y) intersects (lies inside) the region of this Envelope.
Definition Envelope.h:584
double getDiameter() const
Definition Envelope.h:361
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:241
bool covers(double x, double y) const
Tests if the given point lies in or on the envelope.
Definition Envelope.h:635
bool centre(CoordinateXY ¢re) const
Computes the coordinate of the centre of this envelope (as long as it is non-null).
double distance(const Envelope &env) const
Computes the distance between this and another Envelope.
Definition Envelope.h:696
static double distanceToCoordinate(const CoordinateXY &c, const CoordinateXY &p0, const CoordinateXY &p1)
Computes the distance between one Coordinate and an Envelope defined by two other Coordinates....
Definition Envelope.h:738
double getArea() const
Gets the area of this envelope.
Definition Envelope.h:290
double getPerimeter() const
Gets the perimeter of this envelope.
Definition Envelope.h:302
void init(const CoordinateXY &p1, const CoordinateXY &p2)
Initialize an Envelope to a region defined by two Coordinates.
Definition Envelope.h:222
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:196
static bool intersects(const CoordinateXY &p1, const CoordinateXY &p2, const CoordinateXY &q)
Test the point q to see whether it intersects the Envelope defined by p1-p2.
bool contains(double x, double y) const
Returns true if the given point lies in or on the envelope.
Definition Envelope.h:560
double getHeight() const
Returns the difference between the maximum and minimum y values.
Definition Envelope.h:275
Envelope()
Creates a null Envelope.
Definition Envelope.h:70
Envelope(const std::string &str)
Create an Envelope from an Envelope string representation produced by Envelope::toString()
bool isFinite() const
Returns true if this Envelope covers a finite region.
Definition Envelope.h:311
double getWidth() const
Returns the difference between the maximum and minimum x values.
Definition Envelope.h:262
double getMaxX() const
Returns the Envelope maximum x-value. Null envelopes do not have maximum values.
Definition Envelope.h:330
bool intersects(const CoordinateXY &a, const CoordinateXY &b) const
Check if the extent defined by two extremal points intersects the extent of this Envelope.
double getMaxY() const
Returns the Envelope maximum y-value. Null envelopes do not have maximum values.
Definition Envelope.h:320
bool isNull(void) const
Returns true if this Envelope is a "null" envelope.
Definition Envelope.h:252
void init(const CoordinateXY &p)
Initialize an Envelope to a region defined by a single Coordinate.
Definition Envelope.h:232
void expandBy(double p_distance)
Expands this envelope by a given distance in all directions.
Definition Envelope.h:426
bool covers(const CoordinateXY *p) const
Tests if the given point lies in or on the envelope.
Definition Envelope.h:648
void expandToInclude(const Envelope *other)
Enlarges the boundary of the Envelope so that it contains other.
Definition Envelope.h:483
static bool intersects(const CoordinateXY &p1, const CoordinateXY &p2, const CoordinateXY &q1, const CoordinateXY &q2)
Test the envelope defined by p1-p2 for intersection with the envelope defined by q1-q2.
Definition Envelope.h:143
Envelope(const CoordinateXY &p)
Creates an Envelope for a region defined by a single Coordinate.
Definition Envelope.h:106
Envelope intersection(const Envelope &env) const
Computes the intersection of two Envelopes.
bool disjoint(const Envelope &other) const
Definition Envelope.h:618
void init()
Initialize to a null Envelope.
Definition Envelope.h:183
friend bool operator==(const Envelope &a, const Envelope &b)
Checks if two Envelopes are equal (2D only check)
Definition Envelope.h:796
Envelope(const CoordinateXY &p1, const CoordinateXY &p2)
Creates an Envelope for a region defined by two Coordinates.
Definition Envelope.h:96
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:598
bool intersects(const CoordinateXY &other) const
Check if the point p intersects (lies inside) the region of this Envelope.
Definition Envelope.h:571
static double distanceSquaredToCoordinate(const CoordinateXY &c, const CoordinateXY &p0, const CoordinateXY &p1)
Computes the squared distance between one Coordinate and an Envelope defined by two other Coordinates...
Definition Envelope.h:755
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. Null envelopes do not have maximum values.
Definition Envelope.h:340
Envelope(double x1, double x2, double y1, double y2)
Creates an Envelope for a region defined by maximum and minimum values.
Definition Envelope.h:85
double maxDistance(const Envelope &other) const
Computes the maximum distance between points in this and another Envelope.
Definition Envelope.h:704
Basic namespace for all GEOS functionalities.
Definition geos.h:38