PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 1025 of file cu_measures.c.

1026 {
1027  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
1028  DISTPTS dl;
1029  int rv;
1030  LWLINE *lwline;
1031  POINT2D P;
1032 
1033  /* Unit semi-circle above X axis */
1034  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
1035 
1036  /* Point at origin */
1037  P.x = 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, 1, 0.000001);
1042 
1043  /* Point above arc on Y axis */
1044  P.y = 2;
1046  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1047  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1048  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1049 
1050  /* Point 45 degrees off arc, 2 radii from center */
1051  P.y = P.x = 2 * cos(M_PI_4);
1053  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1054  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1055  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1056 
1057  /* Four unit semi-circles surrounding the 2x2 box around origin */
1058  lwline_free(lwline);
1059  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)"));
1060 
1061  /* Point at origin */
1062  P.x = P.y = 0;
1064  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1065  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1066  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1067 
1068  /* Point on box edge */
1069  P.x = -1; P.y = 0;
1071  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1072  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1073  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1074 
1075  /* Point within a semicircle lobe */
1076  P.x = -1.5; P.y = 0;
1078  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1079  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1080  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1081 
1082  /* Point outside a semicircle lobe */
1083  P.x = -2.5; P.y = 0;
1085  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1086  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1087  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1088 
1089  /* Point outside a semicircle lobe */
1090  P.y = -2.5; P.x = 0;
1092  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1093  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1094  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1095 
1096  /* Point outside a semicircle lobe */
1097  P.y = 2; P.x = 1;
1099  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1100  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1101  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1102 
1103  /* Clean up */
1104  lwline_free(lwline);
1105 }
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:25
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
#define LW_SUCCESS
Definition: liblwgeom.h:80
void lwline_free(LWLINE *line)
Definition: lwline.c:76
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
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
#define DIST_MIN
Definition: measures.h:44
double distance
Definition: measures.h:51
Structure used in distance-calculations.
Definition: measures.h:50
POINTARRAY * points
Definition: liblwgeom.h:425
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

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().

Here is the call graph for this function:
Here is the caller graph for this function: