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

Definition at line 218 of file cu_ptarray.c.

References getPoint4d(), lwgeom_as_lwline(), lwgeom_from_text(), lwline_free(), POINT4D::m, LWLINE::points, ptarray_locate_point(), POINT4D::x, and POINT4D::y.

Referenced by ptarray_suite_setup().

219 {
220  LWLINE *line;
221  double loc, dist;
222  POINT4D p, l;
223 
224  line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 3,20 4)"));
225 
226  p = getPoint4d(line->points, 0);
227  loc = ptarray_locate_point(line->points, &p, &dist, &l);
228  CU_ASSERT_EQUAL(loc, 0);
229  CU_ASSERT_EQUAL(dist, 0.0);
230 
231  p = getPoint4d(line->points, 1);
232  loc = ptarray_locate_point(line->points, &p, &dist, &l);
233  CU_ASSERT_EQUAL(loc, 1);
234  CU_ASSERT_EQUAL(dist, 0.0);
235 
236  p.x = 21; p.y = 4;
237  loc = ptarray_locate_point(line->points, &p, &dist, NULL);
238  CU_ASSERT_EQUAL(loc, 1);
239  CU_ASSERT_EQUAL(dist, 1.0);
240 
241  p.x = 0; p.y = 2;
242  loc = ptarray_locate_point(line->points, &p, &dist, &l);
243  CU_ASSERT_EQUAL(loc, 0);
244  CU_ASSERT_EQUAL(dist, 1.0);
245 
246  lwline_free(line);
247  line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0,20 0,40 0)"));
248 
249  p.x = 20; p.y = 0;
250  loc = ptarray_locate_point(line->points, &p, &dist, &l);
251  CU_ASSERT_EQUAL(loc, 0.5);
252  CU_ASSERT_EQUAL(dist, 0.0);
253 
254  lwline_free(line);
255  line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-40 0,0 0,20 0,40 0)"));
256 
257  p.x = 20; p.y = 0;
258  loc = ptarray_locate_point(line->points, &p, &dist, &l);
259  CU_ASSERT_EQUAL(loc, 0.75);
260  CU_ASSERT_EQUAL(dist, 0.0);
261 
262  lwline_free(line);
263  line = lwgeom_as_lwline(lwgeom_from_text("LINESTRING M (0 0 0, 10 0 20)"));
264 
265  p.x = 5; p.y = 0;
266  loc = ptarray_locate_point(line->points, &p, &dist, &l);
267  CU_ASSERT_EQUAL(loc, 0.5);
268  CU_ASSERT_EQUAL(dist, 0.0);
269  CU_ASSERT_EQUAL(l.m, 10.0);
270 
271  lwline_free(line);
272 
273 }
double x
Definition: liblwgeom.h:308
double m
Definition: liblwgeom.h:308
void lwline_free(LWLINE *line)
Definition: lwline.c:63
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1267
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_ptarray.c:25
POINT4D getPoint4d(const POINTARRAY *pa, int n)
Definition: lwgeom_api.c:202
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
double y
Definition: liblwgeom.h:308
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function:

Here is the caller graph for this function: