cesium-native  0.41.0
Rectangle.h
1 #pragma once
2 
3 #include "Library.h"
4 
5 #include <glm/vec2.hpp>
6 
7 #include <optional>
8 
9 namespace CesiumGeometry {
10 
14 struct CESIUMGEOMETRY_API Rectangle final {
23  constexpr Rectangle() noexcept
24  : minimumX(0.0), minimumY(0.0), maximumX(0.0), maximumY(0.0) {}
25 
38  constexpr Rectangle(
39  double minimumX_,
40  double minimumY_,
41  double maximumX_,
42  double maximumY_) noexcept
43  : minimumX(minimumX_),
44  minimumY(minimumY_),
45  maximumX(maximumX_),
46  maximumY(maximumY_) {}
47 
51  double minimumX;
52 
56  double minimumY;
57 
61  double maximumX;
62 
66  double maximumY;
67 
78  bool contains(const glm::dvec2& position) const noexcept;
79 
90  bool overlaps(const Rectangle& other) const noexcept;
91 
101  bool fullyContains(const Rectangle& other) const noexcept;
102 
113  double computeSignedDistance(const glm::dvec2& position) const noexcept;
114 
122  constexpr glm::dvec2 getLowerLeft() const noexcept {
123  return glm::dvec2(this->minimumX, this->minimumY);
124  }
125 
133  constexpr glm::dvec2 getLowerRight() const noexcept {
134  return glm::dvec2(this->maximumX, this->minimumY);
135  }
136 
144  constexpr glm::dvec2 getUpperLeft() const noexcept {
145  return glm::dvec2(this->minimumX, this->maximumY);
146  }
147 
155  constexpr glm::dvec2 getUpperRight() const noexcept {
156  return glm::dvec2(this->maximumX, this->maximumY);
157  }
158 
164  constexpr glm::dvec2 getCenter() const noexcept {
165  return glm::dvec2(
166  (this->minimumX + this->maximumX) * 0.5,
167  (this->minimumY + this->maximumY) * 0.5);
168  }
169 
175  constexpr double computeWidth() const noexcept {
176  return this->maximumX - this->minimumX;
177  }
178 
184  constexpr double computeHeight() const noexcept {
185  return this->maximumY - this->minimumY;
186  }
187 
195  std::optional<Rectangle>
196  computeIntersection(const Rectangle& other) const noexcept;
197 
204  Rectangle computeUnion(const Rectangle& other) const noexcept;
205 };
206 
207 } // namespace CesiumGeometry
Basic geometry classes for Cesium.
A 2D rectangle.
Definition: Rectangle.h:14
bool overlaps(const Rectangle &other) const noexcept
Checks whether this rectangle overlaps the given rectangle.
constexpr Rectangle() noexcept
Creates a new instance with all coordinate values set to 0.0.
Definition: Rectangle.h:23
constexpr glm::dvec2 getLowerLeft() const noexcept
Returns a point at the lower left of this rectangle.
Definition: Rectangle.h:122
double minimumX
The minimum x-coordinate.
Definition: Rectangle.h:51
bool contains(const glm::dvec2 &position) const noexcept
Checks whether this rectangle contains the given position.
Rectangle computeUnion(const Rectangle &other) const noexcept
Computes the union of this rectangle with another.
double maximumY
The maximum y-coordinate.
Definition: Rectangle.h:66
double maximumX
The maximum x-coordinate.
Definition: Rectangle.h:61
double minimumY
The minimum y-coordinate.
Definition: Rectangle.h:56
constexpr double computeHeight() const noexcept
Computes the height of this rectangle.
Definition: Rectangle.h:184
bool fullyContains(const Rectangle &other) const noexcept
Checks whether this rectangle fully contains the given rectangle.
constexpr double computeWidth() const noexcept
Computes the width of this rectangle.
Definition: Rectangle.h:175
constexpr glm::dvec2 getCenter() const noexcept
Returns a point at the center of this rectangle.
Definition: Rectangle.h:164
constexpr glm::dvec2 getLowerRight() const noexcept
Returns a point at the lower right of this rectangle.
Definition: Rectangle.h:133
constexpr Rectangle(double minimumX_, double minimumY_, double maximumX_, double maximumY_) noexcept
Creates a new instance.
Definition: Rectangle.h:38
std::optional< Rectangle > computeIntersection(const Rectangle &other) const noexcept
double computeSignedDistance(const glm::dvec2 &position) const noexcept
Computes the signed distance from a position to the edge of the rectangle.
constexpr glm::dvec2 getUpperRight() const noexcept
Returns a point at the upper right of this rectangle.
Definition: Rectangle.h:155
constexpr glm::dvec2 getUpperLeft() const noexcept
Returns a point at the upper left of this rectangle.
Definition: Rectangle.h:144