PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_ptarray_ptarrayarc()

static void test_lw_dist2d_ptarray_ptarrayarc ( void  )
static

Definition at line 1045 of file cu_measures.c.

References ASSERT_STRING_EQUAL, cu_error_msg, cu_error_msg_reset(), DIST_MIN, DISTPTS::distance, lw_dist2d_distpts_init(), lw_dist2d_ptarray_ptarrayarc(), LW_FAILURE, LW_SUCCESS, lwgeom_as_lwline(), lwgeom_from_text(), lwline_free(), and LWLINE::points.

Referenced by measures_suite_setup().

1046 {
1047  /* int lw_dist2d_ptarray_ptarrayarc(const POINTARRAY *pa, const POINTARRAY *pb, DISTPTS *dl) */
1048  DISTPTS dl;
1049  int rv;
1050  LWLINE *lwline1;
1051  LWLINE *lwline2;
1052 
1053  /* Unit semi-circle above X axis */
1054  lwline1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
1055 
1056  /* Line above top of semi-circle */
1057  lwline2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-2 2, -1 2, 1 2, 2 2)"));
1059  rv = lw_dist2d_ptarray_ptarrayarc(lwline2->points, lwline1->points, &dl);
1060  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1061  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1062 
1063  /* Reversed arguments, should fail */
1066  rv = lw_dist2d_ptarray_ptarrayarc(lwline1->points, lwline2->points, &dl);
1067  //printf("%s\n", cu_error_msg);
1068  CU_ASSERT_EQUAL( rv, LW_FAILURE );
1070  cu_error_msg,
1071  "lw_dist2d_ptarray_ptarrayarc called with non-arc input");
1072 
1073  lwline_free(lwline2);
1074 
1075  /* Line along side of semi-circle */
1076  lwline2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-2 -3, -2 -2, -2 2, -2 3)"));
1078  rv = lw_dist2d_ptarray_ptarrayarc(lwline2->points, lwline1->points, &dl);
1079  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1080  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1081 
1082  /* Four unit semi-circles surrounding the 2x2 box around origin */
1083  lwline_free(lwline1);
1084  lwline_free(lwline2);
1085  lwline1 = 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)"));
1086  lwline2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-2.5 -3, -2.5 -2, -2.5 2, -2.5 3)"));
1087  rv = lw_dist2d_ptarray_ptarrayarc(lwline2->points, lwline1->points, &dl);
1088  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1089  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1090 
1091  lwline_free(lwline2);
1092  lwline_free(lwline1);
1093 }
#define ASSERT_STRING_EQUAL(o, e)
#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
#define LW_FAILURE
Definition: liblwgeom.h:78
#define DIST_MIN
Definition: measures.h:41
void cu_error_msg_reset()
int lw_dist2d_ptarray_ptarrayarc(const POINTARRAY *pa, const POINTARRAY *pb, DISTPTS *dl)
Test each segment of pa against each arc of pb for distance.
Definition: measures.c:1187
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
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
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
POINTARRAY * points
Definition: liblwgeom.h:424
Here is the call graph for this function:
Here is the caller graph for this function: