PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_arc()

static void test_lw_dist2d_pt_arc ( void  )
static

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

530 {
531  /* int lw_dist2d_pt_arc(const POINT2D* P, const POINT2D* A1, const POINT2D* A2, const POINT2D* A3, DISTPTS* dl) */
532  DISTPTS dl;
533  POINT2D P, A1, A2, A3;
534  int rv;
535 
536 
537  /* Point within unit semicircle, 0.5 units from arc */
538  A1.x = -1; A1.y = 0;
539  A2.x = 0 ; A2.y = 1;
540  A3.x = 1 ; A3.y = 0;
541  P.x = 0 ; P.y = 0.5;
542 
544  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
545  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
546  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
547 
548  /* Point outside unit semicircle, 0.5 units from arc */
549  P.x = 0 ; P.y = 1.5;
551  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
552  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
553  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
554 
555  /* Point outside unit semicircle, sqrt(2) units from arc end point*/
556  P.x = 0 ; P.y = -1;
558  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
559  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
560  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
561 
562  /* Point outside unit semicircle, sqrt(2)-1 units from arc end point*/
563  P.x = 1 ; P.y = 1;
565  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
566  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
567  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
568 
569  /* Point on unit semicircle midpoint */
570  P.x = 0 ; P.y = 1;
572  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
573  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
574  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
575 
576  /* Point on unit semicircle endpoint */
577  P.x = 1 ; P.y = 0;
579  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
580  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
581  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
582 
583  /* Point on semicircle center */
584  P.x = 0 ; P.y = 0;
586  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
587  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
588  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
589 
590  /* Point inside closed circle */
591  P.x = 0 ; P.y = 0.5;
592  A2.x = 1; A2.y = 0;
593  A3 = A1;
595  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
596  //printf("distance %g\n", dl.distance);
597  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
598  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
599 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
double x
Definition: liblwgeom.h:328
#define DIST_MIN
Definition: measures.h:44
int lw_dist2d_pt_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, DISTPTS *dl)
Definition: measures.c:1435
double y
Definition: liblwgeom.h:328
double distance
Definition: measures.h:51
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: