| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
#ifdef NDEBUG |
| 7 |
# undef NDEBUG |
| 8 |
#endif |
| 9 |
|
| 10 |
#include <ImathInterval.h> |
| 11 |
#include <ImathRandom.h> |
| 12 |
#include <algorithm> |
| 13 |
#include <assert.h> |
| 14 |
#include <iostream> |
| 15 |
#include <sstream> |
| 16 |
#include <typeinfo> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
// Include ImathForward *after* other headers to validate forward declarations |
| 20 |
#include <ImathForward.h> |
| 21 |
|
| 22 |
using namespace std; |
| 23 |
using namespace IMATH_INTERNAL_NAMESPACE; |
| 24 |
|
| 25 |
namespace |
| 26 |
{ |
| 27 |
|
| 28 |
template <class T> |
| 29 |
static void |
| 30 |
testConstructors (const char* type) |
| 31 |
{ |
| 32 |
cout << " constructors for type " << type << endl; |
| 33 |
|
| 34 |
// |
| 35 |
// Empty |
| 36 |
// |
| 37 |
{ |
| 38 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 39 |
assert (b.min == T (std::numeric_limits<T>::max()) && b.max == T (std::numeric_limits<T>::lowest())); |
| 40 |
} |
| 41 |
|
| 42 |
// |
| 43 |
// Single point |
| 44 |
// |
| 45 |
{ |
| 46 |
T p (42); |
| 47 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (p); |
| 48 |
assert (b.min == p && b.max == p); |
| 49 |
} |
| 50 |
|
| 51 |
// |
| 52 |
// Min and max |
| 53 |
// |
| 54 |
{ |
| 55 |
T p0 (42); |
| 56 |
T p1 (666); |
| 57 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (p0, p1); |
| 58 |
assert (b.min == p0 && b.max == p1); |
| 59 |
} |
| 60 |
|
| 61 |
{ |
| 62 |
T p0 (666); |
| 63 |
T p1 (42); |
| 64 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (p0, p1); |
| 65 |
assert (b.min == p0 && b.max == p1); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
template <class T> |
| 70 |
void |
| 71 |
testMakeEmpty (const char* type) |
| 72 |
{ |
| 73 |
cout << " makeEmpty() for type " << type << endl; |
| 74 |
|
| 75 |
// |
| 76 |
// Empty interval |
| 77 |
// |
| 78 |
{ |
| 79 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 80 |
b.makeEmpty(); |
| 81 |
assert (b.min == T (std::numeric_limits<T>::max()) && b.max == T (std::numeric_limits<T>::lowest())); |
| 82 |
} |
| 83 |
|
| 84 |
// |
| 85 |
// Non-empty, has volume |
| 86 |
// |
| 87 |
{ |
| 88 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (T (-1), T (1)); |
| 89 |
b.makeEmpty(); |
| 90 |
assert (b.min == T (std::numeric_limits<T>::max()) && b.max == T (std::numeric_limits<T>::lowest())); |
| 91 |
} |
| 92 |
|
| 93 |
// |
| 94 |
// Non-empty, no volume |
| 95 |
// |
| 96 |
{ |
| 97 |
T min (0); |
| 98 |
T max (10); |
| 99 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 100 |
b.makeEmpty(); |
| 101 |
assert (b.min == T (std::numeric_limits<T>::max()) && b.max == T (std::numeric_limits<T>::lowest())); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
template <class T> |
| 106 |
void |
| 107 |
testMakeInfinite (const char* type) |
| 108 |
{ |
| 109 |
cout << " makeInfinite() for type " << type << endl; |
| 110 |
|
| 111 |
// |
| 112 |
// Infinite interval |
| 113 |
// |
| 114 |
{ |
| 115 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 116 |
b.makeInfinite(); |
| 117 |
assert (b.min == T (std::numeric_limits<T>::lowest()) && b.max == T (std::numeric_limits<T>::max())); |
| 118 |
} |
| 119 |
|
| 120 |
// |
| 121 |
// Non-empty, has volume |
| 122 |
// |
| 123 |
{ |
| 124 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (T (-1), T (1)); |
| 125 |
b.makeInfinite(); |
| 126 |
assert (b.min == T (std::numeric_limits<T>::lowest()) && b.max == T (std::numeric_limits<T>::max())); |
| 127 |
} |
| 128 |
|
| 129 |
// |
| 130 |
// Non-empty, no volume |
| 131 |
// |
| 132 |
{ |
| 133 |
T min (0); |
| 134 |
T max (1); |
| 135 |
|
| 136 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 137 |
b.makeInfinite(); |
| 138 |
assert (b.min == T (std::numeric_limits<T>::lowest()) && b.max == T (std::numeric_limits<T>::max())); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
template <class T> |
| 143 |
void |
| 144 |
testExtendByPoint (const char* type) |
| 145 |
{ |
| 146 |
cout << " extendBy() point for type " << type << endl; |
| 147 |
|
| 148 |
IMATH_INTERNAL_NAMESPACE::Rand32 rand (0); |
| 149 |
|
| 150 |
const unsigned int iters = 10; |
| 151 |
|
| 152 |
// |
| 153 |
// Extend empty interval with a single point. |
| 154 |
// |
| 155 |
for (unsigned int i = 0; i < iters; i++) |
| 156 |
{ |
| 157 |
T p (static_cast<T>(rand.nextf (-12345, 12345))); |
| 158 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 159 |
b.extendBy (p); |
| 160 |
assert (b.min == p && b.max == p); |
| 161 |
} |
| 162 |
|
| 163 |
// |
| 164 |
// Extend empty interval with a number of random points. Note that |
| 165 |
// this also covers extending a non-empty interval. |
| 166 |
// |
| 167 |
for (unsigned int i = 0; i < iters; i++) |
| 168 |
{ |
| 169 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 170 |
|
| 171 |
T min; |
| 172 |
T max; |
| 173 |
|
| 174 |
for (unsigned int j = 0; j < i; j++) |
| 175 |
{ |
| 176 |
T p (static_cast<T>(rand.nextf (-12345, 12345))); |
| 177 |
|
| 178 |
if (j == 0) |
| 179 |
{ |
| 180 |
min = p; |
| 181 |
max = p; |
| 182 |
} |
| 183 |
|
| 184 |
min = std::min (min, p); |
| 185 |
max = std::max (max, p); |
| 186 |
|
| 187 |
b.extendBy (p); |
| 188 |
|
| 189 |
assert (b.min == min && b.max == max); |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
template <class T> |
| 195 |
void |
| 196 |
testExtendByInterval (const char* type) |
| 197 |
{ |
| 198 |
cout << " extendBy() interval for type " << type << endl; |
| 199 |
|
| 200 |
// |
| 201 |
// Extend empty interval with an empty interval |
| 202 |
// |
| 203 |
{ |
| 204 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 205 |
b.extendBy (IMATH_INTERNAL_NAMESPACE::Interval<T>()); |
| 206 |
assert (b.min == T (std::numeric_limits<T>::max()) && b.max == T (std::numeric_limits<T>::lowest())); |
| 207 |
} |
| 208 |
|
| 209 |
// |
| 210 |
// Extend empty interval with a non-empty interval and vice versa. |
| 211 |
// |
| 212 |
{ |
| 213 |
T p0 (-1); |
| 214 |
T p1 (1); |
| 215 |
|
| 216 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0; |
| 217 |
b0.extendBy (IMATH_INTERNAL_NAMESPACE::Interval<T> (p0, p1)); |
| 218 |
assert (b0.min == p0 && b0.max == p1); |
| 219 |
|
| 220 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (p0, p1); |
| 221 |
b1.extendBy (IMATH_INTERNAL_NAMESPACE::Interval<T>()); |
| 222 |
assert (b1.min == p0 && b1.max == p1); |
| 223 |
} |
| 224 |
|
| 225 |
// |
| 226 |
// Extend non-empty interval with non-empty interval. Starts with empty, then builds. |
| 227 |
// |
| 228 |
IMATH_INTERNAL_NAMESPACE::Rand32 rand (0); |
| 229 |
const unsigned int iters = 10; |
| 230 |
{ |
| 231 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 232 |
|
| 233 |
T min, max; |
| 234 |
|
| 235 |
for (unsigned int i = 1; i < iters; i++) |
| 236 |
{ |
| 237 |
T p0 (static_cast<T>(rand.nextf (0, 999))); |
| 238 |
T p1 (static_cast<T>(rand.nextf (1000, 1999))); |
| 239 |
|
| 240 |
min = b.min; |
| 241 |
max = b.max; |
| 242 |
min = std::min (min, p0); |
| 243 |
max = std::max (max, p1); |
| 244 |
|
| 245 |
b.extendBy (IMATH_INTERNAL_NAMESPACE::Interval<T> (p0, p1)); |
| 246 |
|
| 247 |
assert (b.min == min && b.max == max); |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
template <class T> |
| 253 |
void |
| 254 |
testComparators (const char* type) |
| 255 |
{ |
| 256 |
cout << " comparators for type " << type << endl; |
| 257 |
|
| 258 |
IMATH_INTERNAL_NAMESPACE::Rand32 rand (0); |
| 259 |
|
| 260 |
// |
| 261 |
// Compare empty. |
| 262 |
// |
| 263 |
{ |
| 264 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0; |
| 265 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1; |
| 266 |
|
| 267 |
assert (b0 == b1); |
| 268 |
assert (!(b0 != b1)); |
| 269 |
} |
| 270 |
|
| 271 |
// |
| 272 |
// Compare empty to non-empty. |
| 273 |
// |
| 274 |
{ |
| 275 |
T p0 (-1); |
| 276 |
T p1 (1); |
| 277 |
|
| 278 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0; |
| 279 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (p0, p1); |
| 280 |
assert (!(b0 == b1)); |
| 281 |
assert (b0 != b1); |
| 282 |
} |
| 283 |
|
| 284 |
// |
| 285 |
// Compare two non-empty |
| 286 |
// |
| 287 |
{ |
| 288 |
T p0 (-1); |
| 289 |
T p1 (1); |
| 290 |
|
| 291 |
T p2 (-2); |
| 292 |
T p3 (2); |
| 293 |
|
| 294 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (p0, p1); |
| 295 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (p2, p3); |
| 296 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b2 (p0, p1); |
| 297 |
|
| 298 |
assert (b0 != b1); |
| 299 |
assert (!(b0 == b1)); |
| 300 |
|
| 301 |
assert (b0 == b2); |
| 302 |
assert (!(b0 != b2)); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
template <class T> |
| 307 |
void |
| 308 |
testIntersects (const char* type) |
| 309 |
{ |
| 310 |
cout << " intersects() for type " << type << endl; |
| 311 |
|
| 312 |
IMATH_INTERNAL_NAMESPACE::Rand32 rand (0); |
| 313 |
|
| 314 |
// |
| 315 |
// Intersect point with empty interval. |
| 316 |
// |
| 317 |
{ |
| 318 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 319 |
T p (1); |
| 320 |
|
| 321 |
assert (!b.intersects (p)); |
| 322 |
} |
| 323 |
|
| 324 |
// |
| 325 |
// Intersect point with non-empty, has-volume interval. |
| 326 |
// |
| 327 |
{ |
| 328 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (T (-1), T (1)); |
| 329 |
T p0 (0); |
| 330 |
T p1 (5); |
| 331 |
T p2 (-5); |
| 332 |
|
| 333 |
assert (b.intersects (p0)); |
| 334 |
assert (!b.intersects (p1)); |
| 335 |
assert (!b.intersects (p2)); |
| 336 |
} |
| 337 |
|
| 338 |
// |
| 339 |
// Intersect point with non-empty, no-volume interval. |
| 340 |
// |
| 341 |
{ |
| 342 |
T min (0); |
| 343 |
T max (1); |
| 344 |
|
| 345 |
T p0 (0); |
| 346 |
T p1 (5); |
| 347 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 348 |
|
| 349 |
assert (b.intersects (p0)); |
| 350 |
assert (!b.intersects (p1)); |
| 351 |
} |
| 352 |
|
| 353 |
// |
| 354 |
// Intersect empty interval with empty interval. |
| 355 |
// |
| 356 |
{ |
| 357 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0; |
| 358 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1; |
| 359 |
|
| 360 |
assert (!b0.intersects (b1)); |
| 361 |
assert (!b1.intersects (b0)); |
| 362 |
} |
| 363 |
|
| 364 |
// |
| 365 |
// Intersect empty interval with non-empty has-volume intervales. |
| 366 |
// |
| 367 |
{ |
| 368 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0; |
| 369 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (T (-1), T (1)); |
| 370 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b2 (T (1), T (2)); |
| 371 |
|
| 372 |
assert (!b0.intersects (b1)); |
| 373 |
assert (!b0.intersects (b2)); |
| 374 |
|
| 375 |
assert (!b1.intersects (b0)); |
| 376 |
assert (!b2.intersects (b0)); |
| 377 |
} |
| 378 |
|
| 379 |
// |
| 380 |
// Intersect empty interval with non-empty no-volume interval. |
| 381 |
// |
| 382 |
{ |
| 383 |
T min (0); |
| 384 |
T max = min; |
| 385 |
max[T::dimensions() - 1] = 1; |
| 386 |
|
| 387 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0; |
| 388 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (min, max); |
| 389 |
|
| 390 |
assert (!b0.intersects (b1)); |
| 391 |
assert (!b1.intersects (b0)); |
| 392 |
} |
| 393 |
|
| 394 |
// |
| 395 |
// Intersect non-empty has-volume interval with non-empty has-volume interval. |
| 396 |
// |
| 397 |
{ |
| 398 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (T (-1), T (1)); |
| 399 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b2 (T (-1), T (1)); |
| 400 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b3 (T (1), T (2)); |
| 401 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b4 (T (2), T (3)); |
| 402 |
|
| 403 |
assert (b1.intersects (b1)); |
| 404 |
assert (b1.intersects (b3)); |
| 405 |
assert (!b1.intersects (b4)); |
| 406 |
|
| 407 |
assert (b3.intersects (b1)); |
| 408 |
assert (!b4.intersects (b1)); |
| 409 |
} |
| 410 |
|
| 411 |
// |
| 412 |
// Intersect non-empty has-volume interval with non-empty no-volume interval. |
| 413 |
// |
| 414 |
{ |
| 415 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (T (-1), T (1)); |
| 416 |
|
| 417 |
T min (0); |
| 418 |
T max (1); |
| 419 |
|
| 420 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (min, max); |
| 421 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b2 (min + T (2), max + T (2)); |
| 422 |
|
| 423 |
assert (b0.intersects (b1)); |
| 424 |
assert (b1.intersects (b0)); |
| 425 |
|
| 426 |
assert (!b0.intersects (b2)); |
| 427 |
assert (!b2.intersects (b1)); |
| 428 |
} |
| 429 |
|
| 430 |
// |
| 431 |
// Intersect non-empty no-volume interval with non-empty no-volume interval. |
| 432 |
// |
| 433 |
{ |
| 434 |
T min (0); |
| 435 |
T max (1); |
| 436 |
|
| 437 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (min, max); |
| 438 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (min, max + T (2)); |
| 439 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b2 (min + T (2), max + T (2)); |
| 440 |
|
| 441 |
assert (b0.intersects (b1)); |
| 442 |
assert (b1.intersects (b0)); |
| 443 |
|
| 444 |
assert (!b0.intersects (b2)); |
| 445 |
assert (!b2.intersects (b0)); |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
template <class T> |
| 450 |
void |
| 451 |
testSize (const char* type) |
| 452 |
{ |
| 453 |
cout << " size() for type " << type << endl; |
| 454 |
|
| 455 |
// |
| 456 |
// Size of empty interval. |
| 457 |
// |
| 458 |
{ |
| 459 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 460 |
assert (b.size() == T (0)); |
| 461 |
} |
| 462 |
|
| 463 |
// |
| 464 |
// Size of non-empty, has-volume interval. |
| 465 |
// |
| 466 |
{ |
| 467 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (T (-1), T (1)); |
| 468 |
assert (b0.size() == T (2)); |
| 469 |
|
| 470 |
T p (42); |
| 471 |
|
| 472 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (-p, p); |
| 473 |
assert (b1.size() == p * T (2)); |
| 474 |
} |
| 475 |
|
| 476 |
// |
| 477 |
// Size of non-empty, no-volume interval. |
| 478 |
// |
| 479 |
{ |
| 480 |
T min (0); |
| 481 |
T max (1); |
| 482 |
|
| 483 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 484 |
|
| 485 |
assert (b.size() == max); |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
template <class T> |
| 490 |
void |
| 491 |
testCenter (const char* type) |
| 492 |
{ |
| 493 |
cout << " center() for type " << type << endl; |
| 494 |
|
| 495 |
// |
| 496 |
// Center of empty interval. |
| 497 |
// |
| 498 |
{ |
| 499 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 500 |
assert (b.center() == T (0)); |
| 501 |
} |
| 502 |
|
| 503 |
// |
| 504 |
// Center of non-empty, has-volume interval. |
| 505 |
// |
| 506 |
{ |
| 507 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (T (-1), T (1)); |
| 508 |
assert (b0.center() == T (0)); |
| 509 |
|
| 510 |
T p0 (1); |
| 511 |
T p1 (2); |
| 512 |
|
| 513 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (p0, p1); |
| 514 |
assert (b1.center() == (p1 + p0) / 2); |
| 515 |
} |
| 516 |
|
| 517 |
// |
| 518 |
// Center of non-empty, no-volume interval. |
| 519 |
// |
| 520 |
{ |
| 521 |
T min (0); |
| 522 |
T max (2); |
| 523 |
|
| 524 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 525 |
|
| 526 |
assert (b.center() == max / 2); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
template <class T> |
| 531 |
void |
| 532 |
testIsEmpty (const char* type) |
| 533 |
{ |
| 534 |
cout << " isEmpty() for type " << type << endl; |
| 535 |
|
| 536 |
// |
| 537 |
// Empty interval. |
| 538 |
// |
| 539 |
{ |
| 540 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 541 |
assert (b.isEmpty()); |
| 542 |
} |
| 543 |
|
| 544 |
// |
| 545 |
// Non-empty, has-volume interval. |
| 546 |
// |
| 547 |
{ |
| 548 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (T (-1), T (1)); |
| 549 |
assert (!b0.isEmpty()); |
| 550 |
|
| 551 |
T p0 (2); |
| 552 |
T p1 (4); |
| 553 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (p0, p1); |
| 554 |
assert (!b1.isEmpty()); |
| 555 |
} |
| 556 |
|
| 557 |
// |
| 558 |
// Non-empty, no-volume interval. |
| 559 |
// |
| 560 |
{ |
| 561 |
T min (0); |
| 562 |
T max (2); |
| 563 |
|
| 564 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 565 |
|
| 566 |
assert (!b.isEmpty()); |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
template <class T> |
| 571 |
void |
| 572 |
testIsInfinite (const char* type) |
| 573 |
{ |
| 574 |
cout << " isInfinite() for type " << type << endl; |
| 575 |
|
| 576 |
// |
| 577 |
// Infinite interval. |
| 578 |
// |
| 579 |
{ |
| 580 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 581 |
b.makeInfinite(); |
| 582 |
assert (b.isInfinite()); |
| 583 |
} |
| 584 |
|
| 585 |
// |
| 586 |
// Non-empty, has-volume interval. |
| 587 |
// |
| 588 |
{ |
| 589 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (T (-1), T (1)); |
| 590 |
assert (!b0.isInfinite()); |
| 591 |
|
| 592 |
T p0 (2); |
| 593 |
T p1 (4); |
| 594 |
|
| 595 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (p0, p1); |
| 596 |
assert (!b1.isInfinite()); |
| 597 |
} |
| 598 |
|
| 599 |
// |
| 600 |
// Non-empty, no-volume interval. |
| 601 |
// |
| 602 |
{ |
| 603 |
T min (0); |
| 604 |
T max (2); |
| 605 |
|
| 606 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 607 |
|
| 608 |
assert (!b.isInfinite()); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
template <class T> |
| 613 |
void |
| 614 |
testHasVolume (const char* type) |
| 615 |
{ |
| 616 |
cout << " hasVolume() for type " << type << endl; |
| 617 |
|
| 618 |
// |
| 619 |
// Empty interval. |
| 620 |
// |
| 621 |
{ |
| 622 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 623 |
assert (!b.hasVolume()); |
| 624 |
} |
| 625 |
|
| 626 |
// |
| 627 |
// Infinite interval. |
| 628 |
// |
| 629 |
{ |
| 630 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b; |
| 631 |
b.makeInfinite(); |
| 632 |
assert (b.hasVolume()); |
| 633 |
} |
| 634 |
|
| 635 |
// |
| 636 |
// Non-empty, has-volume interval. |
| 637 |
// |
| 638 |
{ |
| 639 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b0 (T (-1), T (1)); |
| 640 |
assert (b0.hasVolume()); |
| 641 |
|
| 642 |
T p0 (2); |
| 643 |
T p1 (4); |
| 644 |
|
| 645 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b1 (p0, p1); |
| 646 |
assert (b1.hasVolume()); |
| 647 |
} |
| 648 |
|
| 649 |
// |
| 650 |
// Non-empty, no-volume interval. |
| 651 |
// |
| 652 |
{ |
| 653 |
T min (0); |
| 654 |
T max (2); |
| 655 |
|
| 656 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 657 |
b.makeEmpty(); |
| 658 |
assert (!b.hasVolume()); |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
template <class T> |
| 663 |
void |
| 664 |
testStream (const char* type) |
| 665 |
{ |
| 666 |
cout << " hasVolume() for type " << type << endl; |
| 667 |
|
| 668 |
T min (0); |
| 669 |
T max (1); |
| 670 |
|
| 671 |
IMATH_INTERNAL_NAMESPACE::Interval<T> b (min, max); |
| 672 |
std::stringstream s1; |
| 673 |
s1 << '(' << min << ' ' << max << ')'; |
| 674 |
|
| 675 |
std::stringstream s2; |
| 676 |
s2 << b; |
| 677 |
|
| 678 |
assert (s1.str() == s2.str()); |
| 679 |
} |
| 680 |
|
| 681 |
} // anonymous namespace |
| 682 |
|
| 683 |
void |
| 684 |
testInterval() |
| 685 |
{ |
| 686 |
cout << "Testing interval methods" << endl; |
| 687 |
|
| 688 |
// |
| 689 |
// Constructors |
| 690 |
// |
| 691 |
testConstructors<short> ("short"); |
| 692 |
testConstructors<int> ("int"); |
| 693 |
testConstructors<float> ("float"); |
| 694 |
testConstructors<double> ("double"); |
| 695 |
|
| 696 |
// |
| 697 |
// makeEmpty() |
| 698 |
// |
| 699 |
testMakeEmpty<short> ("short"); |
| 700 |
testMakeEmpty<int> ("int"); |
| 701 |
testMakeEmpty<float> ("float"); |
| 702 |
testMakeEmpty<double> ("double"); |
| 703 |
|
| 704 |
// |
| 705 |
// makeInfinite() |
| 706 |
// |
| 707 |
testMakeInfinite<short> ("short"); |
| 708 |
testMakeInfinite<int> ("int"); |
| 709 |
testMakeInfinite<float> ("float"); |
| 710 |
testMakeInfinite<double> ("double"); |
| 711 |
|
| 712 |
// |
| 713 |
// extendBy() (point) |
| 714 |
// |
| 715 |
testExtendByPoint<short> ("short"); |
| 716 |
testExtendByPoint<int> ("int"); |
| 717 |
testExtendByPoint<float> ("float"); |
| 718 |
testExtendByPoint<double> ("double"); |
| 719 |
|
| 720 |
// |
| 721 |
// extendBy() interval |
| 722 |
// |
| 723 |
testExtendByInterval<short> ("short"); |
| 724 |
testExtendByInterval<int> ("int"); |
| 725 |
testExtendByInterval<float> ("float"); |
| 726 |
testExtendByInterval<double> ("double"); |
| 727 |
|
| 728 |
// |
| 729 |
// == and !== |
| 730 |
// |
| 731 |
testComparators<short> ("short"); |
| 732 |
testComparators<int> ("int"); |
| 733 |
testComparators<float> ("float"); |
| 734 |
testComparators<double> ("double"); |
| 735 |
|
| 736 |
// |
| 737 |
// size() |
| 738 |
// |
| 739 |
testSize<short> ("short"); |
| 740 |
testSize<int> ("int"); |
| 741 |
testSize<float> ("float"); |
| 742 |
testSize<double> ("double"); |
| 743 |
|
| 744 |
// |
| 745 |
// center() |
| 746 |
// |
| 747 |
testCenter<short> ("short"); |
| 748 |
testCenter<int> ("int"); |
| 749 |
testCenter<float> ("float"); |
| 750 |
testCenter<double> ("double"); |
| 751 |
|
| 752 |
// |
| 753 |
// isEmpty() |
| 754 |
// |
| 755 |
testIsEmpty<short> ("short"); |
| 756 |
testIsEmpty<int> ("int"); |
| 757 |
testIsEmpty<float> ("float"); |
| 758 |
testIsEmpty<double> ("double"); |
| 759 |
|
| 760 |
// |
| 761 |
// isInfinite() |
| 762 |
// |
| 763 |
testIsInfinite<short> ("short"); |
| 764 |
testIsInfinite<int> ("int"); |
| 765 |
testIsInfinite<float> ("float"); |
| 766 |
testIsInfinite<double> ("double"); |
| 767 |
|
| 768 |
// |
| 769 |
// hasVolume() |
| 770 |
// |
| 771 |
testHasVolume<short> ("short"); |
| 772 |
testHasVolume<int> ("int"); |
| 773 |
testHasVolume<float> ("float"); |
| 774 |
testHasVolume<double> ("double"); |
| 775 |
|
| 776 |
// |
| 777 |
// stream |
| 778 |
// |
| 779 |
testStream<short> ("short"); |
| 780 |
testStream<int> ("int"); |
| 781 |
testStream<float> ("float"); |
| 782 |
testStream<double> ("double"); |
| 783 |
|
| 784 |
cout << "ok\n" << endl; |
| 785 |
} |