POINT2D pt;
POINTARRAY* pa1;
POINTARRAY* pa2;
+ double vstol; /* vertex snap tolerance */
/* Possible outcomes:
*
}
/* There is a real intersection, let's get two substrings */
-
- pa1 = ptarray_substring(lwline_in->points, 0, loc);
- pa2 = ptarray_substring(lwline_in->points, loc, 1);
+ vstol = 1e-14; /* TODO: take this as parameter ? */
+ pa1 = ptarray_substring(lwline_in->points, 0, loc, vstol);
+ pa2 = ptarray_substring(lwline_in->points, loc, 1, vstol);
/* NOTE: I've seen empty pointarrays with loc != 0 and loc != 1 */
if ( pa1->npoints == 0 || pa2->npoints == 0 ) {
}
POINTARRAY *
-ptarray_substring(POINTARRAY *ipa, double from, double to)
+ptarray_substring(POINTARRAY *ipa, double from, double to, double tolerance)
{
POINTARRAY *dpa;
POINT4D pt;
LWDEBUG(3, " Before start");
- /*
- * Didn't reach the 'from' point,
- * nothing to do
- */
- if ( from > tlength + slength ) goto END;
-
- else if ( from == tlength + slength )
+ if ( fabs ( from - ( tlength + slength ) ) <= tolerance )
{
LWDEBUG(3, " Second point is our start");
/*
* Second point is our start
*/
- ptarray_append_point(dpa, &p2, LW_TRUE);
+ ptarray_append_point(dpa, &p2, LW_FALSE);
state=1; /* we're inside now */
goto END;
}
- else if ( from == tlength )
+ else if ( fabs(from - tlength) <= tolerance )
{
LWDEBUG(3, " First point is our start");
/*
* First point is our start
*/
- ptarray_append_point(dpa, &p1, LW_TRUE);
+ ptarray_append_point(dpa, &p1, LW_FALSE);
/*
* We're inside now, but will check
state=1;
}
+ /*
+ * Didn't reach the 'from' point,
+ * nothing to do
+ */
+ else if ( from > tlength + slength ) goto END;
+
else /* tlength < from < tlength+slength */
{
* second point
*/
dseg = (from - tlength) / slength;
+
interpolate_point4d(&p1, &p2, &pt, dseg);
- ptarray_append_point(dpa, &pt, LW_TRUE);
+ ptarray_append_point(dpa, &pt, LW_FALSE);
/*
* We're inside now, but will check
LWDEBUG(3, " Inside");
- /*
- * Didn't reach the 'end' point,
- * just copy second point
- */
- if ( to > tlength + slength )
- {
- ptarray_append_point(dpa, &p2, LW_FALSE);
- goto END;
- }
-
/*
* 'to' point is our second point.
*/
- else if ( to == tlength + slength )
+ if ( fabs(to - ( tlength + slength ) ) <= tolerance )
{
LWDEBUG(3, " Second point is our end");
* 'to' point is our first point.
* (should only happen if 'to' is 0)
*/
- else if ( to == tlength )
+ else if ( fabs(to - tlength) <= tolerance )
{
LWDEBUG(3, " First point is our end");
break; /* substring complete */
}
+ /*
+ * Didn't reach the 'end' point,
+ * just copy second point
+ */
+ else if ( to > tlength + slength )
+ {
+ ptarray_append_point(dpa, &p2, LW_FALSE);
+ goto END;
+ }
+
/*
* 'to' point falls on this segment
* Interpolate and break.
ipa = iline->points;
- opa = ptarray_substring(ipa, from, to);
+ opa = ptarray_substring(ipa, from, to, 0);
if ( opa->npoints == 1 ) /* Point returned */
olwgeom = (LWGEOM *)lwpoint_construct(iline->srid, NULL, opa);
subto = (to - minprop) / (maxprop - minprop);
- opa = ptarray_substring(subline->points, subfrom, subto);
+ opa = ptarray_substring(subline->points, subfrom, subto, 0);
if ( opa && opa->npoints > 0 )
{
if ( opa->npoints == 1 ) /* Point returned */