MOAB: Mesh Oriented datABase  (version 5.5.0)
GeomUtilTests.cpp File Reference
#include "moab/Core.hpp"
#include "moab/GeomUtil.hpp"
#include <iostream>
#include "TestUtil.hpp"
+ Include dependency graph for GeomUtilTests.cpp:

Go to the source code of this file.

Classes

class  ElemOverlapTest
 
class  LinearElemOverlapTest
 
class  TypeElemOverlapTest
 

Macros

#define ASSERT_VECTORS_EQUAL(A, B)   assert_vectors_equal( ( A ), ( B ), #A, #B, __LINE__ )
 
#define ASSERT_DOUBLES_EQUAL(A, B)   CHECK_REAL_EQUAL( A, B, TOL )
 
#define ASSERT(B)   CHECK( B )
 

Functions

void assert_vectors_equal (const CartVect &a, const CartVect &b, const char *sa, const char *sb, int lineno)
 
void test_box_plane_norm (CartVect norm, CartVect min, CartVect max)
 
void test_box_plane_axis (int axis, double ns, const CartVect &min, const CartVect &max)
 
void test_box_plane_edge (int axis1, int axis2, bool flip_axis2, CartVect min, CartVect max)
 
void test_box_plane_corner (int xdir, int ydir, int zdir, CartVect min, CartVect max)
 
void test_box_plane_overlap ()
 
void general_box_tri_overlap_test (const ElemOverlapTest &overlap)
 
void general_box_hex_overlap_test (const ElemOverlapTest &overlap)
 
void general_box_tet_overlap_test (const ElemOverlapTest &overlap)
 
void test_box_tri_overlap ()
 
void test_box_linear_elem_overlap_tri ()
 
void test_box_hex_overlap ()
 
void test_box_linear_elem_overlap_hex ()
 
void test_box_tet_overlap ()
 
void test_box_linear_elem_overlap_tet ()
 
void test_ray_tri_intersect ()
 
void test_plucker_ray_tri_intersect ()
 
void test_closest_location_on_tri ()
 
void test_closest_location_on_polygon ()
 
void test_segment_box_intersect ()
 
void test_closest_location_on_box ()
 
int main ()
 

Variables

const double TOL = 1e-6
 

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   B)    CHECK( B )

Definition at line 13 of file GeomUtilTests.cpp.

◆ ASSERT_DOUBLES_EQUAL

#define ASSERT_DOUBLES_EQUAL (   A,
 
)    CHECK_REAL_EQUAL( A, B, TOL )

Definition at line 12 of file GeomUtilTests.cpp.

◆ ASSERT_VECTORS_EQUAL

#define ASSERT_VECTORS_EQUAL (   A,
 
)    assert_vectors_equal( ( A ), ( B ), #A, #B, __LINE__ )

Definition at line 11 of file GeomUtilTests.cpp.

Function Documentation

◆ assert_vectors_equal()

void assert_vectors_equal ( const CartVect a,
const CartVect b,
const char *  sa,
const char *  sb,
int  lineno 
)

Definition at line 15 of file GeomUtilTests.cpp.

16 {
17  if( fabs( a[0] - b[0] ) > TOL || fabs( a[1] - b[1] ) > TOL || fabs( a[2] - b[2] ) > TOL )
18  {
19  std::cerr << "Assertion failed at line " << lineno << std::endl
20  << "\t" << sa << " == " << sb << std::endl
21  << "\t[" << a[0] << ", " << a[1] << ", " << a[2] << "] == [" << b[0] << ", " << b[1] << ", " << b[2]
22  << "]" << std::endl;
23  FLAG_ERROR;
24  }
25 }

References FLAG_ERROR, and TOL.

◆ general_box_hex_overlap_test()

void general_box_hex_overlap_test ( const ElemOverlapTest overlap)

Definition at line 373 of file GeomUtilTests.cpp.

374 {
375  CartVect coords[8];
376 
377  // test against axis-aligned rectilinear hex
378  coords[0] = CartVect( -0.5, -0.5, -0.5 );
379  coords[1] = CartVect( 0.5, -0.5, -0.5 );
380  coords[2] = CartVect( 0.5, 0.5, -0.5 );
381  coords[3] = CartVect( -0.5, 0.5, -0.5 );
382  coords[4] = CartVect( -0.5, -0.5, 0.5 );
383  coords[5] = CartVect( 0.5, -0.5, 0.5 );
384  coords[6] = CartVect( 0.5, 0.5, 0.5 );
385  coords[7] = CartVect( -0.5, 0.5, 0.5 );
386 
387  ASSERT( overlap( coords, CartVect( 0, 0, 0 ), CartVect( 1, 1, 1 ) ) );
388 
389  ASSERT( overlap( coords, CartVect( 1, 0, 0 ), CartVect( 1, 1, 1 ) ) );
390  ASSERT( overlap( coords, CartVect( 0, 1, 0 ), CartVect( 1, 1, 1 ) ) );
391  ASSERT( overlap( coords, CartVect( 0, 0, 1 ), CartVect( 1, 1, 1 ) ) );
392  ASSERT( overlap( coords, CartVect( -1, 0, 0 ), CartVect( 1, 1, 1 ) ) );
393  ASSERT( overlap( coords, CartVect( 0, -1, 0 ), CartVect( 1, 1, 1 ) ) );
394  ASSERT( overlap( coords, CartVect( 0, 0, -1 ), CartVect( 1, 1, 1 ) ) );
395 
396  ASSERT( overlap( coords, CartVect( 1, 1, 0 ), CartVect( 1, 1, 1 ) ) );
397  ASSERT( overlap( coords, CartVect( -1, 1, 0 ), CartVect( 1, 1, 1 ) ) );
398  ASSERT( overlap( coords, CartVect( -1, -1, 0 ), CartVect( 1, 1, 1 ) ) );
399  ASSERT( overlap( coords, CartVect( 1, -1, 0 ), CartVect( 1, 1, 1 ) ) );
400  ASSERT( overlap( coords, CartVect( 1, 0, 1 ), CartVect( 1, 1, 1 ) ) );
401  ASSERT( overlap( coords, CartVect( -1, 0, 1 ), CartVect( 1, 1, 1 ) ) );
402  ASSERT( overlap( coords, CartVect( -1, 0, -1 ), CartVect( 1, 1, 1 ) ) );
403  ASSERT( overlap( coords, CartVect( 1, 0, -1 ), CartVect( 1, 1, 1 ) ) );
404  ASSERT( overlap( coords, CartVect( 0, 1, 1 ), CartVect( 1, 1, 1 ) ) );
405  ASSERT( overlap( coords, CartVect( 0, -1, 1 ), CartVect( 1, 1, 1 ) ) );
406  ASSERT( overlap( coords, CartVect( 0, -1, -1 ), CartVect( 1, 1, 1 ) ) );
407  ASSERT( overlap( coords, CartVect( 0, 1, -1 ), CartVect( 1, 1, 1 ) ) );
408 
409  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
410  ASSERT( overlap( coords, CartVect( -1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
411  ASSERT( overlap( coords, CartVect( -1, -1, 1 ), CartVect( 1, 1, 1 ) ) );
412  ASSERT( overlap( coords, CartVect( 1, -1, 1 ), CartVect( 1, 1, 1 ) ) );
413  ASSERT( overlap( coords, CartVect( 1, 1, -1 ), CartVect( 1, 1, 1 ) ) );
414  ASSERT( overlap( coords, CartVect( -1, 1, -1 ), CartVect( 1, 1, 1 ) ) );
415  ASSERT( overlap( coords, CartVect( -1, -1, -1 ), CartVect( 1, 1, 1 ) ) );
416  ASSERT( overlap( coords, CartVect( 1, -1, -1 ), CartVect( 1, 1, 1 ) ) );
417 
418  ASSERT( !overlap( coords, CartVect( 3, 0, 0 ), CartVect( 1, 1, 1 ) ) );
419  ASSERT( !overlap( coords, CartVect( 0, 3, 0 ), CartVect( 1, 1, 1 ) ) );
420  ASSERT( !overlap( coords, CartVect( 0, 0, 3 ), CartVect( 1, 1, 1 ) ) );
421  ASSERT( !overlap( coords, CartVect( -3, 0, 0 ), CartVect( 1, 1, 1 ) ) );
422  ASSERT( !overlap( coords, CartVect( 0, -3, 0 ), CartVect( 1, 1, 1 ) ) );
423  ASSERT( !overlap( coords, CartVect( 0, 0, -3 ), CartVect( 1, 1, 1 ) ) );
424 
425  ASSERT( !overlap( coords, CartVect( 3, 3, 0 ), CartVect( 1, 1, 1 ) ) );
426  ASSERT( !overlap( coords, CartVect( -3, 3, 0 ), CartVect( 1, 1, 1 ) ) );
427  ASSERT( !overlap( coords, CartVect( -3, -3, 0 ), CartVect( 1, 1, 1 ) ) );
428  ASSERT( !overlap( coords, CartVect( 3, -3, 0 ), CartVect( 1, 1, 1 ) ) );
429  ASSERT( !overlap( coords, CartVect( 3, 0, 3 ), CartVect( 1, 1, 1 ) ) );
430  ASSERT( !overlap( coords, CartVect( -3, 0, 3 ), CartVect( 1, 1, 1 ) ) );
431  ASSERT( !overlap( coords, CartVect( -3, 0, -3 ), CartVect( 1, 1, 1 ) ) );
432  ASSERT( !overlap( coords, CartVect( 3, 0, -3 ), CartVect( 1, 1, 1 ) ) );
433  ASSERT( !overlap( coords, CartVect( 0, 3, 3 ), CartVect( 1, 1, 1 ) ) );
434  ASSERT( !overlap( coords, CartVect( 0, -3, 3 ), CartVect( 1, 1, 1 ) ) );
435  ASSERT( !overlap( coords, CartVect( 0, -3, -3 ), CartVect( 1, 1, 1 ) ) );
436  ASSERT( !overlap( coords, CartVect( 0, 3, -3 ), CartVect( 1, 1, 1 ) ) );
437 
438  ASSERT( !overlap( coords, CartVect( 3, 3, 3 ), CartVect( 1, 1, 1 ) ) );
439  ASSERT( !overlap( coords, CartVect( -3, 3, 3 ), CartVect( 1, 1, 1 ) ) );
440  ASSERT( !overlap( coords, CartVect( -3, -3, 3 ), CartVect( 1, 1, 1 ) ) );
441  ASSERT( !overlap( coords, CartVect( 3, -3, 3 ), CartVect( 1, 1, 1 ) ) );
442  ASSERT( !overlap( coords, CartVect( 3, 3, -3 ), CartVect( 1, 1, 1 ) ) );
443  ASSERT( !overlap( coords, CartVect( -3, 3, -3 ), CartVect( 1, 1, 1 ) ) );
444  ASSERT( !overlap( coords, CartVect( -3, -3, -3 ), CartVect( 1, 1, 1 ) ) );
445  ASSERT( !overlap( coords, CartVect( 3, -3, -3 ), CartVect( 1, 1, 1 ) ) );
446 
447  // test against rectilinear hex rotated 45 degrees about z axis
448  const double r = sqrt( 2.0 ) / 2.0;
449  coords[0] = CartVect( r, 0, -0.5 );
450  coords[1] = CartVect( 0, r, -0.5 );
451  coords[2] = CartVect( -r, 0, -0.5 );
452  coords[3] = CartVect( 0, -r, -0.5 );
453  coords[4] = CartVect( r, 0, 0.5 );
454  coords[5] = CartVect( 0, r, 0.5 );
455  coords[6] = CartVect( -r, 0, 0.5 );
456  coords[7] = CartVect( 0, -r, 0.5 );
457 
458  ASSERT( overlap( coords, CartVect( 1, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
459  ASSERT( overlap( coords, CartVect( -1, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
460  ASSERT( overlap( coords, CartVect( 0, 1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
461  ASSERT( overlap( coords, CartVect( 0, -1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
462 
463  ASSERT( !overlap( coords, CartVect( 1, 0, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) );
464  ASSERT( !overlap( coords, CartVect( -1, 0, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) );
465  ASSERT( !overlap( coords, CartVect( 0, 1, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) );
466  ASSERT( !overlap( coords, CartVect( 0, -1, 2 ), CartVect( 0.5, 0.5, 0.5 ) ) );
467 
468  ASSERT( !overlap( coords, CartVect( 2, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
469  ASSERT( !overlap( coords, CartVect( -2, 0, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
470  ASSERT( !overlap( coords, CartVect( 0, 2, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
471  ASSERT( !overlap( coords, CartVect( 0, -2, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
472 
473  ASSERT( !overlap( coords, CartVect( 1, 1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
474  ASSERT( !overlap( coords, CartVect( -1, 1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
475  ASSERT( !overlap( coords, CartVect( -1, -1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
476  ASSERT( !overlap( coords, CartVect( 1, -1, 0 ), CartVect( 0.5, 0.5, 0.5 ) ) );
477 
478  ASSERT( overlap( coords, CartVect( 1, 1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) );
479  ASSERT( overlap( coords, CartVect( -1, 1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) );
480  ASSERT( overlap( coords, CartVect( -1, -1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) );
481  ASSERT( overlap( coords, CartVect( 1, -1, 0 ), CartVect( 0.75, 0.75, 0.5 ) ) );
482 }

References ASSERT.

Referenced by test_box_hex_overlap(), and test_box_linear_elem_overlap_hex().

◆ general_box_tet_overlap_test()

void general_box_tet_overlap_test ( const ElemOverlapTest overlap)

Definition at line 484 of file GeomUtilTests.cpp.

485 {
486  CartVect coords[4];
487 
488  // Octant I
489  coords[0] = CartVect( 0, 0, 0 );
490  coords[1] = CartVect( 1, 0, 0 );
491  coords[2] = CartVect( 0, 1, 0 );
492  coords[3] = CartVect( 0, 0, 1 );
493  // tet entirely within box
494  ASSERT( overlap( coords, CartVect( -1, -1, -1 ), CartVect( 3, 3, 3 ) ) );
495  // box entirely within tet
496  ASSERT( overlap( coords, CartVect( 0.2, 0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
497  // box corner penetrates tet face
498  ASSERT( overlap( coords, CartVect( 0.5, 0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
499  // box corner does not penetrate face
500  ASSERT( !overlap( coords, CartVect( 0.5, 0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
501 
502  // Octant II
503  coords[0] = CartVect( 0, 1, 0 );
504  coords[1] = CartVect( -1, 0, 0 );
505  coords[2] = CartVect( 0, 0, 0 );
506  coords[3] = CartVect( 0, 0, 1 );
507  // tet entirely within box
508  ASSERT( overlap( coords, CartVect( 1, -1, -1 ), CartVect( 3, 3, 3 ) ) );
509  // box entirely within tet
510  ASSERT( overlap( coords, CartVect( -0.2, 0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
511  // box corner penetrates tet face
512  ASSERT( overlap( coords, CartVect( -0.5, 0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
513  // box corner does not penetrate face
514  ASSERT( !overlap( coords, CartVect( -0.5, 0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
515 
516  // Octant III
517  coords[0] = CartVect( 0, -1, 0 );
518  coords[1] = CartVect( 0, 0, 0 );
519  coords[2] = CartVect( -1, 0, 0 );
520  coords[3] = CartVect( 0, 0, 1 );
521  // tet entirely within box
522  ASSERT( overlap( coords, CartVect( 1, 1, -1 ), CartVect( 3, 3, 3 ) ) );
523  // box entirely within tet
524  ASSERT( overlap( coords, CartVect( -0.2, -0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
525  // box corner penetrates tet face
526  ASSERT( overlap( coords, CartVect( -0.5, -0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
527  // box corner does not penetrate face
528  ASSERT( !overlap( coords, CartVect( -0.5, -0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
529 
530  // Octant IV
531  coords[0] = CartVect( 1, 0, 0 );
532  coords[1] = CartVect( 0, -1, 0 );
533  coords[2] = CartVect( 0, 0, 1 );
534  coords[3] = CartVect( 0, 0, 0 );
535  // tet entirely within box
536  ASSERT( overlap( coords, CartVect( -1, 1, -1 ), CartVect( 3, 3, 3 ) ) );
537  // box entirely within tet
538  ASSERT( overlap( coords, CartVect( 0.2, -0.2, 0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
539  // box corner penetrates tet face
540  ASSERT( overlap( coords, CartVect( 0.5, -0.5, 0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
541  // box corner does not penetrate face
542  ASSERT( !overlap( coords, CartVect( 0.5, -0.5, 0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
543 
544  // Octant V
545  coords[0] = CartVect( 0, 0, 0 );
546  coords[1] = CartVect( 0, 1, 0 );
547  coords[2] = CartVect( 1, 0, 0 );
548  coords[3] = CartVect( 0, 0, -1 );
549  // tet entirely within box
550  ASSERT( overlap( coords, CartVect( -1, -1, 1 ), CartVect( 3, 3, 3 ) ) );
551  // box entirely within tet
552  ASSERT( overlap( coords, CartVect( 0.2, 0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
553  // box corner penetrates tet face
554  ASSERT( overlap( coords, CartVect( 0.5, 0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
555  // box corner does not penetrate face
556  ASSERT( !overlap( coords, CartVect( 0.5, 0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
557 
558  // Octant VI
559  coords[0] = CartVect( -1, 0, 0 );
560  coords[1] = CartVect( 0, 1, 0 );
561  coords[2] = CartVect( 0, 0, 0 );
562  coords[3] = CartVect( 0, 0, -1 );
563  // tet entirely within box
564  ASSERT( overlap( coords, CartVect( 1, -1, 1 ), CartVect( 3, 3, 3 ) ) );
565  // box entirely within tet
566  ASSERT( overlap( coords, CartVect( -0.2, 0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
567  // box corner penetrates tet face
568  ASSERT( overlap( coords, CartVect( -0.5, 0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
569  // box corner does not penetrate face
570  ASSERT( !overlap( coords, CartVect( -0.5, 0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
571 
572  // Octant VII
573  coords[0] = CartVect( 0, 0, 0 );
574  coords[1] = CartVect( 0, -1, 0 );
575  coords[2] = CartVect( -1, 0, 0 );
576  coords[3] = CartVect( 0, 0, -1 );
577  // tet entirely within box
578  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 3, 3, 3 ) ) );
579  // box entirely within tet
580  ASSERT( overlap( coords, CartVect( -0.2, -0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
581  // box corner penetrates tet face
582  ASSERT( overlap( coords, CartVect( -0.5, -0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
583  // box corner does not penetrate face
584  ASSERT( !overlap( coords, CartVect( -0.5, -0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
585 
586  // Octant VIII
587  coords[0] = CartVect( 0, -1, 0 );
588  coords[1] = CartVect( 1, 0, 0 );
589  coords[2] = CartVect( 0, 0, -1 );
590  coords[3] = CartVect( 0, 0, 0 );
591  // tet entirely within box
592  ASSERT( overlap( coords, CartVect( -1, 1, 1 ), CartVect( 3, 3, 3 ) ) );
593  // box entirely within tet
594  ASSERT( overlap( coords, CartVect( 0.2, -0.2, -0.2 ), CartVect( 0.1, 0.1, 0.1 ) ) );
595  // box corner penetrates tet face
596  ASSERT( overlap( coords, CartVect( 0.5, -0.5, -0.5 ), CartVect( 0.2, 0.2, 0.2 ) ) );
597  // box corner does not penetrate face
598  ASSERT( !overlap( coords, CartVect( 0.5, -0.5, -0.5 ), CartVect( 0.15, 0.15, 0.15 ) ) );
599 
600  // Box edge -x,-z
601  coords[0] = CartVect( 0, 0, 0 );
602  coords[1] = CartVect( 2, -1, 0 );
603  coords[2] = CartVect( 2, 1, 0 );
604  coords[3] = CartVect( 0, 0, 2 );
605  // box edge passes through tet
606  ASSERT( overlap( coords, CartVect( 1.5, 0.0, 1.5 ), CartVect( 1, 1, 1 ) ) );
607  // box edge does not pass through tet
608  ASSERT( !overlap( coords, CartVect( 2.5, 0.0, 2.5 ), CartVect( 1, 1, 1 ) ) );
609 
610  // Box edge -y,-z
611  coords[0] = CartVect( 1, 2, 0 );
612  coords[1] = CartVect( -1, 2, 0 );
613  coords[2] = CartVect( 0, 0, 0 );
614  coords[3] = CartVect( 0, 0, 2 );
615  // box edge passes through tet
616  ASSERT( overlap( coords, CartVect( 0.0, 1.5, 1.5 ), CartVect( 1, 1, 1 ) ) );
617  // box edge does not pass through tet
618  ASSERT( !overlap( coords, CartVect( 0.0, 2.5, 2.5 ), CartVect( 1, 1, 1 ) ) );
619 
620  // Box edge +x,-z
621  coords[0] = CartVect( -2, -1, 0 );
622  coords[1] = CartVect( -2, 1, 0 );
623  coords[2] = CartVect( 0, 0, 2 );
624  coords[3] = CartVect( 0, 0, 0 );
625  // box edge passes through tet
626  ASSERT( overlap( coords, CartVect( -1.5, 0.0, 1.5 ), CartVect( 1, 1, 1 ) ) );
627  // box edge does not pass through tet
628  ASSERT( !overlap( coords, CartVect( -2.5, 0.0, 2.5 ), CartVect( 1, 1, 1 ) ) );
629 
630  // Box edge +y,-z
631  coords[0] = CartVect( 2, -1, 0 );
632  coords[1] = CartVect( 0, 0, 0 );
633  coords[2] = CartVect( -2, -1, 0 );
634  coords[3] = CartVect( 0, 0, 2 );
635  // box edge passes through tet
636  ASSERT( overlap( coords, CartVect( 0.0, -1.5, 1.5 ), CartVect( 1, 1, 1 ) ) );
637  // box edge does not pass through tet
638  ASSERT( !overlap( coords, CartVect( 0.0, -2.5, 2.5 ), CartVect( 1, 1, 1 ) ) );
639 
640  // Box edge -x,+z
641  coords[0] = CartVect( 2, -1, 0 );
642  coords[1] = CartVect( 0, 0, 0 );
643  coords[2] = CartVect( 2, 1, 0 );
644  coords[3] = CartVect( 0, 0, -2 );
645  // box edge passes through tet
646  ASSERT( overlap( coords, CartVect( 1.5, 0.0, -1.5 ), CartVect( 1, 1, 1 ) ) );
647  // box edge does not pass through tet
648  ASSERT( !overlap( coords, CartVect( 2.5, 0.0, -2.5 ), CartVect( 1, 1, 1 ) ) );
649 
650  // Box edge -y,+z
651  coords[0] = CartVect( -1, 2, 0 );
652  coords[1] = CartVect( 1, 2, 0 );
653  coords[2] = CartVect( 0, 0, 0 );
654  coords[3] = CartVect( 0, 0, -2 );
655  // box edge passes through tet
656  ASSERT( overlap( coords, CartVect( 0.0, 1.5, -1.5 ), CartVect( 1, 1, 1 ) ) );
657  // box edge does not pass through tet
658  ASSERT( !overlap( coords, CartVect( 0.0, 2.5, -2.5 ), CartVect( 1, 1, 1 ) ) );
659 
660  // Box edge +x,+z
661  coords[0] = CartVect( -2, 1, 0 );
662  coords[1] = CartVect( -2, -1, 0 );
663  coords[2] = CartVect( 0, 0, -2 );
664  coords[3] = CartVect( 0, 0, 0 );
665  // box edge passes through tet
666  ASSERT( overlap( coords, CartVect( -1.5, 0.0, -1.5 ), CartVect( 1, 1, 1 ) ) );
667  // box edge does not pass through tet
668  ASSERT( !overlap( coords, CartVect( -2.5, 0.0, -2.5 ), CartVect( 1, 1, 1 ) ) );
669 
670  // Box edge +y,+z
671  coords[0] = CartVect( 0, 0, 0 );
672  coords[1] = CartVect( 2, -1, 0 );
673  coords[2] = CartVect( -2, -1, 0 );
674  coords[3] = CartVect( 0, 0, -2 );
675  // box edge passes through tet
676  ASSERT( overlap( coords, CartVect( 0.0, -1.5, -1.5 ), CartVect( 1, 1, 1 ) ) );
677  // box edge does not pass through tet
678  ASSERT( !overlap( coords, CartVect( 0.0, -2.5, -2.5 ), CartVect( 1, 1, 1 ) ) );
679 
680  // Box edge -x,-y
681  coords[0] = CartVect( 0, 0, 0 );
682  coords[1] = CartVect( 0, 2, -1 );
683  coords[2] = CartVect( 0, 2, 1 );
684  coords[3] = CartVect( 2, 0, 0 );
685  // box edge passes through tet
686  ASSERT( overlap( coords, CartVect( 1.5, 1.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
687  // box edge does not pass through tet
688  ASSERT( !overlap( coords, CartVect( 2.5, 2.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
689 
690  // Box edge +x,-y
691  coords[0] = CartVect( 0, 2, -1 );
692  coords[1] = CartVect( 0, 0, 0 );
693  coords[2] = CartVect( 0, 2, 1 );
694  coords[3] = CartVect( -2, 0, 0 );
695  // box edge passes through tet
696  ASSERT( overlap( coords, CartVect( -1.5, 1.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
697  // box edge does not pass through tet
698  ASSERT( !overlap( coords, CartVect( -2.5, 2.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
699 
700  // Box edge -x,+y
701  coords[0] = CartVect( 0, -2, 1 );
702  coords[1] = CartVect( 0, -2, -1 );
703  coords[2] = CartVect( 0, 0, 0 );
704  coords[3] = CartVect( 2, 0, 0 );
705  // box edge passes through tet
706  ASSERT( overlap( coords, CartVect( 1.5, -1.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
707  // box edge does not pass through tet
708  ASSERT( !overlap( coords, CartVect( 2.5, -2.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
709 
710  // Box edge +x,+y
711  coords[0] = CartVect( 0, -2, -1 );
712  coords[1] = CartVect( -2, 0, 0 );
713  coords[2] = CartVect( 0, -2, 1 );
714  coords[3] = CartVect( 0, 0, 0 );
715  // box edge passes through tet
716  ASSERT( overlap( coords, CartVect( -1.5, -1.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
717  // box edge does not pass through tet
718  ASSERT( !overlap( coords, CartVect( -2.5, -2.5, 0.0 ), CartVect( 1, 1, 1 ) ) );
719 
720  // Test tet edge through box
721  coords[0] = CartVect( -0.13369421660900116, -2.9871494770050049, 0.0526076555252075 );
722  coords[1] = CartVect( -0.00350524857640266, -3.3236153125762939, 0.2924639880657196 );
723  coords[2] = CartVect( 0.16473215818405151, -2.9966945648193359, -0.1936169415712357 );
724  coords[3] = CartVect( 0.26740345358848572, -2.8492588996887207, 0.1519143134355545 );
725  ASSERT( overlap( coords, CartVect( -2.5, -2.8, -2.5 ), CartVect( 2.5, 0.31, 2.5 ) ) );
726 }

References ASSERT.

Referenced by test_box_linear_elem_overlap_tet(), and test_box_tet_overlap().

◆ general_box_tri_overlap_test()

void general_box_tri_overlap_test ( const ElemOverlapTest overlap)

Definition at line 132 of file GeomUtilTests.cpp.

133 {
134  CartVect coords[3];
135  CartVect center, dims;
136 
137  // test box projection within triangle, z-plane
138  coords[0] = CartVect( 0, 0, 0 );
139  coords[1] = CartVect( 0, 4, 0 );
140  coords[2] = CartVect( -4, 0, 0 );
141  center = CartVect( -2, 1, 0 );
142  dims = CartVect( 1, 0.5, 3 );
143  ASSERT( overlap( coords, center, dims ) );
144  // move box below plane of triangle
145  center[2] = -4;
146  ASSERT( !overlap( coords, center, dims ) );
147  // move box above plane of triangle
148  center[2] = 4;
149  ASSERT( !overlap( coords, center, dims ) );
150 
151  // test box projection within triangle, x-plane
152  coords[0] = CartVect( 3, 3, 0 );
153  coords[1] = CartVect( 3, 3, 1 );
154  coords[2] = CartVect( 3, 0, 0 );
155  center = CartVect( 3, 2.5, .25 );
156  dims = CartVect( 0.001, 0.4, .2 );
157  ASSERT( overlap( coords, center, dims ) );
158  // move box below plane of triangle
159  center[0] = 2;
160  ASSERT( !overlap( coords, center, dims ) );
161  // move box above plane of triangle
162  center[0] = 4;
163  ASSERT( !overlap( coords, center, dims ) );
164 
165  // test tri slices corner at +x,+y,+z
166  coords[0] = CartVect( 3, 1, 1 );
167  coords[1] = CartVect( 1, 3, 1 );
168  coords[2] = CartVect( 1, 1, 3 );
169  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
170  // test with tri above the corner
171  ASSERT( !overlap( coords, CartVect( 0, 0, 0 ), CartVect( 1, 1, 1 ) ) );
172  // test tri slices corner at -x,-y,-z
173  coords[0] = CartVect( -1, 1, 1 );
174  coords[1] = CartVect( 1, -1, 1 );
175  coords[2] = CartVect( 1, 1, -1 );
176  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
177  // test with tri below the corner
178  ASSERT( !overlap( coords, CartVect( 2, 2, 2 ), CartVect( 1, 1, 1 ) ) );
179 
180  // test tri slices corner at -x,+y,+z
181  coords[0] = CartVect( 0.5, 0.0, 2.5 );
182  coords[1] = CartVect( 0.5, 2.5, 0.0 );
183  coords[2] = CartVect( -0.5, 0.0, 0.0 );
184  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
185  // test with tri above the corner
186  ASSERT( !overlap( coords, CartVect( 2, 1, 1 ), CartVect( 1, 1, 1 ) ) );
187 
188  // test tri slices corner at +x,-y,-z
189  coords[0] = CartVect( 0.5, 0.0, -1.5 );
190  coords[1] = CartVect( 0.5, -1.5, 0.0 );
191  coords[2] = CartVect( 1.5, 0.0, 0.0 );
192  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
193  // test with tri above the corner
194  ASSERT( !overlap( coords, CartVect( 0, 1, 1 ), CartVect( 1, 1, 1 ) ) );
195 
196  // test tri slices corner at +x,-y,+z
197  coords[0] = CartVect( 1.0, 1.0, 2.5 );
198  coords[1] = CartVect( 2.5, 1.0, 1.0 );
199  coords[2] = CartVect( 1.0, -0.5, 1.0 );
200  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
201  // test with tri above the corner
202  ASSERT( !overlap( coords, CartVect( -1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
203 
204  // test tri slices corner at -x,+y,-z
205  coords[0] = CartVect( 1.0, 1.0, -0.5 );
206  coords[1] = CartVect( -0.5, 1.0, 1.0 );
207  coords[2] = CartVect( 1.0, 2.5, 1.0 );
208  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
209  // test with tri above the corner
210  ASSERT( !overlap( coords, CartVect( 3, 1, 1 ), CartVect( 1, 1, 1 ) ) );
211 
212  // test tri slices corner at +x,+y,-z
213  coords[0] = CartVect( -0.1, 1.0, 1.0 );
214  coords[1] = CartVect( 1.0, -0.1, 1.0 );
215  coords[2] = CartVect( 1.0, 1.0, -0.1 );
216  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
217  // test with tri outside box
218  ASSERT( !overlap( coords, CartVect( 1, 1, 3 ), CartVect( 1, 1, 1 ) ) );
219 
220  // test tri slices corner at -x,-y,+z
221  coords[0] = CartVect( 2.1, 1.0, 1.0 );
222  coords[1] = CartVect( 1.0, 2.1, 1.0 );
223  coords[2] = CartVect( 1.0, 1.0, 2.1 );
224  ASSERT( box_tri_overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
225  // test with tri outside box
226  ASSERT( !overlap( coords, CartVect( 1, 1, -1 ), CartVect( 1, 1, 1 ) ) );
227 
228  // box edge parallel to x at +y,+z passes through triangle
229  coords[0] = CartVect( 1.0, 1.0, 3.0 );
230  coords[1] = CartVect( 1.0, 3.0, 3.0 );
231  coords[2] = CartVect( 1.0, 3.0, 1.0 );
232  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
233  // test with tri outside box
234  ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) );
235 
236  // box edge parallel to x at +y,-z passes through triangle
237  coords[0] = CartVect( 1.0, 3.0, 1.0 );
238  coords[1] = CartVect( 1.0, 3.0, -1.0 );
239  coords[2] = CartVect( 1.0, 1.0, -1.0 );
240  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
241  // test with tri outside box
242  ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) );
243 
244  // box edge parallel to x at -y,-z passes through triangle
245  coords[0] = CartVect( 1.0, -1.0, 1.0 );
246  coords[1] = CartVect( 1.0, -1.0, -1.0 );
247  coords[2] = CartVect( 1.0, 1.0, -1.0 );
248  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
249  // test with tri outside box
250  ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) );
251 
252  // box edge parallel to x at -y,+z passes through triangle
253  coords[0] = CartVect( 1.0, -1.0, 1.0 );
254  coords[1] = CartVect( 1.0, -1.0, 3.0 );
255  coords[2] = CartVect( 1.0, 1.0, 3.0 );
256  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
257  // test with tri outside box
258  ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) );
259 
260  // box edge parallel to y at +x,+z passes through triangle
261  coords[0] = CartVect( 1.0, 1.0, 3.0 );
262  coords[1] = CartVect( 3.0, 1.0, 3.0 );
263  coords[2] = CartVect( 3.0, 1.0, 1.0 );
264  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
265  // test with tri outside box
266  ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) );
267 
268  // box edge parallel to y at -x,+z passes through triangle
269  coords[0] = CartVect( 1.0, 1.0, 3.0 );
270  coords[1] = CartVect( -1.0, 1.0, 3.0 );
271  coords[2] = CartVect( -1.0, 1.0, 1.0 );
272  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
273  // test with tri outside box
274  ASSERT( !overlap( coords, CartVect( 1, 1, 0.3 ), CartVect( 1, 1, 1 ) ) );
275 
276  // box edge parallel to y at +x,-z passes through triangle
277  coords[0] = CartVect( 1.0, 1.0, -1.0 );
278  coords[1] = CartVect( 3.0, 1.0, -1.0 );
279  coords[2] = CartVect( 3.0, 1.0, 1.0 );
280  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
281  // test with tri outside box
282  ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) );
283 
284  // box edge parallel to y at -x,-z passes through triangle
285  coords[0] = CartVect( 1.0, 1.0, -1.0 );
286  coords[1] = CartVect( -1.0, 1.0, -1.0 );
287  coords[2] = CartVect( -1.0, 1.0, 1.0 );
288  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
289  // test with tri outside box
290  ASSERT( !overlap( coords, CartVect( 1, 1, 1.7 ), CartVect( 1, 1, 1 ) ) );
291 
292  // box edge parallel to z at +x,+y passes through triangle
293  coords[0] = CartVect( 1.0, 3.0, 1.0 );
294  coords[1] = CartVect( 3.0, 3.0, 1.0 );
295  coords[2] = CartVect( 3.0, 1.0, 1.0 );
296  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
297  // test with tri outside box
298  ASSERT( !overlap( coords, CartVect( 0.3, 1, 1 ), CartVect( 1, 1, 1 ) ) );
299 
300  // box edge parallel to z at +x,-y passes through triangle
301  coords[0] = CartVect( 1.0, -1.0, 1.0 );
302  coords[1] = CartVect( 3.0, -1.0, 1.0 );
303  coords[2] = CartVect( 3.0, 1.0, 1.0 );
304  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
305  // test with tri outside box
306  ASSERT( !overlap( coords, CartVect( 0.3, 1, 1 ), CartVect( 1, 1, 1 ) ) );
307 
308  // box edge parallel to z at -x,+y passes through triangle
309  coords[0] = CartVect( 1.0, 3.0, 1.0 );
310  coords[1] = CartVect( -1.0, 3.0, 1.0 );
311  coords[2] = CartVect( -1.0, 1.0, 1.0 );
312  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
313  // test with tri outside box
314  ASSERT( !overlap( coords, CartVect( 1.7, 1, 1 ), CartVect( 1, 1, 1 ) ) );
315 
316  // box edge parallel to z at -x,-y passes through triangle
317  coords[0] = CartVect( 1.0, -1.0, 1.0 );
318  coords[1] = CartVect( -1.0, -1.0, 1.0 );
319  coords[2] = CartVect( -1.0, 1.0, 1.0 );
320  ASSERT( overlap( coords, CartVect( 1, 1, 1 ), CartVect( 1, 1, 1 ) ) );
321  // test with tri outside box
322  ASSERT( !overlap( coords, CartVect( 1.7, 1, 1 ), CartVect( 1, 1, 1 ) ) );
323 
324  // triangle penetrates +x face
325  coords[0] = CartVect( 2.0, 2.0, 2.0 );
326  coords[1] = CartVect( 5.0, 3.0, 2.0 );
327  coords[2] = CartVect( 5.0, 1.0, 2.0 );
328  ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) );
329  // test with tri outside box
330  ASSERT( !overlap( coords, CartVect( -1, 2, 2 ), CartVect( 2, 2, 2 ) ) );
331 
332  // triangle penetrates -x face
333  coords[0] = CartVect( 2.0, 2.0, 2.0 );
334  coords[1] = CartVect( -1.0, 3.0, 2.0 );
335  coords[2] = CartVect( -1.0, 1.0, 2.0 );
336  ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) );
337  // test with tri outside box
338  ASSERT( !overlap( coords, CartVect( 5, 2, 2 ), CartVect( 2, 2, 2 ) ) );
339 
340  // triangle penetrates +y face
341  coords[0] = CartVect( 2.0, 2.0, 2.0 );
342  coords[1] = CartVect( 3.0, 5.0, 2.0 );
343  coords[2] = CartVect( 1.0, 5.0, 2.0 );
344  ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) );
345  // test with tri outside box
346  ASSERT( !overlap( coords, CartVect( 2, -1, 2 ), CartVect( 2, 2, 2 ) ) );
347 
348  // triangle penetrates -y face
349  coords[0] = CartVect( 2.0, 2.0, 2.0 );
350  coords[1] = CartVect( 3.0, -1.0, 2.0 );
351  coords[2] = CartVect( 1.0, -1.0, 2.0 );
352  ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) );
353  // test with tri outside box
354  ASSERT( !overlap( coords, CartVect( 2, 5, 2 ), CartVect( 2, 2, 2 ) ) );
355 
356  // triangle penetrates +z face
357  coords[0] = CartVect( 2.0, 2.0, 2.0 );
358  coords[1] = CartVect( 2.0, 3.0, 5.0 );
359  coords[2] = CartVect( 2.0, 1.0, 5.0 );
360  ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) );
361  // test with tri outside box
362  ASSERT( !overlap( coords, CartVect( 2, 2, -1 ), CartVect( 2, 2, 2 ) ) );
363 
364  // triangle penetrates -z face
365  coords[0] = CartVect( 2.0, 2.0, 2.0 );
366  coords[1] = CartVect( 2.0, 3.0, -1.0 );
367  coords[2] = CartVect( 2.0, 1.0, -1.0 );
368  ASSERT( overlap( coords, CartVect( 2, 2, 2 ), CartVect( 2, 2, 2 ) ) );
369  // test with tri outside box
370  ASSERT( !overlap( coords, CartVect( 2, 2, 5 ), CartVect( 2, 2, 2 ) ) );
371 }

References ASSERT, moab::GeomUtil::box_tri_overlap(), and center().

Referenced by test_box_linear_elem_overlap_tri(), and test_box_tri_overlap().

◆ main()

◆ test_box_hex_overlap()

void test_box_hex_overlap ( )

◆ test_box_linear_elem_overlap_hex()

void test_box_linear_elem_overlap_hex ( )

Definition at line 743 of file GeomUtilTests.cpp.

References general_box_hex_overlap_test(), and MBHEX.

Referenced by main().

◆ test_box_linear_elem_overlap_tet()

void test_box_linear_elem_overlap_tet ( )

Definition at line 753 of file GeomUtilTests.cpp.

References general_box_tet_overlap_test(), and MBTET.

Referenced by main().

◆ test_box_linear_elem_overlap_tri()

void test_box_linear_elem_overlap_tri ( )

Definition at line 733 of file GeomUtilTests.cpp.

References general_box_tri_overlap_test(), and MBTRI.

Referenced by main().

◆ test_box_plane_axis()

void test_box_plane_axis ( int  axis,
double  ns,
const CartVect min,
const CartVect max 
)

Definition at line 50 of file GeomUtilTests.cpp.

51 {
52  CartVect norm( 0.0 );
53  norm[axis] = ns;
54  test_box_plane_norm( norm, min, max );
55 }

References test_box_plane_norm().

Referenced by test_box_plane_overlap().

◆ test_box_plane_corner()

void test_box_plane_corner ( int  xdir,
int  ydir,
int  zdir,
CartVect  min,
CartVect  max 
)

Definition at line 70 of file GeomUtilTests.cpp.

71 {
72  CartVect norm( max - min );
73  norm[0] *= xdir;
74  norm[1] *= ydir;
75  norm[2] *= zdir;
76  test_box_plane_norm( norm, min, max );
77 }

References test_box_plane_norm().

Referenced by test_box_plane_overlap().

◆ test_box_plane_edge()

void test_box_plane_edge ( int  axis1,
int  axis2,
bool  flip_axis2,
CartVect  min,
CartVect  max 
)

Definition at line 57 of file GeomUtilTests.cpp.

58 {
59  CartVect norm( 0.0 );
60  norm[axis1] = max[axis1] - min[axis1];
61  if( flip_axis2 )
62  norm[axis2] = min[axis2] - max[axis2];
63  else
64  norm[axis2] = max[axis2] - min[axis2];
65  norm.normalize();
66 
67  test_box_plane_norm( norm, min, max );
68 }

References moab::CartVect::normalize(), and test_box_plane_norm().

Referenced by test_box_plane_overlap().

◆ test_box_plane_norm()

void test_box_plane_norm ( CartVect  norm,
CartVect  min,
CartVect  max 
)

Definition at line 27 of file GeomUtilTests.cpp.

28 {
29  CartVect c_lower = min;
30  CartVect c_upper = max;
31  for( int i = 0; i < 3; ++i )
32  if( norm[i] < 0.0 ) std::swap( c_lower[i], c_upper[i] );
33 
34  CartVect p_below = c_lower - norm;
35  CartVect p_lower = c_lower + norm;
36  CartVect p_upper = c_upper - norm;
37  CartVect p_above = c_upper + norm;
38 
39  double below = -( p_below % norm );
40  double lower = -( p_lower % norm );
41  double upper = -( p_upper % norm );
42  double above = -( p_above % norm );
43 
44  ASSERT( !box_plane_overlap( norm, below, min, max ) );
45  ASSERT( box_plane_overlap( norm, lower, min, max ) );
46  ASSERT( box_plane_overlap( norm, upper, min, max ) );
47  ASSERT( !box_plane_overlap( norm, above, min, max ) );
48 }

References ASSERT, moab::GeomUtil::box_plane_overlap(), and swap().

Referenced by test_box_plane_axis(), test_box_plane_corner(), and test_box_plane_edge().

◆ test_box_plane_overlap()

void test_box_plane_overlap ( )

Definition at line 79 of file GeomUtilTests.cpp.

80 {
81  const CartVect min( -1, -2, -3 );
82  const CartVect max( 6, 4, 2 );
83 
84  // test with planes orthogonal to Z axis
85  test_box_plane_axis( 2, 2.0, min, max );
86  // test with planes orthogonal to X axis
87  test_box_plane_axis( 1, -2.0, min, max );
88  // test with planes orthogonal to Y axis
89  test_box_plane_axis( 1, 1.0, min, max );
90 
91  // test with plane orthogonal to face diagonals
92  test_box_plane_edge( 0, 1, true, min, max );
93  test_box_plane_edge( 0, 1, false, min, max );
94  test_box_plane_edge( 0, 2, true, min, max );
95  test_box_plane_edge( 0, 2, false, min, max );
96  test_box_plane_edge( 2, 1, true, min, max );
97  test_box_plane_edge( 2, 1, false, min, max );
98 
99  // test with plane orthogonal to box diagonals
100  test_box_plane_corner( 1, 1, 1, min, max );
101  test_box_plane_corner( 1, 1, -1, min, max );
102  test_box_plane_corner( 1, -1, -1, min, max );
103  test_box_plane_corner( 1, -1, 1, min, max );
104 }

References test_box_plane_axis(), test_box_plane_corner(), and test_box_plane_edge().

Referenced by main().

◆ test_box_tet_overlap()

void test_box_tet_overlap ( )

◆ test_box_tri_overlap()

void test_box_tri_overlap ( )

◆ test_closest_location_on_box()

void test_closest_location_on_box ( )

Definition at line 1198 of file GeomUtilTests.cpp.

1199 {
1200  const CartVect min( 0, 0, 0 ), max( 1, 2, 3 );
1201  CartVect pt;
1202 
1203  // inside
1204  closest_location_on_box( min, max, CartVect( 0.5, 0.5, 0.5 ), pt );
1205  ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.5, 0.5 ), pt );
1206 
1207  // closest to min x side
1208  closest_location_on_box( min, max, CartVect( -1.0, 0.5, 0.5 ), pt );
1209  ASSERT_VECTORS_EQUAL( CartVect( 0.0, 0.5, 0.5 ), pt );
1210 
1211  // closest to max x side
1212  closest_location_on_box( min, max, CartVect( 2.0, 0.5, 0.5 ), pt );
1213  ASSERT_VECTORS_EQUAL( CartVect( 1.0, 0.5, 0.5 ), pt );
1214 
1215  // closest to min y side
1216  closest_location_on_box( min, max, CartVect( 0.5, -1.0, 0.5 ), pt );
1217  ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.0, 0.5 ), pt );
1218 
1219  // closest to max y side
1220  closest_location_on_box( min, max, CartVect( 0.5, 2.5, 0.5 ), pt );
1221  ASSERT_VECTORS_EQUAL( CartVect( 0.5, 2.0, 0.5 ), pt );
1222 
1223  // closest to min z side
1224  closest_location_on_box( min, max, CartVect( 0.5, 0.5, -0.1 ), pt );
1225  ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.5, 0.0 ), pt );
1226 
1227  // closest to max z side
1228  closest_location_on_box( min, max, CartVect( 0.5, 0.5, 100.0 ), pt );
1229  ASSERT_VECTORS_EQUAL( CartVect( 0.5, 0.5, 3.0 ), pt );
1230 
1231  // closest to min corner
1232  closest_location_on_box( min, max, CartVect( -1, -1, -1 ), pt );
1233  ASSERT_VECTORS_EQUAL( min, pt );
1234 
1235  // closest to max corner
1236  closest_location_on_box( min, max, CartVect( 2, 3, 4 ), pt );
1237  ASSERT_VECTORS_EQUAL( max, pt );
1238 }

References ASSERT_VECTORS_EQUAL, and moab::GeomUtil::closest_location_on_box().

Referenced by main().

◆ test_closest_location_on_polygon()

void test_closest_location_on_polygon ( )

Definition at line 934 of file GeomUtilTests.cpp.

935 {
936  CartVect result, input;
937 
938  // define a unit square in xy plane
939  const CartVect quad[4] = { CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 0.0 ),
940  CartVect( 0.0, 1.0, 0.0 ) };
941 
942  // test input in center of square
943  closest_location_on_polygon( CartVect( 0.5, 0.5, 0.0 ), quad, 4, result );
944  ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) );
945  // test above center of square
946  closest_location_on_polygon( CartVect( 0.5, 0.5, 1.0 ), quad, 4, result );
947  ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) );
948  // test below center of square
949  closest_location_on_polygon( CartVect( 0.5, 0.5, -1.0 ), quad, 4, result );
950  ASSERT_VECTORS_EQUAL( result, CartVect( 0.5, 0.5, 0.0 ) );
951 
952  // test points within square, but not at center
953  input = CartVect( 0.25, 0.25, 0 );
954  closest_location_on_polygon( input, quad, 4, result );
955  ASSERT_VECTORS_EQUAL( result, input );
956  input = CartVect( 0.75, 0.25, 0 );
957  closest_location_on_polygon( input, quad, 4, result );
958  ASSERT_VECTORS_EQUAL( result, input );
959  input = CartVect( 0.75, 0.75, 0 );
960  closest_location_on_polygon( input, quad, 4, result );
961  ASSERT_VECTORS_EQUAL( result, input );
962  input = CartVect( 0.25, 0.75, 0 );
963  closest_location_on_polygon( input, quad, 4, result );
964  ASSERT_VECTORS_EQUAL( result, input );
965 
966  // test at each corner
967  closest_location_on_polygon( quad[0], quad, 4, result );
968  ASSERT_VECTORS_EQUAL( result, quad[0] );
969  closest_location_on_polygon( quad[1], quad, 4, result );
970  ASSERT_VECTORS_EQUAL( result, quad[1] );
971  closest_location_on_polygon( quad[2], quad, 4, result );
972  ASSERT_VECTORS_EQUAL( result, quad[2] );
973  closest_location_on_polygon( quad[3], quad, 4, result );
974  ASSERT_VECTORS_EQUAL( result, quad[3] );
975 
976  // test at point on each edge
977  input = 0.5 * quad[0] + 0.5 * quad[1];
978  closest_location_on_polygon( input, quad, 4, result );
979  ASSERT_VECTORS_EQUAL( result, input );
980  input = 0.2 * quad[1] + 0.8 * quad[2];
981  closest_location_on_polygon( input, quad, 4, result );
982  ASSERT_VECTORS_EQUAL( result, input );
983  input = 0.7 * quad[2] + 0.3 * quad[3];
984  closest_location_on_polygon( input, quad, 4, result );
985  ASSERT_VECTORS_EQUAL( result, input );
986  input = 0.6 * quad[3] + 0.4 * quad[0];
987  closest_location_on_polygon( input, quad, 4, result );
988  ASSERT_VECTORS_EQUAL( result, input );
989 
990  // test at point outside and closest to each corner
991  closest_location_on_polygon( CartVect( -1.0, -1.0, 0.0 ), quad, 4, result );
992  ASSERT_VECTORS_EQUAL( result, quad[0] );
993  closest_location_on_polygon( CartVect( 2.0, -1.0, 0.0 ), quad, 4, result );
994  ASSERT_VECTORS_EQUAL( result, quad[1] );
995  closest_location_on_polygon( CartVect( 2.0, 2.0, 0.0 ), quad, 4, result );
996  ASSERT_VECTORS_EQUAL( result, quad[2] );
997  closest_location_on_polygon( CartVect( -1.0, 2.0, 0.0 ), quad, 4, result );
998  ASSERT_VECTORS_EQUAL( result, quad[3] );
999 
1000  // test at point outside and closest to an edge
1001  CartVect x( 1.0, 0.0, 0.0 ), y( 0.0, 1.0, 0.0 );
1002  input = 0.5 * quad[0] + 0.5 * quad[1];
1003  closest_location_on_polygon( input - y, quad, 4, result );
1004  ASSERT_VECTORS_EQUAL( result, input );
1005  input = 0.2 * quad[1] + 0.8 * quad[2];
1006  closest_location_on_polygon( input + x, quad, 4, result );
1007  ASSERT_VECTORS_EQUAL( result, input );
1008  input = 0.7 * quad[2] + 0.3 * quad[3];
1009  closest_location_on_polygon( input + y, quad, 4, result );
1010  ASSERT_VECTORS_EQUAL( result, input );
1011  input = 0.6 * quad[3] + 0.4 * quad[0];
1012  closest_location_on_polygon( input - x, quad, 4, result );
1013  ASSERT_VECTORS_EQUAL( result, input );
1014 }

References ASSERT_VECTORS_EQUAL, and moab::GeomUtil::closest_location_on_polygon().

Referenced by main().

◆ test_closest_location_on_tri()

void test_closest_location_on_tri ( )

Definition at line 848 of file GeomUtilTests.cpp.

849 {
850  CartVect result, input;
851 
852  // define a triangle
853  const CartVect tri[3] = { CartVect( 1.0, 0.0, 0.0 ), CartVect( 0.0, 1.0, 0.0 ), CartVect( 0.0, 0.0, 1.0 ) };
854 
855  // try point at triangle centroid
856  input = CartVect( 1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0 );
857  closest_location_on_tri( input, tri, result );
858  ASSERT_VECTORS_EQUAL( result, input );
859 
860  // try point at each vertex
861  closest_location_on_tri( tri[0], tri, result );
862  ASSERT_VECTORS_EQUAL( result, tri[0] );
863  closest_location_on_tri( tri[1], tri, result );
864  ASSERT_VECTORS_EQUAL( result, tri[1] );
865  closest_location_on_tri( tri[2], tri, result );
866  ASSERT_VECTORS_EQUAL( result, tri[2] );
867 
868  // try point at center of each edge
869  input = 0.5 * ( tri[0] + tri[1] );
870  closest_location_on_tri( input, tri, result );
871  ASSERT_VECTORS_EQUAL( result, input );
872  input = 0.5 * ( tri[0] + tri[2] );
873  closest_location_on_tri( input, tri, result );
874  ASSERT_VECTORS_EQUAL( result, input );
875  input = 0.5 * ( tri[2] + tri[1] );
876  closest_location_on_tri( input, tri, result );
877  ASSERT_VECTORS_EQUAL( result, input );
878 
879  // try a point above the center of the triangle
880  input = CartVect( 1.0, 1.0, 1.0 );
881  closest_location_on_tri( input, tri, result );
882  ASSERT_VECTORS_EQUAL( result, CartVect( 1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0 ) );
883 
884  // try a point below the center of the triangle
885  input = CartVect( 0.0, 0.0, 0.0 );
886  closest_location_on_tri( input, tri, result );
887  ASSERT_VECTORS_EQUAL( result, CartVect( 1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0 ) );
888 
889  // try a point closest to each vertex and 'outside' of both adjacent edges.
890  input = 2 * tri[0];
891  closest_location_on_tri( input, tri, result );
892  ASSERT_VECTORS_EQUAL( result, tri[0] );
893  input = 2 * tri[1];
894  closest_location_on_tri( input, tri, result );
895  ASSERT_VECTORS_EQUAL( result, tri[1] );
896  input = 2 * tri[2];
897  closest_location_on_tri( input, tri, result );
898  ASSERT_VECTORS_EQUAL( result, tri[2] );
899 
900  // try a point outside and closest to each edge
901  input = tri[0] + tri[1];
902  closest_location_on_tri( input, tri, result );
903  ASSERT_VECTORS_EQUAL( result, 0.5 * input );
904  input = tri[2] + tri[1];
905  closest_location_on_tri( input, tri, result );
906  ASSERT_VECTORS_EQUAL( result, 0.5 * input );
907  input = tri[0] + tri[2];
908  closest_location_on_tri( input, tri, result );
909  ASSERT_VECTORS_EQUAL( result, 0.5 * input );
910 
911  // define an equilateral triangle in the xy-plane
912  const CartVect tri_xy[3] = { CartVect( 0.0, sqrt( 3.0 ) / 2.0, 0.0 ), CartVect( 0.5, 0.0, 0.0 ),
913  CartVect( -0.5, 0.0, 0.0 ) };
914 
915  // for each vertex, test point that is
916  // - outside triangle
917  // - closest to vertex
918  // - 'inside' one of the adjacent edges
919  // - 'outside' the other adjacent edge
920  closest_location_on_tri( CartVect( -0.3, 1.2, 0.0 ), tri_xy, result );
921  ASSERT_VECTORS_EQUAL( result, tri_xy[0] );
922  closest_location_on_tri( CartVect( 0.3, 1.2, 0.0 ), tri_xy, result );
923  ASSERT_VECTORS_EQUAL( result, tri_xy[0] );
924  closest_location_on_tri( CartVect( 1.0, 0.1, 0.0 ), tri_xy, result );
925  ASSERT_VECTORS_EQUAL( result, tri_xy[1] );
926  closest_location_on_tri( CartVect( 0.6, -0.5, 0.0 ), tri_xy, result );
927  ASSERT_VECTORS_EQUAL( result, tri_xy[1] );
928  closest_location_on_tri( CartVect( -0.6, -0.5, 0.0 ), tri_xy, result );
929  ASSERT_VECTORS_EQUAL( result, tri_xy[2] );
930  closest_location_on_tri( CartVect( -1.0, 0.1, 0.0 ), tri_xy, result );
931  ASSERT_VECTORS_EQUAL( result, tri_xy[2] );
932 }

References ASSERT_VECTORS_EQUAL, and moab::GeomUtil::closest_location_on_tri().

Referenced by main().

◆ test_plucker_ray_tri_intersect()

void test_plucker_ray_tri_intersect ( )

Definition at line 788 of file GeomUtilTests.cpp.

789 {
790  bool xsect;
791  double t;
792 
793  // define a triangle
794  const CartVect tri[3] = { CartVect( 1.0, 0.0, 0.0 ), CartVect( 0.0, 1.0, 0.0 ), CartVect( 0.0, 0.0, 1.0 ) };
795 
796  // try a ray through the center of the triangle
797  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t );
798  ASSERT( xsect );
799  ASSERT_DOUBLES_EQUAL( 1.0 / 3.0, t );
800 
801  // try a same ray, but move base point above triangle
802  xsect = plucker_ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( 1.0, 1.0, 1.0 ), t );
803  ASSERT( !xsect );
804 
805  // try a same ray the other direction with base point below triangle
806  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( -1.0, -1.0, -1.0 ), t );
807  ASSERT( !xsect );
808 
809  // try a ray that passes above the triangle
810  xsect = plucker_ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( -1.0, -1.0, 1.0 ), t );
811  ASSERT( !xsect );
812 
813  // try a skew ray
814  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, -0.1 ), t );
815  ASSERT( !xsect );
816 
817  // try a ray that intersects with wrong orientation
818  const int orientation = -1.0;
819  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t, NULL, NULL,
820  &orientation );
821  ASSERT( !xsect );
822 
823  // try a ray that intersects beyond the nonneg_ray_len
824  const double nonneg_ray_len = 0.25;
825  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t, &nonneg_ray_len );
826  ASSERT( !xsect );
827 
828  // try a ray that intersects behind the origin
829  const double neg_ray_len = -2.0;
830  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( -1.0, -1.0, -1.0 ), t, NULL,
831  &neg_ray_len );
832  ASSERT( xsect );
833 
834  // try a ray that intersects a node
835  intersection_type int_type;
836  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 0.0, 0.0 ), t, NULL, NULL, NULL,
837  &int_type );
838  ASSERT( xsect );
839  ASSERT( NODE0 == int_type );
840 
841  // try a ray that intersects an edge
842  xsect = plucker_ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 0.0 ), t, NULL, NULL, NULL,
843  &int_type );
844  ASSERT( xsect );
845  ASSERT( EDGE0 == int_type );
846 }

References ASSERT, ASSERT_DOUBLES_EQUAL, moab::GeomUtil::EDGE0, moab::GeomUtil::NODE0, moab::GeomUtil::plucker_ray_tri_intersect(), and t.

Referenced by main().

◆ test_ray_tri_intersect()

void test_ray_tri_intersect ( )

Definition at line 758 of file GeomUtilTests.cpp.

759 {
760  bool xsect;
761  double t;
762 
763  // define a triangle
764  const CartVect tri[3] = { CartVect( 1.0, 0.0, 0.0 ), CartVect( 0.0, 1.0, 0.0 ), CartVect( 0.0, 0.0, 1.0 ) };
765 
766  // try a ray through the center of the triangle
767  xsect = ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, 1.0 ), t );
768  ASSERT( xsect );
769  ASSERT_DOUBLES_EQUAL( 1.0 / 3.0, t );
770 
771  // try a same ray, but move base point above triangle
772  xsect = ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( 1.0, 1.0, 1.0 ), t );
773  ASSERT( !xsect );
774 
775  // try a same ray the other direction with base point below triangle
776  xsect = ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( -1.0, -1.0, -1.0 ), t );
777  ASSERT( !xsect );
778 
779  // try a ray that passes above the triangle
780  xsect = ray_tri_intersect( tri, CartVect( 1.0, 1.0, 1.0 ), CartVect( -1.0, -1.0, 1.0 ), t );
781  ASSERT( !xsect );
782 
783  // try a skew ray
784  xsect = ray_tri_intersect( tri, CartVect( 0.0, 0.0, 0.0 ), CartVect( 1.0, 1.0, -0.1 ), t );
785  ASSERT( !xsect );
786 }

References ASSERT, ASSERT_DOUBLES_EQUAL, moab::GeomUtil::ray_tri_intersect(), and t.

Referenced by main().

◆ test_segment_box_intersect()

void test_segment_box_intersect ( )

Definition at line 1016 of file GeomUtilTests.cpp.

1017 {
1018  const double box_min = 0.0;
1019  const double box_max = 2.0;
1020  const double box_wid = box_max - box_min;
1021  const double box_mid = 0.5 * ( box_min + box_max );
1022  const CartVect min( box_min );
1023  const CartVect max( box_max );
1024  const CartVect X( 1, 0, 0 ), Y( 0, 1, 0 ), Z( 0, 0, 1 );
1025  CartVect pt;
1026  double start, end;
1027  bool r;
1028 
1029  // test line through box in +x direction
1030  double offset = 1;
1031  pt = CartVect( box_min - offset, box_mid, box_mid );
1032  start = -HUGE_VAL;
1033  end = HUGE_VAL;
1034  r = segment_box_intersect( min, max, pt, X, start, end );
1035  ASSERT( r );
1036  ASSERT_DOUBLES_EQUAL( start, box_min + offset );
1037  ASSERT_DOUBLES_EQUAL( end - start, box_wid );
1038 
1039  // test with ray ending left of the box
1040  start = -HUGE_VAL;
1041  end = 0;
1042  r = segment_box_intersect( min, max, pt, X, start, end );
1043  ASSERT( !r );
1044 
1045  // test with ray ending within box
1046  start = -HUGE_VAL;
1047  end = box_mid + offset;
1048  r = segment_box_intersect( min, max, pt, X, start, end );
1049  ASSERT( r );
1050  ASSERT_DOUBLES_EQUAL( start, box_min + offset );
1051  ASSERT_DOUBLES_EQUAL( end, box_mid + offset );
1052 
1053  // test with ray beginning within box
1054  start = box_mid + offset;
1055  end = HUGE_VAL;
1056  r = segment_box_intersect( min, max, pt, X, start, end );
1057  ASSERT( r );
1058  ASSERT_DOUBLES_EQUAL( start, box_mid + offset );
1059  ASSERT_DOUBLES_EQUAL( end, box_max + offset );
1060 
1061  // test with ray right of box
1062  start = offset + offset + box_max;
1063  end = HUGE_VAL;
1064  r = segment_box_intersect( min, max, pt, X, start, end );
1065  ASSERT( !r );
1066 
1067  // test line through box in -y direction
1068  offset = 1;
1069  pt = CartVect( box_mid, box_min - offset, box_mid );
1070  start = -HUGE_VAL;
1071  end = HUGE_VAL;
1072  r = segment_box_intersect( min, max, pt, -Y, start, end );
1073  ASSERT( r );
1074  ASSERT_DOUBLES_EQUAL( end - start, box_wid );
1075  ASSERT_DOUBLES_EQUAL( end, box_min - offset );
1076 
1077  // test with ray ending left of the box
1078  start = box_min;
1079  end = HUGE_VAL;
1080  r = segment_box_intersect( min, max, pt, -Y, start, end );
1081  ASSERT( !r );
1082 
1083  // test with ray beginning within box
1084  start = -box_mid - offset;
1085  end = HUGE_VAL;
1086  r = segment_box_intersect( min, max, pt, -Y, start, end );
1087  ASSERT( r );
1088  ASSERT_DOUBLES_EQUAL( start, -box_mid - offset );
1089  ASSERT_DOUBLES_EQUAL( end, box_min - offset );
1090 
1091  // test with ray ending within box
1092  start = -HUGE_VAL;
1093  end = -box_mid - offset;
1094  r = segment_box_intersect( min, max, pt, -Y, start, end );
1095  ASSERT( r );
1096  ASSERT_DOUBLES_EQUAL( start, -box_max - offset );
1097  ASSERT_DOUBLES_EQUAL( end, -box_mid - offset );
1098 
1099  // test with ray right of box
1100  start = -HUGE_VAL;
1101  end = -box_max - offset - offset;
1102  r = segment_box_intersect( min, max, pt, -Y, start, end );
1103  ASSERT( !r );
1104 
1105  // test ray outside in Z direction, parallel to Z plane, and
1106  // intersecting in projections into other planes
1107  pt = CartVect( box_mid, box_mid, box_max + 1 );
1108  start = 0;
1109  end = box_wid;
1110  r = segment_box_intersect( min, max, pt, X, start, end );
1111  ASSERT( !r );
1112  start = 0;
1113  end = box_wid;
1114  r = segment_box_intersect( min, max, pt, -X, start, end );
1115  ASSERT( !r );
1116  start = 0;
1117  end = box_wid;
1118  r = segment_box_intersect( min, max, pt, Y, start, end );
1119  ASSERT( !r );
1120  start = 0;
1121  end = box_wid;
1122  r = segment_box_intersect( min, max, pt, -Y, start, end );
1123  ASSERT( !r );
1124 
1125  // try the other side (less than the min Z);
1126  pt = CartVect( box_mid, box_mid, box_min - 1 );
1127  start = 0;
1128  end = box_wid;
1129  r = segment_box_intersect( min, max, pt, X, start, end );
1130  ASSERT( !r );
1131  start = 0;
1132  end = box_wid;
1133  r = segment_box_intersect( min, max, pt, -X, start, end );
1134  ASSERT( !r );
1135  start = 0;
1136  end = box_wid;
1137  r = segment_box_intersect( min, max, pt, Y, start, end );
1138  ASSERT( !r );
1139  start = 0;
1140  end = box_wid;
1141  r = segment_box_intersect( min, max, pt, -Y, start, end );
1142  ASSERT( !r );
1143 
1144  // now move the ray such that it lies exactly on the side of the box
1145  pt = CartVect( box_mid, box_mid, box_min );
1146  start = 0;
1147  end = box_wid;
1148  r = segment_box_intersect( min, max, pt, X, start, end );
1149  ASSERT( r );
1150  ASSERT_DOUBLES_EQUAL( start, 0 );
1151  ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid );
1152  start = 0;
1153  end = box_wid;
1154  r = segment_box_intersect( min, max, pt, -X, start, end );
1155  ASSERT( r );
1156  ASSERT_DOUBLES_EQUAL( start, 0 );
1157  ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid );
1158  start = 0;
1159  end = box_wid;
1160  r = segment_box_intersect( min, max, pt, Y, start, end );
1161  ASSERT( r );
1162  ASSERT_DOUBLES_EQUAL( start, 0 );
1163  ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid );
1164  start = 0;
1165  end = box_wid;
1166  r = segment_box_intersect( min, max, pt, -Y, start, end );
1167  ASSERT( r );
1168  ASSERT_DOUBLES_EQUAL( start, 0 );
1169  ASSERT_DOUBLES_EQUAL( end, 0.5 * box_wid );
1170 
1171  // try a skew line segment
1172  pt = CartVect( box_min - 0.25 * box_wid, box_mid, box_mid );
1173  CartVect dir( 1.0 / sqrt( 2.0 ), 1.0 / sqrt( 2.0 ), 0 );
1174  start = 0;
1175  end = 1.5 / sqrt( 2.0 ) * box_wid;
1176  r = segment_box_intersect( min, max, pt, dir, start, end );
1177  ASSERT( r );
1178  ASSERT_DOUBLES_EQUAL( start, 0.5 / sqrt( 2.0 ) * box_wid );
1179  ASSERT_DOUBLES_EQUAL( end, box_wid / sqrt( 2.0 ) );
1180 
1181  // try with skew line segment that just touches edge of box
1182  pt = CartVect( box_min - 0.5 * box_wid, box_mid, box_mid );
1183  start = 0;
1184  end = 3.0 / sqrt( 2.0 ) * box_wid;
1185  r = segment_box_intersect( min, max, pt, dir, start, end );
1186  ASSERT( r );
1187  ASSERT_DOUBLES_EQUAL( start, box_wid / sqrt( 2.0 ) );
1188  ASSERT_DOUBLES_EQUAL( end, box_wid / sqrt( 2.0 ) );
1189 
1190  // try with skew line segment outside of box
1191  pt = CartVect( box_min - 0.75 * box_wid, box_mid, box_mid );
1192  start = 0;
1193  end = 3.0 / sqrt( 2.0 ) * box_wid;
1194  r = segment_box_intersect( min, max, pt, dir, start, end );
1195  ASSERT( !r );
1196 }

References ASSERT, ASSERT_DOUBLES_EQUAL, box_max(), box_min(), moab::GeomUtil::segment_box_intersect(), and Z.

Referenced by main().

Variable Documentation

◆ TOL

const double TOL = 1e-6

Definition at line 10 of file GeomUtilTests.cpp.

Referenced by assert_vectors_equal().