cesium-native 0.53.0
Loading...
Searching...
No Matches
GlobeRectangle.h
1#pragma once
2
3#include <CesiumGeometry/Rectangle.h>
4#include <CesiumGeospatial/Cartographic.h>
5#include <CesiumGeospatial/Library.h>
6#include <CesiumUtility/Math.h>
7
8#include <glm/ext/vector_double2.hpp>
9
10#include <optional>
11
12namespace CesiumGeospatial {
13
25class CESIUMGEOSPATIAL_API GlobeRectangle final {
26public:
36 static const GlobeRectangle EMPTY;
37
47 static const GlobeRectangle MAXIMUM;
48
59 constexpr GlobeRectangle(
60 double west,
61 double south,
62 double east,
63 double north) noexcept
64 : _west(west), _south(south), _east(east), _north(north) {}
65
76 static constexpr GlobeRectangle
78 return GlobeRectangle(
79 rectangle.minimumX,
80 rectangle.minimumY,
81 rectangle.maximumX,
82 rectangle.maximumY);
83 }
84
101 static constexpr GlobeRectangle fromDegrees(
102 double westDegrees,
103 double southDegrees,
104 double eastDegrees,
105 double northDegrees) noexcept {
106 return GlobeRectangle(
111 }
112
116 constexpr double getWest() const noexcept { return this->_west; }
117
121 void setWest(double value) noexcept { this->_west = value; }
122
126 constexpr double getSouth() const noexcept { return this->_south; }
127
131 void setSouth(double value) noexcept { this->_south = value; }
132
136 constexpr double getEast() const noexcept { return this->_east; }
137
141 void setEast(double value) noexcept { this->_east = value; }
142
146 constexpr double getNorth() const noexcept { return this->_north; }
147
151 void setNorth(double value) noexcept { this->_north = value; }
152
156 constexpr Cartographic getSouthwest() const noexcept {
157 return Cartographic(this->_west, this->_south);
158 }
159
163 constexpr Cartographic getSoutheast() const noexcept {
164 return Cartographic(this->_east, this->_south);
165 }
166
170 constexpr Cartographic getNorthwest() const noexcept {
171 return Cartographic(this->_west, this->_north);
172 }
173
177 constexpr Cartographic getNortheast() const noexcept {
178 return Cartographic(this->_east, this->_north);
179 }
180
184 constexpr CesiumGeometry::Rectangle toSimpleRectangle() const noexcept {
186 this->getWest(),
187 this->getSouth(),
188 this->getEast(),
189 this->getNorth());
190 }
191
197 constexpr double computeWidth() const noexcept {
198 double east = this->_east;
199 const double west = this->_west;
200 if (east < west) {
202 }
203 return east - west;
204 }
205
211 constexpr double computeHeight() const noexcept {
212 return this->_north - this->_south;
213 }
214
218 Cartographic computeCenter() const noexcept;
219
229 bool contains(const Cartographic& cartographic) const noexcept;
230
236 bool isEmpty() const noexcept;
237
253 std::optional<GlobeRectangle>
254 computeIntersection(const GlobeRectangle& other) const noexcept;
255
262 GlobeRectangle computeUnion(const GlobeRectangle& other) const noexcept;
263
273 glm::dvec2
274 computeNormalizedCoordinates(const Cartographic& cartographic) const noexcept;
275
286 std::pair<GlobeRectangle, std::optional<GlobeRectangle>>
287 splitAtAntiMeridian() const noexcept;
288
296 static bool
297 equals(const GlobeRectangle& left, const GlobeRectangle& right) noexcept;
298
308 static bool equalsEpsilon(
309 const GlobeRectangle& left,
310 const GlobeRectangle& right,
311 double relativeEpsilon) noexcept;
312
313private:
314 double _west;
315 double _south;
316 double _east;
317 double _north;
318};
319
320} // namespace CesiumGeospatial
A position defined by longitude, latitude, and height.
A two-dimensional, rectangular region on a globe, specified using longitude and latitude coordinates....
constexpr double getWest() const noexcept
Returns the westernmost longitude, in radians.
constexpr double computeWidth() const noexcept
Computes the width of this rectangle.
constexpr double getNorth() const noexcept
Returns the northernmost latitude, in radians.
Cartographic computeCenter() const noexcept
Computes the Cartographic center position of this rectangle.
static const GlobeRectangle MAXIMUM
The maximum rectangle.
void setNorth(double value) noexcept
Sets the northernmost latitude, in radians.
constexpr GlobeRectangle(double west, double south, double east, double north) noexcept
Constructs a new instance.
static bool equals(const GlobeRectangle &left, const GlobeRectangle &right) noexcept
Checks whether two globe rectangles are exactly equal.
constexpr Cartographic getSouthwest() const noexcept
Returns the Cartographic position of the south-west corner.
bool isEmpty() const noexcept
Determines if this rectangle is empty.
constexpr Cartographic getNortheast() const noexcept
Returns the Cartographic position of the north-east corner.
static constexpr GlobeRectangle fromDegrees(double westDegrees, double southDegrees, double eastDegrees, double northDegrees) noexcept
static bool equalsEpsilon(const GlobeRectangle &left, const GlobeRectangle &right, double relativeEpsilon) noexcept
Checks whether two globe rectangles are equal up to a given relative epsilon.
constexpr double getEast() const noexcept
Returns the easternmost longitude, in radians.
void setWest(double value) noexcept
Sets the westernmost longitude, in radians.
bool contains(const Cartographic &cartographic) const noexcept
Returns true if this rectangle contains the given point.
std::optional< GlobeRectangle > computeIntersection(const GlobeRectangle &other) const noexcept
Computes the intersection of two rectangles.
constexpr Cartographic getSoutheast() const noexcept
Returns the Cartographic position of the south-east corner.
constexpr CesiumGeometry::Rectangle toSimpleRectangle() const noexcept
Returns this rectangle as a CesiumGeometry::Rectangle.
static constexpr GlobeRectangle fromRectangleRadians(const CesiumGeometry::Rectangle &rectangle) noexcept
Constructs a new GlobeRectangle from the provided Rectangle.
void setSouth(double value) noexcept
Sets the southernmost latitude, in radians.
void setEast(double value) noexcept
Sets the easternmost longitude, in radians.
constexpr double computeHeight() const noexcept
Computes the height of this rectangle.
GlobeRectangle computeUnion(const GlobeRectangle &other) const noexcept
Computes the union of this globe rectangle with another.
glm::dvec2 computeNormalizedCoordinates(const Cartographic &cartographic) const noexcept
Computes the normalized position of the given cartographic coordinate on this globe rectangle,...
static const GlobeRectangle EMPTY
An empty rectangle.
constexpr Cartographic getNorthwest() const noexcept
Returns the Cartographic position of the north-west corner.
constexpr double getSouth() const noexcept
Returns the southernmost latitude, in radians.
std::pair< GlobeRectangle, std::optional< GlobeRectangle > > splitAtAntiMeridian() const noexcept
Splits this rectangle at the anti-meridian (180 degrees longitude), if necessary.
static constexpr double degreesToRadians(double angleDegrees) noexcept
Converts degrees to radians.
Definition Math.h:367
static constexpr double TwoPi
Two times pi.
Definition Math.h:86
Classes for geospatial computations in Cesium.
STL namespace.
A 2D rectangle.
Definition Rectangle.h:14