cesium-native 0.43.0
Loading...
Searching...
No Matches
Rectangle.h
1#pragma once
2
3#include "Library.h"
4
5#include <glm/vec2.hpp>
6
7#include <optional>
8
9namespace CesiumGeometry {
10
14struct CESIUMGEOMETRY_API Rectangle final {
18 constexpr Rectangle() noexcept
19 : minimumX(0.0), minimumY(0.0), maximumX(0.0), maximumY(0.0) {}
20
33 constexpr Rectangle(
34 double minimumX_,
35 double minimumY_,
36 double maximumX_,
37 double maximumY_) noexcept
38 : minimumX(minimumX_),
39 minimumY(minimumY_),
40 maximumX(maximumX_),
41 maximumY(maximumY_) {}
42
46 double minimumX;
47
51 double minimumY;
52
56 double maximumX;
57
61 double maximumY;
62
73 bool contains(const glm::dvec2& position) const noexcept;
74
85 bool overlaps(const Rectangle& other) const noexcept;
86
96 bool fullyContains(const Rectangle& other) const noexcept;
97
108 double computeSignedDistance(const glm::dvec2& position) const noexcept;
109
117 constexpr glm::dvec2 getLowerLeft() const noexcept {
118 return glm::dvec2(this->minimumX, this->minimumY);
119 }
120
128 constexpr glm::dvec2 getLowerRight() const noexcept {
129 return glm::dvec2(this->maximumX, this->minimumY);
130 }
131
139 constexpr glm::dvec2 getUpperLeft() const noexcept {
140 return glm::dvec2(this->minimumX, this->maximumY);
141 }
142
150 constexpr glm::dvec2 getUpperRight() const noexcept {
151 return glm::dvec2(this->maximumX, this->maximumY);
152 }
153
159 constexpr glm::dvec2 getCenter() const noexcept {
160 return glm::dvec2(
161 (this->minimumX + this->maximumX) * 0.5,
162 (this->minimumY + this->maximumY) * 0.5);
163 }
164
170 constexpr double computeWidth() const noexcept {
171 return this->maximumX - this->minimumX;
172 }
173
179 constexpr double computeHeight() const noexcept {
180 return this->maximumY - this->minimumY;
181 }
182
190 std::optional<Rectangle>
191 computeIntersection(const Rectangle& other) const noexcept;
192
199 Rectangle computeUnion(const Rectangle& other) const noexcept;
200};
201
202} // 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:18
constexpr glm::dvec2 getLowerLeft() const noexcept
Returns a point at the lower left of this rectangle.
Definition Rectangle.h:117
double minimumX
The minimum x-coordinate.
Definition Rectangle.h:46
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:61
double maximumX
The maximum x-coordinate.
Definition Rectangle.h:56
double minimumY
The minimum y-coordinate.
Definition Rectangle.h:51
constexpr double computeHeight() const noexcept
Computes the height of this rectangle.
Definition Rectangle.h:179
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:170
constexpr glm::dvec2 getCenter() const noexcept
Returns a point at the center of this rectangle.
Definition Rectangle.h:159
constexpr glm::dvec2 getLowerRight() const noexcept
Returns a point at the lower right of this rectangle.
Definition Rectangle.h:128
std::optional< Rectangle > computeIntersection(const Rectangle &other) const noexcept
constexpr Rectangle(double minimumX_, double minimumY_, double maximumX_, double maximumY_) noexcept
Creates a new instance.
Definition Rectangle.h:33
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:150
constexpr glm::dvec2 getUpperLeft() const noexcept
Returns a point at the upper left of this rectangle.
Definition Rectangle.h:139