PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_seg_arc()

static void test_lw_dist2d_seg_arc ( void  )
static

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

603 {
604  /* int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl) */
605 
606  DISTPTS dl;
607  POINT2D A1, A2, B1, B2, B3;
608  int rv;
609 
610  /* Unit semicircle */
611  B1.x = -1; B1.y = 0;
612  B2.x = 0 ; B2.y = 1;
613  B3.x = 1 ; B3.y = 0;
614 
615  /* Edge above the unit semicircle */
617  A1.x = -2; A1.y = 2;
618  A2.x = 2 ; A2.y = 2;
619  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
620  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
621  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
622 
623  /* Edge to the right of the unit semicircle */
625  A1.x = 2; A1.y = -2;
626  A2.x = 2; A2.y = 2;
627  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
628  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
629  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
630 
631  /* Edge to the left of the unit semicircle */
633  A1.x = -2; A1.y = -2;
634  A2.x = -2; A2.y = 2;
635  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
636  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
637  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
638 
639  /* Edge within the unit semicircle */
641  A1.x = 0; A1.y = 0;
642  A2.x = 0; A2.y = 0.5;
643  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
644  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
645  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
646 
647  /* Edge grazing the unit semicircle */
649  A1.x = -2; A1.y = 1;
650  A2.x = 2; A2.y = 1;
651  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
652  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
653  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0., 0.000001);
654 
655  /* Line grazing the unit semicircle, but edge not */
657  A1.x = 1; A1.y = 1;
658  A2.x = 2; A2.y = 1;
659  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
660  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
661  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
662 
663  /* Edge intersecting the unit semicircle */
665  A1.x = 0; A1.y = 0;
666  A2.x = 2; A2.y = 2;
667  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
668  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
669  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
670 
671  /* Line intersecting the unit semicircle, but edge not */
673  A1.x = -1; A1.y = 1;
674  A2.x = -2; A2.y = 2;
675  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
676  //printf("distance %g\n", dl.distance);
677  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
678  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
679 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
double x
Definition: liblwgeom.h:328
#define DIST_MIN
Definition: measures.h:44
double y
Definition: liblwgeom.h:328
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:1288
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: