PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_arc()

static void test_lw_dist2d_pt_arc ( void  )
static

Definition at line 590 of file cu_measures.c.

References DIST_MIN, DISTPTS::distance, lw_dist2d_distpts_init(), lw_dist2d_pt_arc(), LW_SUCCESS, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

591 {
592  /* int lw_dist2d_pt_arc(const POINT2D* P, const POINT2D* A1, const POINT2D* A2, const POINT2D* A3, DISTPTS* dl) */
593  DISTPTS dl;
594  POINT2D P, A1, A2, A3;
595  int rv;
596 
597 
598  /* Point within unit semicircle, 0.5 units from arc */
599  A1.x = -1; A1.y = 0;
600  A2.x = 0 ; A2.y = 1;
601  A3.x = 1 ; A3.y = 0;
602  P.x = 0 ; P.y = 0.5;
603 
605  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
606  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
607  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
608 
609  /* Point outside unit semicircle, 0.5 units from arc */
610  P.x = 0 ; P.y = 1.5;
612  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
613  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
614  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
615 
616  /* Point outside unit semicircle, sqrt(2) units from arc end point*/
617  P.x = 0 ; P.y = -1;
619  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
620  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
621  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
622 
623  /* Point outside unit semicircle, sqrt(2)-1 units from arc end point*/
624  P.x = 1 ; P.y = 1;
626  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
627  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
628  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
629 
630  /* Point on unit semicircle midpoint */
631  P.x = 0 ; P.y = 1;
633  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
634  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
635  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
636 
637  /* Point on unit semicircle endpoint */
638  P.x = 1 ; P.y = 0;
640  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
641  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
642  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
643 
644  /* Point on semicircle center */
645  P.x = 0 ; P.y = 0;
647  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
648  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
649  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
650 
651  /* Point inside closed circle */
652  P.x = 0 ; P.y = 0.5;
653  A2.x = 1; A2.y = 0;
654  A3 = A1;
656  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
657  //printf("distance %g\n", dl.distance);
658  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
659  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
660 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
double x
Definition: liblwgeom.h:330
#define DIST_MIN
Definition: measures.h:41
int lw_dist2d_pt_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, DISTPTS *dl)
Definition: measures.c:1439
double y
Definition: liblwgeom.h:330
double distance
Definition: measures.h:48
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: