PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_seg_arc()

static void test_lw_dist2d_seg_arc ( void  )
static

Definition at line 556 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().

557 {
558  /* int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl) */
559 
560  DISTPTS dl;
561  POINT2D A1, A2, B1, B2, B3;
562  int rv;
563 
564  /* Unit semicircle */
565  B1.x = -1; B1.y = 0;
566  B2.x = 0 ; B2.y = 1;
567  B3.x = 1 ; B3.y = 0;
568 
569  /* Edge above the unit semicircle */
571  A1.x = -2; A1.y = 2;
572  A2.x = 2 ; A2.y = 2;
573  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
574  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
575  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
576 
577  /* Edge to the right of the unit semicircle */
579  A1.x = 2; A1.y = -2;
580  A2.x = 2; A2.y = 2;
581  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
582  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
583  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
584 
585  /* Edge to the left of the unit semicircle */
587  A1.x = -2; A1.y = -2;
588  A2.x = -2; A2.y = 2;
589  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
590  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
591  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
592 
593  /* Edge within the unit semicircle */
595  A1.x = 0; A1.y = 0;
596  A2.x = 0; A2.y = 0.5;
597  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
598  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
599  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
600 
601  /* Edge grazing the unit semicircle */
603  A1.x = -2; A1.y = 1;
604  A2.x = 2; A2.y = 1;
605  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
606  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
607  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0., 0.000001);
608 
609  /* Line grazing the unit semicircle, but edge not */
611  A1.x = 1; A1.y = 1;
612  A2.x = 2; A2.y = 1;
613  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
614  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
615  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
616 
617  /* Edge intersecting the unit semicircle */
619  A1.x = 0; A1.y = 0;
620  A2.x = 2; A2.y = 2;
621  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
622  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
623  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
624 
625  /* Line intersecting the unit semicircle, but edge not */
627  A1.x = -1; A1.y = 1;
628  A2.x = -2; A2.y = 2;
629  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
630  //printf("distance %g\n", dl.distance);
631  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
632  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
633 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
double x
Definition: liblwgeom.h:327
#define DIST_MIN
Definition: measures.h:41
double y
Definition: liblwgeom.h:327
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:1288
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: