PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_arc()

static void test_lw_dist2d_pt_arc ( void  )
static

Definition at line 642 of file cu_measures.c.

643 {
644  /* int lw_dist2d_pt_arc(const POINT2D* P, const POINT2D* A1, const POINT2D* A2, const POINT2D* A3, DISTPTS* dl) */
645  DISTPTS dl;
646  POINT2D P, A1, A2, A3;
647  int rv;
648 
649 
650  /* Point within unit semicircle, 0.5 units from arc */
651  A1.x = -1; A1.y = 0;
652  A2.x = 0 ; A2.y = 1;
653  A3.x = 1 ; A3.y = 0;
654  P.x = 0 ; P.y = 0.5;
655 
657  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
658  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
659  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
660 
661  /* Point outside unit semicircle, 0.5 units from arc */
662  P.x = 0 ; P.y = 1.5;
664  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
665  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
666  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
667 
668  /* Point outside unit semicircle, sqrt(2) units from arc end point*/
669  P.x = 0 ; P.y = -1;
671  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
672  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
673  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
674 
675  /* Point outside unit semicircle, sqrt(2)-1 units from arc end point*/
676  P.x = 1 ; P.y = 1;
678  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
679  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
680  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
681 
682  /* Point on unit semicircle midpoint */
683  P.x = 0 ; P.y = 1;
685  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
686  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
687  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
688 
689  /* Point on unit semicircle endpoint */
690  P.x = 1 ; P.y = 0;
692  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
693  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
694  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
695 
696  /* Point on semicircle center */
697  P.x = 0 ; P.y = 0;
699  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
700  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
701  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
702 
703  /* Point inside closed circle */
704  P.x = 0 ; P.y = 0.5;
705  A2.x = 1; A2.y = 0;
706  A3 = A1;
708  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
709  //printf("distance %g\n", dl.distance);
710  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
711  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
712 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
int lw_dist2d_pt_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, DISTPTS *dl)
Definition: measures.c:1439
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_pt_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: