PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_seg_arc()

static void test_lw_dist2d_seg_arc ( void  )
static

Definition at line 715 of file cu_measures.c.

716 {
717  /* int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl) */
718 
719  DISTPTS dl;
720  POINT2D A1, A2, B1, B2, B3;
721  int rv;
722 
723  /* Unit semicircle */
724  B1.x = -1; B1.y = 0;
725  B2.x = 0 ; B2.y = 1;
726  B3.x = 1 ; B3.y = 0;
727 
728  /* Edge above the unit semicircle */
730  A1.x = -2; A1.y = 2;
731  A2.x = 2 ; A2.y = 2;
732  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
733  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
734  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
735 
736  /* Edge to the right of the unit semicircle */
738  A1.x = 2; A1.y = -2;
739  A2.x = 2; A2.y = 2;
740  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
741  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
742  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
743 
744  /* Edge to the left of the unit semicircle */
746  A1.x = -2; A1.y = -2;
747  A2.x = -2; A2.y = 2;
748  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
749  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
750  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
751 
752  /* Edge within the unit semicircle */
754  A1.x = 0; A1.y = 0;
755  A2.x = 0; A2.y = 0.5;
756  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
757  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
758  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
759 
760  /* Edge grazing the unit semicircle */
762  A1.x = -2; A1.y = 1;
763  A2.x = 2; A2.y = 1;
764  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
765  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
766  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0., 0.000001);
767 
768  /* Line grazing the unit semicircle, but edge not */
770  A1.x = 1; A1.y = 1;
771  A2.x = 2; A2.y = 1;
772  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
773  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
774  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
775 
776  /* Edge intersecting the unit semicircle */
778  A1.x = 0; A1.y = 0;
779  A2.x = 2; A2.y = 2;
780  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
781  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
782  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
783 
784  /* Line intersecting the unit semicircle, but edge not */
786  A1.x = -1; A1.y = 1;
787  A2.x = -2; A2.y = 2;
788  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
789  //printf("distance %g\n", dl.distance);
790  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
791  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
792 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
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
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
#define DIST_MIN
Definition: measures.h:44
double distance
Definition: measures.h:51
Structure used in distance-calculations.
Definition: measures.h:50
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

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().

Here is the call graph for this function:
Here is the caller graph for this function: