PostGIS  2.5.0dev-r@@SVN_REVISION@@
static void test_lw_dist2d_pt_arc ( void  )
static

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

484 {
485  /* int lw_dist2d_pt_arc(const POINT2D* P, const POINT2D* A1, const POINT2D* A2, const POINT2D* A3, DISTPTS* dl) */
486  DISTPTS dl;
487  POINT2D P, A1, A2, A3;
488  int rv;
489 
490 
491  /* Point within unit semicircle, 0.5 units from arc */
492  A1.x = -1; A1.y = 0;
493  A2.x = 0 ; A2.y = 1;
494  A3.x = 1 ; A3.y = 0;
495  P.x = 0 ; P.y = 0.5;
496 
498  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
499  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
500  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
501 
502  /* Point outside unit semicircle, 0.5 units from arc */
503  P.x = 0 ; P.y = 1.5;
505  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
506  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
507  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
508 
509  /* Point outside unit semicircle, sqrt(2) units from arc end point*/
510  P.x = 0 ; P.y = -1;
512  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
513  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
514  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
515 
516  /* Point outside unit semicircle, sqrt(2)-1 units from arc end point*/
517  P.x = 1 ; P.y = 1;
519  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
520  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
521  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
522 
523  /* Point on unit semicircle midpoint */
524  P.x = 0 ; P.y = 1;
526  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
527  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
528  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
529 
530  /* Point on unit semicircle endpoint */
531  P.x = 1 ; P.y = 0;
533  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
534  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
535  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
536 
537  /* Point on semicircle center */
538  P.x = 0 ; P.y = 0;
540  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
541  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
542  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
543 
544  /* Point inside closed circle */
545  P.x = 0 ; P.y = 0.5;
546  A2.x = 1; A2.y = 0;
547  A3 = A1;
549  rv = lw_dist2d_pt_arc(&P, &A1, &A2, &A3, &dl);
550  //printf("distance %g\n", dl.distance);
551  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
552  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
553 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
double x
Definition: liblwgeom.h:327
#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:1435
double y
Definition: liblwgeom.h:327
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: