PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_seg_arc()

static void test_lw_dist2d_seg_arc ( void  )
static

Definition at line 680 of file cu_measures.c.

References DIST_MIN, DISTPTS::distance, lw_dist2d_distpts_init(), lw_dist2d_seg_arc(), LW_SUCCESS, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

681 {
682  /* int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl) */
683 
684  DISTPTS dl;
685  POINT2D A1, A2, B1, B2, B3;
686  int rv;
687 
688  /* Unit semicircle */
689  B1.x = -1; B1.y = 0;
690  B2.x = 0 ; B2.y = 1;
691  B3.x = 1 ; B3.y = 0;
692 
693  /* Edge above the unit semicircle */
695  A1.x = -2; A1.y = 2;
696  A2.x = 2 ; A2.y = 2;
697  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
698  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
699  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
700 
701  /* Edge to the right of the unit semicircle */
703  A1.x = 2; A1.y = -2;
704  A2.x = 2; A2.y = 2;
705  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
706  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
707  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
708 
709  /* Edge to the left of the unit semicircle */
711  A1.x = -2; A1.y = -2;
712  A2.x = -2; A2.y = 2;
713  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
714  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
715  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
716 
717  /* Edge within the unit semicircle */
719  A1.x = 0; A1.y = 0;
720  A2.x = 0; A2.y = 0.5;
721  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
722  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
723  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
724 
725  /* Edge grazing the unit semicircle */
727  A1.x = -2; A1.y = 1;
728  A2.x = 2; A2.y = 1;
729  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
730  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
731  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0., 0.000001);
732 
733  /* Line grazing the unit semicircle, but edge not */
735  A1.x = 1; A1.y = 1;
736  A2.x = 2; A2.y = 1;
737  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
738  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
739  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
740 
741  /* Edge intersecting the unit semicircle */
743  A1.x = 0; A1.y = 0;
744  A2.x = 2; A2.y = 2;
745  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
746  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
747  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
748 
749  /* Line intersecting the unit semicircle, but edge not */
751  A1.x = -1; A1.y = 1;
752  A2.x = -2; A2.y = 2;
753  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
754  //printf("distance %g\n", dl.distance);
755  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
756  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
757 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
double x
Definition: liblwgeom.h:330
#define DIST_MIN
Definition: measures.h:41
double y
Definition: liblwgeom.h:330
double distance
Definition: measures.h:48
int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl)
Calculate the shortest distance between an arc and an edge.
Definition: measures.c:1292
Structure used in distance-calculations.
Definition: measures.h:46
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
Here is the call graph for this function:
Here is the caller graph for this function: