31 #include "../postgis_config.h"
90 LWDEBUGF(5,
"pa = %p; p = %p; where = %d", pa, p, where);
95 lwerror(
"ptarray_insert_point: called on read-only point array");
102 lwerror(
"ptarray_insert_point: offset out of range (%d)", where);
129 if( where < pa->npoints )
131 size_t copy_size = point_size * (pa->
npoints - where);
133 LWDEBUGF(5,
"copying %d bytes to start vertex %d from start vertex %d", copy_size, where+1, where);
141 LWDEBUGF(5,
"copying new point to start vertex %d", point_size, where);
152 lwerror(
"ptarray_append_point: null input");
161 LWDEBUGF(4,
"checking for duplicate end point (pt = POINT(%g %g) pa->npoints-q = POINT(%g %g))",pt->
x,pt->
y,tmp.
x,tmp.
y);
164 if ( (pt->
x == tmp.
x) && (pt->
y == tmp.
y) &&
179 unsigned int poff = 0;
180 unsigned int npoints;
187 lwerror(
"ptarray_append_ptarray: null input");
197 lwerror(
"ptarray_append_ptarray: target pointarray is read-only");
203 lwerror(
"ptarray_append_ptarray: appending mixed dimensionality is not allowed");
221 else if ( gap_tolerance == 0 || ( gap_tolerance > 0 &&
224 lwerror(
"Second line start point too far from first line end point");
264 lwerror(
"ptarray_remove_point: null input");
271 lwerror(
"ptarray_remove_point: offset out of range (%d)", where);
276 if (where < pa->npoints - 1)
294 LWDEBUGF(5,
"hasz = %d, hasm = %d, npoints = %d, ptlist = %p", hasz, hasm, npoints, ptlist);
344 uint32_t last = pa->
npoints - 1;
345 uint32_t mid = pa->
npoints / 2;
350 for (i = 0; i < mid; i++)
352 for (j = 0; j < ndims; j++)
356 d[i*ndims+j] = d[(last-i)*ndims+j];
357 d[(last-i)*ndims+j] = buf;
374 for (i=0 ; i < pa->
npoints ; i++)
390 double d, *dp1, *dp2;
393 dp1 = ((
double*)&p)+(unsigned)o1;
394 dp2 = ((
double*)&p)+(unsigned)o2;
395 for (i=0 ; i < pa->
npoints ; i++)
423 pbuf.
x = pbuf.
y = pbuf.
z = pbuf.
m = 0;
433 for (i = 1; i < ipa->
npoints; i++)
444 POINT4D *p1ptr=&p1, *p2ptr=&p2;
451 segments = ceil(segdist / dist);
456 lwnotice(
"%s:%d - %s: Too many segments required (%e)",
457 __FILE__, __LINE__,__func__, segments);
463 for (j = 1; j < nseg; j++)
465 pbuf.
x = p1.
x + (p2.
x - p1.
x) * j / nseg;
466 pbuf.
y = p1.
y + (p2.
y - p1.
y) * j / nseg;
468 pbuf.
z = p1.
z + (p2.
z - p1.
z) * j / nseg;
470 pbuf.
m = p1.
m + (p2.
m - p1.
m) * j / nseg;
490 LWDEBUG(5,
"dimensions are the same");
493 LWDEBUG(5,
"npoints are the same");
502 LWDEBUGF(5,
"point #%d is the same",i);
515 LWDEBUGF(3,
"pa %x p %x size %d where %d",
516 pa, p, pdims, where);
518 if ( pdims < 2 || pdims > 4 )
520 lwerror(
"ptarray_addPoint: point dimension out of range (%d)",
527 lwerror(
"ptarray_addPoint: offset out of range (%d)",
532 LWDEBUG(3,
"called with a %dD point");
534 pbuf.
x = pbuf.
y = pbuf.
z = pbuf.
m = 0.0;
535 memcpy((uint8_t *)&pbuf, p, pdims*
sizeof(
double));
537 LWDEBUG(3,
"initialized point buffer");
566 LWDEBUGF(3,
"pa %x which %d", pa, which);
568 #if PARANOIA_LEVEL > 0
571 lwerror(
"%s [%d] offset (%d) out of range (%d..%d)", __FILE__, __LINE__,
578 lwerror(
"%s [%d] can't remove a point from a 2-vertex POINTARRAY", __FILE__, __LINE__);
593 if ( which < pa->npoints-1 )
609 lwerror(
"ptarray_cat: Mixed dimension");
638 LWDEBUG(3,
"ptarray_clone_deep called.");
669 LWDEBUG(3,
"ptarray_clone called.");
691 lwerror(
"ptarray_is_closed: called with null point array");
705 lwerror(
"ptarray_is_closed_2d: called with null point array");
718 lwerror(
"ptarray_is_closed_3d: called with null point array");
754 lwerror(
"ptarray_contains_point called on unclosed ring");
756 for (uint32_t i = 1; i < pa->
npoints; i++)
758 double side, ymin, ymax;
773 if (pt->
y > ymax || pt->
y < ymin)
795 if ((side < 0) && (seg1->
y <= pt->
y) && (pt->
y < seg2->
y))
805 else if ( (side > 0) && (seg2->
y <= pt->
y) && (pt->
y < seg1->
y) )
822 lwerror(
"%s called on invalid linestring", __func__);
824 int intersections = 0;
829 for (uint32_t i = 0; i < pa->
npoints-1; ++i)
853 if (((p1->
y <= py) && (py < p2->
y)) || ((p2->
y <= py) && (py < p1->
y)))
859 double x_intersection = p1->
x + (py - p1->
y) * (p2->
x - p1->
x) / (p2->
y - p1->
y);
865 if (x_intersection > px)
872 return intersections;
897 double dy = ray - center->
y;
900 if (fabs(dy) > radius)
906 double dx_squared = radius * radius - dy * dy;
920 double dx = sqrt(dx_squared);
923 i0->
x = center->
x - dx;
927 i1->
x = center->
x + dx;
937 int intersections = 0;
945 lwerror(
"%s called on invalid circularstring", __func__);
948 lwerror(
"%s called with even number of points", __func__);
951 for (uint32_t i = 1; i < pa->
npoints-1; i +=2)
985 if ((gbox.
ymin <= py) && (py < gbox.
ymax))
1013 return intersections;
1028 if ( check_closed && !
p2d_same(seg1, seg2) )
1029 lwerror(
"ptarray_contains_point called on unclosed ring");
1031 for ( i=1; i < pa->
npoints; i++ )
1036 if ( seg1->
x == seg2->
x && seg1->
y == seg2->
y )
1046 if ( pt->
y > ymax || pt->
y < ymin )
1068 if ( (side < 0) && (seg1->
y <= pt->
y) && (pt->
y < seg2->
y) )
1078 else if ( (side > 0) && (seg2->
y <= pt->
y) && (pt->
y < seg1->
y) )
1087 if ( winding_number )
1088 *winding_number = wn;
1115 lwerror(
"%s called on unclosed ring", __func__);
1138 lwerror(
"ptarrayarc_contains_point called with even number of points");
1145 lwerror(
"ptarrayarc_contains_point called too-short pointarray");
1152 if ( check_closed && !
p2d_same(seg1, seg3) )
1154 lwerror(
"ptarrayarc_contains_point called on unclosed ring");
1173 else if ( d < radius )
1185 for ( i=1; i < pa->
npoints; i += 2 )
1203 if ( pt->
y > gbox.
ymax || pt->
y < gbox.
ymin )
1210 if ( (pt->
x > gbox.
xmax || pt->
x < gbox.
xmin) &&
1220 if ( (side == 0) &&
lw_pt_in_arc(pt, seg1, seg2, seg3) )
1226 if ( side < 0 && (seg1->
y <= pt->
y) && (pt->
y < seg3->
y) )
1232 if ( side > 0 && (seg3->
y <= pt->
y) && (pt->
y < seg1->
y) )
1238 if ( pt->
x <= gbox.
xmax && pt->
x >= gbox.
xmin )
1264 if ( winding_number )
1265 *winding_number = wn;
1289 double x0,
x, y1, y2;
1298 for ( i = 2; i < pa->
npoints; i++ )
1332 for( i = 0; i < pa->
npoints; i++ )
1335 if( hasz && ! in_hasz )
1337 if( hasm && ! in_hasm )
1354 double length, slength, tlength;
1367 LWDEBUGF(3,
"Total length: %g", length);
1375 LWDEBUGF(3,
"From/To: %g/%g", from, to);
1381 for ( i = 0; i < nsegs; i++ )
1388 LWDEBUGF(3 ,
"Segment %d: (%g,%g,%g,%g)-(%g,%g,%g,%g)",
1389 i, p1.
x, p1.
y, p1.
z, p1.
m, p2.
x, p2.
y, p2.
z, p2.
m);
1403 if ( fabs ( from - ( tlength + slength ) ) <= tolerance )
1406 LWDEBUG(3,
" Second point is our start");
1416 else if ( fabs(from - tlength) <= tolerance )
1419 LWDEBUG(3,
" First point is our start");
1437 else if ( from > tlength + slength )
goto END;
1442 LWDEBUG(3,
" Seg contains first point");
1448 dseg = (from - tlength) / slength;
1470 if ( fabs(to - ( tlength + slength ) ) <= tolerance )
1473 LWDEBUG(3,
" Second point is our end");
1483 else if ( fabs(to - tlength) <= tolerance )
1486 LWDEBUG(3,
" First point is our end");
1497 else if ( to > tlength + slength )
1507 else if ( to < tlength + slength )
1510 LWDEBUG(3,
" Seg contains our end");
1512 dseg = (to - tlength) / slength;
1530 memcpy(&p1, &p2,
sizeof(
POINT4D));
1567 r = ( (p->
x-A->
x) * (B->
x-A->
x) + (p->
y-A->
y) * (B->
y-A->
y) )/( (B->
x-A->
x)*(B->
x-A->
x) +(B->
y-A->
y)*(B->
y-A->
y) );
1580 ret->
x = A->
x + ( (B->
x - A->
x) *
r );
1581 ret->
y = A->
y + ( (B->
y - A->
y) *
r );
1582 ret->
z = A->
z + ( (B->
z - A->
z) *
r );
1583 ret->
m = A->
m + ( (B->
m - A->
m) *
r );
1591 double mindist=DBL_MAX;
1600 if (dist_sqr < mindist)
1606 LWDEBUG(3,
"Breaking on mindist=0");
1614 if ( dist ) *dist = sqrt(mindist);
1624 double mindist = DBL_MAX;
1633 if (dist_sqr < mindist)
1639 LWDEBUG(3,
"Breaking on mindist=0");
1644 if ( dist ) *dist = sqrt(mindist);
1655 double mindist=DBL_MAX;
1658 POINT4D start4d, end4d, projtmp;
1660 const POINT2D *start = NULL, *end = NULL;
1666 if ( ! proj4d ) proj4d = &projtmp;
1688 if (dist_sqr < mindist)
1694 LWDEBUG(3,
"Breaking on mindist=0");
1701 mindist = sqrt(mindist);
1703 if ( mindistout ) *mindistout = mindist;
1705 LWDEBUGF(3,
"Closest segment: %d", seg);
1706 LWDEBUGF(3,
"mindist: %g", mindist);
1728 LWDEBUGF(3,
"Closest point on segment: %g,%g", proj.
x, proj.
y);
1736 if ( tlen == 0 )
return 0;
1740 for (t=0; t<seg; t++, start=end)
1745 LWDEBUGF(4,
"Segment %d made plen %g", t, plen);
1750 LWDEBUGF(3,
"plen %g, tlen %g", plen, tlen);
1773 if (
x < 0 )
x+= 360;
1774 else if (
x > 180 )
x -= 360;
1805 double tolsq = tolerance * tolerance;
1808 uint32_t n_points = pa->
npoints;
1809 uint32_t n_points_out = 1;
1812 double dsq = FLT_MAX;
1815 if ( n_points <= min_points )
return;
1818 void *p_to = ((
char *)last) + pt_size;
1819 for (i = 1; i < n_points; i++)
1821 int last_point = (i == n_points - 1);
1827 if (n_points + n_points_out > min_points + i)
1829 if (tolerance > 0.0)
1834 if (!last_point && dsq <= tolsq)
1842 if (memcmp((
char*)pt, (
char*)last, pt_size) == 0)
1850 if (last_point && n_points_out > 1 && tolerance > 0.0 && dsq <= tolsq)
1853 p_to = (
char*)p_to - pt_size;
1858 memcpy(p_to, pt, pt_size);
1860 p_to = (
char*)p_to + pt_size;
1875 uint32_t split = it_first;
1876 if ((it_first - it_last) < 2)
1885 for (uint32_t itk = it_first + 1; itk < it_last; itk++)
1889 if (distance_sqr > max_distance_sqr)
1892 max_distance_sqr = distance_sqr;
1899 double ba_x = (B->
x - A->
x);
1900 double ba_y = (B->
y - A->
y);
1901 double ab_length_sqr = (ba_x * ba_x + ba_y * ba_y);
1904 max_distance_sqr *= ab_length_sqr;
1905 for (uint32_t itk = it_first + 1; itk < it_last; itk++)
1908 double distance_sqr;
1909 double ca_x = (C->
x - A->
x);
1910 double ca_y = (C->
y - A->
y);
1911 double dot_ac_ab = (ca_x * ba_x + ca_y * ba_y);
1913 if (dot_ac_ab <= 0.0)
1917 else if (dot_ac_ab >= ab_length_sqr)
1923 double s_numerator = ca_x * ba_y - ca_y * ba_x;
1924 distance_sqr = s_numerator * s_numerator;
1927 if (distance_sqr > max_distance_sqr)
1930 max_distance_sqr = distance_sqr;
1940 uint32_t kept_it = 0;
1941 uint32_t last_it = pa->
npoints - 1;
1945 for (uint32_t i = 1; i < last_it; i++)
1950 double ba_x = next_pt->
x - kept_pt->
x;
1951 double ba_y = next_pt->
y - kept_pt->
y;
1952 double ab_length_sqr = ba_x * ba_x + ba_y * ba_y;
1954 double ca_x = curr_pt->
x - kept_pt->
x;
1955 double ca_y = curr_pt->
y - kept_pt->
y;
1956 double dot_ac_ab = ca_x * ba_x + ca_y * ba_y;
1957 double s_numerator = ca_x * ba_y - ca_y * ba_x;
1959 if (dot_ac_ab < 0.0 || dot_ac_ab > ab_length_sqr || s_numerator != 0)
1972 if (kept_it != last_it)
1986 if (tolerance == 0 && minpts <= 2)
2004 uint32_t *iterator_stack =
lwalloc(
sizeof(uint32_t) * pa->
npoints);
2005 iterator_stack[0] = 0;
2006 uint32_t iterator_stack_size = 1;
2008 uint32_t it_first = 0;
2009 uint32_t it_last = pa->
npoints - 1;
2011 const double tolerance_sqr = tolerance * tolerance;
2013 double it_tol = keptn >= minpts ? tolerance_sqr : -1.0;
2015 while (iterator_stack_size)
2018 if (split == it_first)
2021 it_last = iterator_stack[--iterator_stack_size];
2028 iterator_stack[iterator_stack_size++] = it_last;
2030 it_tol = keptn >= minpts ? tolerance_sqr : -1.0;
2045 else if (pa->
npoints != keptn)
2047 for (uint32_t i = 1; i < pa->
npoints; i++)
2081 lwerror(
"arc point array with even number of points");
2085 for ( i=2; i < pts->
npoints; i += 2 )
2106 if ( pts->
npoints < 2 )
return 0.0;
2110 for ( i=1; i < pts->
npoints; i++ )
2114 dist += sqrt( ((frm->
x - to->
x)*(frm->
x - to->
x)) +
2115 ((frm->
y - to->
y)*(frm->
y - to->
y)) );
2134 if ( pts->
npoints < 2 )
return 0.0;
2140 for ( i=1; i < pts->
npoints; i++ )
2143 dist += sqrt( ((frm.
x - to.
x)*(frm.
x - to.
x)) +
2144 ((frm.
y - to.
y)*(frm.
y - to.
y)) +
2145 ((frm.
z - to.
z)*(frm.
z - to.
z)) );
2161 for (uint32_t i = 0; i < pa->
npoints; i++)
2174 for (uint32_t i = 0; i < pa->
npoints; i++)
2190 static int gluInvertMatrix(
const double *m,
double *invOut)
2192 double inv[16],
det;
2195 inv[0] = m[5] * m[10] * m[15] -
2196 m[5] * m[11] * m[14] -
2197 m[9] * m[6] * m[15] +
2198 m[9] * m[7] * m[14] +
2199 m[13] * m[6] * m[11] -
2200 m[13] * m[7] * m[10];
2202 inv[4] = -m[4] * m[10] * m[15] +
2203 m[4] * m[11] * m[14] +
2204 m[8] * m[6] * m[15] -
2205 m[8] * m[7] * m[14] -
2206 m[12] * m[6] * m[11] +
2207 m[12] * m[7] * m[10];
2209 inv[8] = m[4] * m[9] * m[15] -
2210 m[4] * m[11] * m[13] -
2211 m[8] * m[5] * m[15] +
2212 m[8] * m[7] * m[13] +
2213 m[12] * m[5] * m[11] -
2214 m[12] * m[7] * m[9];
2216 inv[12] = -m[4] * m[9] * m[14] +
2217 m[4] * m[10] * m[13] +
2218 m[8] * m[5] * m[14] -
2219 m[8] * m[6] * m[13] -
2220 m[12] * m[5] * m[10] +
2221 m[12] * m[6] * m[9];
2223 inv[1] = -m[1] * m[10] * m[15] +
2224 m[1] * m[11] * m[14] +
2225 m[9] * m[2] * m[15] -
2226 m[9] * m[3] * m[14] -
2227 m[13] * m[2] * m[11] +
2228 m[13] * m[3] * m[10];
2230 inv[5] = m[0] * m[10] * m[15] -
2231 m[0] * m[11] * m[14] -
2232 m[8] * m[2] * m[15] +
2233 m[8] * m[3] * m[14] +
2234 m[12] * m[2] * m[11] -
2235 m[12] * m[3] * m[10];
2237 inv[9] = -m[0] * m[9] * m[15] +
2238 m[0] * m[11] * m[13] +
2239 m[8] * m[1] * m[15] -
2240 m[8] * m[3] * m[13] -
2241 m[12] * m[1] * m[11] +
2242 m[12] * m[3] * m[9];
2244 inv[13] = m[0] * m[9] * m[14] -
2245 m[0] * m[10] * m[13] -
2246 m[8] * m[1] * m[14] +
2247 m[8] * m[2] * m[13] +
2248 m[12] * m[1] * m[10] -
2249 m[12] * m[2] * m[9];
2251 inv[2] = m[1] * m[6] * m[15] -
2252 m[1] * m[7] * m[14] -
2253 m[5] * m[2] * m[15] +
2254 m[5] * m[3] * m[14] +
2255 m[13] * m[2] * m[7] -
2256 m[13] * m[3] * m[6];
2258 inv[6] = -m[0] * m[6] * m[15] +
2259 m[0] * m[7] * m[14] +
2260 m[4] * m[2] * m[15] -
2261 m[4] * m[3] * m[14] -
2262 m[12] * m[2] * m[7] +
2263 m[12] * m[3] * m[6];
2265 inv[10] = m[0] * m[5] * m[15] -
2266 m[0] * m[7] * m[13] -
2267 m[4] * m[1] * m[15] +
2268 m[4] * m[3] * m[13] +
2269 m[12] * m[1] * m[7] -
2270 m[12] * m[3] * m[5];
2272 inv[14] = -m[0] * m[5] * m[14] +
2273 m[0] * m[6] * m[13] +
2274 m[4] * m[1] * m[14] -
2275 m[4] * m[2] * m[13] -
2276 m[12] * m[1] * m[6] +
2277 m[12] * m[2] * m[5];
2279 inv[3] = -m[1] * m[6] * m[11] +
2280 m[1] * m[7] * m[10] +
2281 m[5] * m[2] * m[11] -
2282 m[5] * m[3] * m[10] -
2283 m[9] * m[2] * m[7] +
2286 inv[7] = m[0] * m[6] * m[11] -
2287 m[0] * m[7] * m[10] -
2288 m[4] * m[2] * m[11] +
2289 m[4] * m[3] * m[10] +
2290 m[8] * m[2] * m[7] -
2293 inv[11] = -m[0] * m[5] * m[11] +
2294 m[0] * m[7] * m[9] +
2295 m[4] * m[1] * m[11] -
2296 m[4] * m[3] * m[9] -
2297 m[8] * m[1] * m[7] +
2300 inv[15] = m[0] * m[5] * m[10] -
2301 m[0] * m[6] * m[9] -
2302 m[4] * m[1] * m[10] +
2303 m[4] * m[2] * m[9] +
2304 m[8] * m[1] * m[6] -
2307 det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
2314 for (i = 0; i < 16; i++)
2315 invOut[i] = inv[i] *
det;
2329 LWDEBUG(3,
"ptarray_scale start");
2339 LWDEBUG(3,
"ptarray_scale end");
2362 double x,
y, z = 0, m = 0;
2367 for (uint32_t i = 0; i < pa->
npoints; i++)
2378 if (grid->
xsize > 0)
2381 if (grid->
ysize > 0)
2386 if (has_z && grid->
zsize > 0)
2390 if (has_m && grid->
msize > 0)
2400 if (p_out && p_out->
x ==
x && p_out->
y ==
y && (ndims > 2 ? p_out->
z == z : 1) &&
2401 (ndims > 3 ? p_out->
m == m : 1))
2425 for ( i = 0; i < pa->
npoints; i++ )
2452 lwerror(
"ptarray_scroll_in_place: input POINTARRAY is not closed");
2460 for ( it = 0; it < pa->
npoints; ++it )
2471 lwerror(
"ptarray_scroll_in_place: input POINTARRAY does not contain the given point");
int gbox_contains_point2d(const GBOX *g, const POINT2D *p)
int lw_arc_calculate_gbox_cartesian_2d(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, GBOX *gbox)
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F)
Find interpolation point I between point A and point B so that the len(AI) == len(AB)*F and I falls o...
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
#define FLAGS_GET_READONLY(flags)
#define FLAGS_GET_Z(flags)
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
void * lwrealloc(void *mem, size_t size)
#define FLAGS_NDIMS(flags)
#define FLAGS_GET_M(flags)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
double distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
#define FLAGS_GET_ZM(flags)
void * lwalloc(size_t size)
#define FLAGS_SET_READONLY(flags, value)
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
#define LW_TRUE
Return types for functions with status returns.
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
enum LWORD_T LWORD
Ordinate names.
#define LW_INSIDE
Constants for point-in-polygon return values.
double lw_arc_length(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns the length of a circular arc segment.
int lw_pt_on_segment(const POINT2D *A1, const POINT2D *A2, const POINT2D *P)
#define LW_ON_INTERRUPT(x)
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
int lw_arc_side(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *Q)
int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2)
Returns true if P is between A1/A2.
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
int lw_arc_is_pt(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if arc A is actually a point (all vertices are the same) .
int lw_pt_in_arc(const POINT2D *P, const POINT2D *A1, const POINT2D *A2, const POINT2D *A3)
Returns true if P is on the same side of the plane partition defined by A1/A3 as A2 is.
int p2d_same(const POINT2D *p1, const POINT2D *p2)
static double det(double m00, double m01, double m10, double m11)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
static double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
static size_t ptarray_point_size(const POINTARRAY *pa)
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
POINTARRAY * ptarray_force_dims(const POINTARRAY *pa, int hasz, int hasm, double zval, double mval)
static uint32_t ptarray_dp_findsplit_in_place(const POINTARRAY *pts, uint32_t it_first, uint32_t it_last, double max_distance_sqr)
POINTARRAY * ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist)
Build a new POINTARRAY, but on top of someone else's ordinate array.
int ptarray_remove_point(POINTARRAY *pa, uint32_t where)
Remove a point from an existing POINTARRAY.
void ptarray_longitude_shift(POINTARRAY *pa)
Longitude shift for a pointarray.
POINTARRAY * ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist)
Construct a new POINTARRAY, copying in the data from ptlist.
int ptarray_closest_segment_2d(const POINTARRAY *pa, const POINT2D *qp, double *dist)
POINTARRAY * ptarray_clone(const POINTARRAY *in)
Clone a POINTARRAY object.
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
void ptarray_reverse_in_place(POINTARRAY *pa)
int ptarray_closest_vertex_2d(const POINTARRAY *pa, const POINT2D *qp, double *dist)
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
int ptarray_is_closed_2d(const POINTARRAY *in)
int ptarray_is_closed_z(const POINTARRAY *in)
int ptarray_raycast_intersections(const POINTARRAY *pa, const POINT2D *p, int *on_boundary)
double ptarray_length(const POINTARRAY *pts)
Find the 3d/2d length of the given POINTARRAY (depending on its dimensionality)
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
POINTARRAY * ptarray_addPoint(const POINTARRAY *pa, uint8_t *p, size_t pdims, uint32_t where)
Add a point in a pointarray.
void closest_point_on_segment(const POINT4D *p, const POINT4D *A, const POINT4D *B, POINT4D *ret)
int ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
int ptarray_is_closed(const POINTARRAY *in)
Check for ring closure using whatever dimensionality is declared on the pointarray.
POINTARRAY * ptarray_clone_deep(const POINTARRAY *in)
Deep clone a pointarray (also clones serialized pointlist)
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
void ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
Snap to grid.
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2)
int ptarray_is_closed_3d(const POINTARRAY *in)
void ptarray_remove_repeated_points_in_place(POINTARRAY *pa, double tolerance, uint32_t min_points)
int ptarrayarc_raycast_intersections(const POINTARRAY *pa, const POINT2D *p, int *on_boundary)
POINTARRAY * ptarray_removePoint(POINTARRAY *pa, uint32_t which)
Remove a point from a pointarray.
int ptarray_scroll_in_place(POINTARRAY *pa, const POINT4D *pt)
void ptarray_simplify_in_place(POINTARRAY *pa, double tolerance, uint32_t minpts)
int ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, uint32_t where)
Insert a point into an existing POINTARRAY.
double ptarray_arc_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY, using circular arc interpolation between each coordinate ...
POINTARRAY * ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance)
static int circle_raycast_intersections(const POINT2D *center, double radius, double ray, POINT2D *i0, POINT2D *i1)
Calculates the intersection points of a circle and a horizontal line.
void ptarray_affine(POINTARRAY *pa, const AFFINE *a)
Affine transform a pointarray.
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
The following is based on the "Fast Winding Number Inclusion of a Point in a Polygon" algorithm by Da...
int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
void ptarray_free(POINTARRAY *pa)
static void ptarray_simplify_in_place_tolerance0(POINTARRAY *pa)
int ptarray_isccw(const POINTARRAY *pa)
int ptarray_has_z(const POINTARRAY *pa)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int repeated_points)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
void ptarray_scale(POINTARRAY *pa, const POINT4D *fact)
WARNING, make sure you send in only 16-member double arrays or obviously things will go pear-shaped f...
static POINTARRAY * ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints)
void ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
int ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox)
POINTARRAY * ptarray_substring(POINTARRAY *ipa, double from, double to, double tolerance)
@d1 start location (distance from start / total distance) @d2 end location (distance from start / tot...
POINTARRAY * ptarray_merge(POINTARRAY *pa1, POINTARRAY *pa2)
Merge two given POINTARRAY and returns a pointer on the new aggregate one.
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
int ptarray_has_m(const POINTARRAY *pa)
POINTARRAY * ptarray_segmentize2d(const POINTARRAY *ipa, double dist)
Returns a modified POINTARRAY so that no segment is longer than the given distance (computed using 2d...
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *p4d, double *mindistout, POINT4D *proj4d)
uint8_t * serialized_pointlist