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

Definition at line 855 of file cu_measures.c.

References DIST_MIN, DISTPTS::distance, lw_dist2d_distpts_init(), lw_dist2d_pt_ptarrayarc(), LW_SUCCESS, lwgeom_as_lwline(), lwgeom_from_text(), lwline_free(), LWLINE::points, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

856 {
857  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
858  DISTPTS dl;
859  int rv;
860  LWLINE *lwline;
861  POINT2D P;
862 
863  /* Unit semi-circle above X axis */
864  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
865 
866  /* Point at origin */
867  P.x = P.y = 0;
869  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
870  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
871  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
872 
873  /* Point above arc on Y axis */
874  P.y = 2;
876  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
877  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
878  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
879 
880  /* Point 45 degrees off arc, 2 radii from center */
881  P.y = P.x = 2 * cos(M_PI_4);
883  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
884  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
885  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
886 
887  /* Four unit semi-circles surrounding the 2x2 box around origin */
888  lwline_free(lwline);
889  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 -1, -2 0, -1 1, 0 2, 1 1, 2 0, 1 -1, 0 -2, -1 -1)"));
890 
891  /* Point at origin */
892  P.x = P.y = 0;
894  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
895  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
896  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
897 
898  /* Point on box edge */
899  P.x = -1; P.y = 0;
901  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
902  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
903  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
904 
905  /* Point within a semicircle lobe */
906  P.x = -1.5; P.y = 0;
908  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
909  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
910  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
911 
912  /* Point outside a semicircle lobe */
913  P.x = -2.5; P.y = 0;
915  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
916  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
917  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
918 
919  /* Point outside a semicircle lobe */
920  P.y = -2.5; P.x = 0;
922  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
923  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
924  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
925 
926  /* Point outside a semicircle lobe */
927  P.y = 2; P.x = 1;
929  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
930  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
931  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
932 
933  /* Clean up */
934  lwline_free(lwline);
935 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
void lwline_free(LWLINE *line)
Definition: lwline.c:76
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:24
double x
Definition: liblwgeom.h:327
#define DIST_MIN
Definition: measures.h:41
int lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl)
Search all the arcs of pointarray to see which one is closest to p1 Returns minimum distance between ...
Definition: measures.c:1079
double y
Definition: liblwgeom.h:327
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
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
POINTARRAY * points
Definition: liblwgeom.h:421

Here is the call graph for this function:

Here is the caller graph for this function: