PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

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

980 {
981  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
982  DISTPTS dl;
983  int rv;
984  LWLINE *lwline;
985  POINT2D P;
986 
987  /* Unit semi-circle above X axis */
988  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
989 
990  /* Point at origin */
991  P.x = P.y = 0;
993  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
994  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
995  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
996 
997  /* Point above arc on Y axis */
998  P.y = 2;
1000  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1001  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1002  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1003 
1004  /* Point 45 degrees off arc, 2 radii from center */
1005  P.y = P.x = 2 * cos(M_PI_4);
1007  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1008  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1009  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1010 
1011  /* Four unit semi-circles surrounding the 2x2 box around origin */
1012  lwline_free(lwline);
1013  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)"));
1014 
1015  /* Point at origin */
1016  P.x = P.y = 0;
1018  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1019  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1020  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1021 
1022  /* Point on box edge */
1023  P.x = -1; P.y = 0;
1025  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1026  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1027  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1028 
1029  /* Point within a semicircle lobe */
1030  P.x = -1.5; P.y = 0;
1032  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1033  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1034  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1035 
1036  /* Point outside a semicircle lobe */
1037  P.x = -2.5; P.y = 0;
1039  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1040  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1041  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1042 
1043  /* Point outside a semicircle lobe */
1044  P.y = -2.5; P.x = 0;
1046  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1047  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1048  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1049 
1050  /* Point outside a semicircle lobe */
1051  P.y = 2; P.x = 1;
1053  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1054  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1055  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1056 
1057  /* Clean up */
1058  lwline_free(lwline);
1059 }
#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:330
#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:1083
double y
Definition: liblwgeom.h:330
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
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:424
Here is the call graph for this function:
Here is the caller graph for this function: