PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_lw_dist2d_seg_arc ( void  )
static

Definition at line 501 of file cu_measures.c.

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

Referenced by measures_suite_setup().

502 {
503  /* int lw_dist2d_seg_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl) */
504 
505  DISTPTS dl;
506  POINT2D A1, A2, B1, B2, B3;
507  int rv;
508 
509  /* Unit semicircle */
510  B1.x = -1; B1.y = 0;
511  B2.x = 0 ; B2.y = 1;
512  B3.x = 1 ; B3.y = 0;
513 
514  /* Edge above the unit semicircle */
516  A1.x = -2; A1.y = 2;
517  A2.x = 2 ; A2.y = 2;
518  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
519  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
520 
521  /* Edge to the right of the unit semicircle */
523  A1.x = 2; A1.y = -2;
524  A2.x = 2; A2.y = 2;
525  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
526  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
527 
528  /* Edge to the left of the unit semicircle */
530  A1.x = -2; A1.y = -2;
531  A2.x = -2; A2.y = 2;
532  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
533  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
534 
535  /* Edge within the unit semicircle */
537  A1.x = 0; A1.y = 0;
538  A2.x = 0; A2.y = 0.5;
539  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
540  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
541 
542  /* Edge grazing the unit semicircle */
544  A1.x = -2; A1.y = 1;
545  A2.x = 2; A2.y = 1;
546  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
547  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0., 0.000001);
548 
549  /* Line grazing the unit semicircle, but edge not */
551  A1.x = 1; A1.y = 1;
552  A2.x = 2; A2.y = 1;
553  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
554  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
555 
556  /* Edge intersecting the unit semicircle */
558  A1.x = 0; A1.y = 0;
559  A2.x = 2; A2.y = 2;
560  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
561  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
562 
563  /* Line intersecting the unit semicircle, but edge not */
565  A1.x = -1; A1.y = 1;
566  A2.x = -2; A2.y = 2;
567  rv = lw_dist2d_seg_arc(&A1, &A2, &B1, &B2, &B3, &dl);
568  //printf("distance %g\n", dl.distance);
569  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1, 0.000001);
570 }
#define DIST_MIN
double x
Definition: liblwgeom.h:284
double y
Definition: liblwgeom.h:284
double distance
Definition: measures.h:23
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:1248
Structure used in distance-calculations.
Definition: measures.h:21
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:27

Here is the call graph for this function:

Here is the caller graph for this function: