Skip to content

Commit cb4ee47

Browse files
committed
Add BoundingRegionBuilder::expandToIncludeBoundingRegion
1 parent f7e8eab commit cb4ee47

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

CesiumGeospatial/include/CesiumGeospatial/BoundingRegionBuilder.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ class CESIUMGEOSPATIAL_API BoundingRegionBuilder {
8282
*/
8383
bool expandToIncludeGlobeRectangle(const GlobeRectangle& rectangle);
8484

85+
/**
86+
* @brief Expands the bounding region to include the given bounding region.
87+
*
88+
* The region will be kept as small as possible.
89+
*
90+
* @param region The region to be included in the region.
91+
* @returns True if the region was modified, or false if the region already
92+
* contained the region.
93+
*/
94+
bool expandToIncludeBoundingRegion(const BoundingRegion& region);
95+
8596
private:
8697
/**
8798
* @brief When a position's latitude is within this distance in radians from

CesiumGeospatial/src/BoundingRegionBuilder.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,25 @@ bool BoundingRegionBuilder::expandToIncludeGlobeRectangle(
145145
return modified;
146146
}
147147

148+
bool BoundingRegionBuilder::expandToIncludeBoundingRegion(
149+
const BoundingRegion& region) {
150+
bool modified = false;
151+
152+
if (expandToIncludeGlobeRectangle(region.getRectangle())) {
153+
modified = true;
154+
}
155+
156+
if (region.getMinimumHeight() < this->_minimumHeight) {
157+
this->_minimumHeight = region.getMinimumHeight();
158+
modified = true;
159+
}
160+
161+
if (region.getMaximumHeight() > this->_maximumHeight) {
162+
this->_maximumHeight = region.getMaximumHeight();
163+
modified = true;
164+
}
165+
166+
return modified;
167+
}
168+
148169
} // namespace CesiumGeospatial

CesiumGeospatial/test/TestBoundingRegionBuilder.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <CesiumGeospatial/BoundingRegion.h>
12
#include <CesiumGeospatial/BoundingRegionBuilder.h>
23
#include <CesiumGeospatial/Ellipsoid.h>
34
#include <CesiumGeospatial/GlobeRectangle.h>
@@ -183,3 +184,107 @@ TEST_CASE("BoundingRegionBuilder::expandToIncludeGlobeRectangle") {
183184
Math::Epsilon15));
184185
}
185186
}
187+
188+
TEST_CASE("BoundingRegionBuilder::expandToIncludeBoundingRegion") {
189+
SUBCASE("expands to include rectangle") {
190+
BoundingRegionBuilder builder;
191+
bool modified = builder.expandToIncludeBoundingRegion(
192+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0));
193+
BoundingRegion region = builder.toRegion();
194+
CHECK(BoundingRegion::equalsEpsilon(
195+
region,
196+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0),
197+
Math::Epsilon15));
198+
CHECK(modified);
199+
200+
SUBCASE("does nothing if the rectangle is already included") {
201+
modified = builder.expandToIncludeBoundingRegion(
202+
BoundingRegion(GlobeRectangle(0.15, 0.25, 0.25, 0.35), -1.0, 2.0));
203+
region = builder.toRegion();
204+
CHECK(BoundingRegion::equalsEpsilon(
205+
region,
206+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0),
207+
Math::Epsilon15));
208+
CHECK_FALSE(modified);
209+
}
210+
211+
SUBCASE("expands if rectangle is not included") {
212+
modified = builder.expandToIncludeBoundingRegion(
213+
BoundingRegion(GlobeRectangle(0.05, 0.15, 0.35, 0.45), -1.0, 2.0));
214+
region = builder.toRegion();
215+
CHECK(BoundingRegion::equalsEpsilon(
216+
region,
217+
BoundingRegion(GlobeRectangle(0.05, 0.15, 0.35, 0.45), -1.0, 2.0),
218+
Math::Epsilon15));
219+
CHECK(modified);
220+
}
221+
}
222+
223+
SUBCASE("expands to include min height") {
224+
BoundingRegionBuilder builder;
225+
bool modified = builder.expandToIncludeBoundingRegion(
226+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0));
227+
BoundingRegion region = builder.toRegion();
228+
CHECK(BoundingRegion::equalsEpsilon(
229+
region,
230+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0),
231+
Math::Epsilon15));
232+
CHECK(modified);
233+
234+
SUBCASE("does nothing if min height is already included") {
235+
modified = builder.expandToIncludeBoundingRegion(
236+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -0.5, 2.0));
237+
region = builder.toRegion();
238+
CHECK(BoundingRegion::equalsEpsilon(
239+
region,
240+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0),
241+
Math::Epsilon15));
242+
CHECK_FALSE(modified);
243+
}
244+
245+
SUBCASE("expands to include min height") {
246+
modified = builder.expandToIncludeBoundingRegion(
247+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.5, 2.0));
248+
region = builder.toRegion();
249+
CHECK(BoundingRegion::equalsEpsilon(
250+
region,
251+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.5, 2.0),
252+
Math::Epsilon15));
253+
CHECK(modified);
254+
}
255+
}
256+
257+
SUBCASE("expands to include max height") {
258+
BoundingRegionBuilder builder;
259+
bool modified = builder.expandToIncludeBoundingRegion(
260+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0));
261+
BoundingRegion region = builder.toRegion();
262+
CHECK(BoundingRegion::equalsEpsilon(
263+
region,
264+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0),
265+
Math::Epsilon15));
266+
CHECK(modified);
267+
268+
SUBCASE("does nothing if max height is already included") {
269+
modified = builder.expandToIncludeBoundingRegion(
270+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 1.5));
271+
region = builder.toRegion();
272+
CHECK(BoundingRegion::equalsEpsilon(
273+
region,
274+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.0),
275+
Math::Epsilon15));
276+
CHECK_FALSE(modified);
277+
}
278+
279+
SUBCASE("expands to include max height") {
280+
modified = builder.expandToIncludeBoundingRegion(
281+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.5));
282+
region = builder.toRegion();
283+
CHECK(BoundingRegion::equalsEpsilon(
284+
region,
285+
BoundingRegion(GlobeRectangle(0.1, 0.2, 0.3, 0.4), -1.0, 2.5),
286+
Math::Epsilon15));
287+
CHECK(modified);
288+
}
289+
}
290+
}

0 commit comments

Comments
 (0)