PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_seg_arc()

static void test_lw_dist2d_seg_arc ( void  )
static

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

664 {
665  /* int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl) */
666 
667  DISTPTS dl;
668  POINT2D A1, A2, B1, B2, B3;
669  int rv;
670 
671  /* Unit semicircle */
672  B1.x = -1; B1.y = 0;
673  B2.x = 0 ; B2.y = 1;
674  B3.x = 1 ; B3.y = 0;
675 
676  /* Edge above the unit semicircle */
678  A1.x = -2; A1.y = 2;
679  A2.x = 2 ; A2.y = 2;
680  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
681  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
682  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
683 
684  /* Edge to the right of the unit semicircle */
686  A1.x = 2; A1.y = -2;
687  A2.x = 2; A2.y = 2;
688  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
689  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
690  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
691 
692  /* Edge to the left of the unit semicircle */
694  A1.x = -2; A1.y = -2;
695  A2.x = -2; A2.y = 2;
696  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
697  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
698  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
699 
700  /* Edge within the unit semicircle */
702  A1.x = 0; A1.y = 0;
703  A2.x = 0; A2.y = 0.5;
704  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
705  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
706  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
707 
708  /* Edge grazing the unit semicircle */
710  A1.x = -2; A1.y = 1;
711  A2.x = 2; A2.y = 1;
712  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
713  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
714  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0., 0.000001);
715 
716  /* Line grazing the unit semicircle, but edge not */
718  A1.x = 1; A1.y = 1;
719  A2.x = 2; A2.y = 1;
720  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
721  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
722  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
723 
724  /* Edge intersecting the unit semicircle */
726  A1.x = 0; A1.y = 0;
727  A2.x = 2; A2.y = 2;
728  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
729  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
730  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
731 
732  /* Line intersecting the unit semicircle, but edge not */
734  A1.x = -1; A1.y = 1;
735  A2.x = -2; A2.y = 2;
736  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
737  //printf("distance %g\n", dl.distance);
738  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
739  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
740 }
#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: