PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_seg_arc()

static void test_lw_dist2d_seg_arc ( void  )
static

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

709 {
710  /* int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl) */
711 
712  DISTPTS dl;
713  POINT2D A1, A2, B1, B2, B3;
714  int rv;
715 
716  /* Unit semicircle */
717  B1.x = -1; B1.y = 0;
718  B2.x = 0 ; B2.y = 1;
719  B3.x = 1 ; B3.y = 0;
720 
721  /* Edge above the unit semicircle */
723  A1.x = -2; A1.y = 2;
724  A2.x = 2 ; A2.y = 2;
725  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
726  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
727  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
728 
729  /* Edge to the right of the unit semicircle */
731  A1.x = 2; A1.y = -2;
732  A2.x = 2; A2.y = 2;
733  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
734  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
735  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
736 
737  /* Edge to the left of the unit semicircle */
739  A1.x = -2; A1.y = -2;
740  A2.x = -2; A2.y = 2;
741  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
742  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
743  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
744 
745  /* Edge within the unit semicircle */
747  A1.x = 0; A1.y = 0;
748  A2.x = 0; A2.y = 0.5;
749  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
750  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
751  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
752 
753  /* Edge grazing the unit semicircle */
755  A1.x = -2; A1.y = 1;
756  A2.x = 2; A2.y = 1;
757  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
758  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
759  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0., 0.000001);
760 
761  /* Line grazing the unit semicircle, but edge not */
763  A1.x = 1; A1.y = 1;
764  A2.x = 2; A2.y = 1;
765  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
766  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
767  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
768 
769  /* Edge intersecting the unit semicircle */
771  A1.x = 0; A1.y = 0;
772  A2.x = 2; A2.y = 2;
773  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
774  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
775  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
776 
777  /* Line intersecting the unit semicircle, but edge not */
779  A1.x = -1; A1.y = 1;
780  A2.x = -2; A2.y = 2;
781  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
782  //printf("distance %g\n", dl.distance);
783  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
784  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
785 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
double x
Definition: liblwgeom.h:330
#define DIST_MIN
Definition: measures.h:44
double y
Definition: liblwgeom.h:330
double distance
Definition: measures.h:51
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:49
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: