[geos-devel] Geometry/Rectangle Intersection, line merging ?

Sandro Santilli strk at keybit.net
Tue Sep 9 06:06:25 PDT 2014


On Tue, Sep 09, 2014 at 03:00:44PM +0300, Mika Heiskanen wrote:
> On 09/09/2014 01:48 PM, Sandro Santilli wrote:
> >RE: rectangle intersection (#699)
> >
> >I've plugged the leak and compared the result of Geometry::intersection()
> >and RectangleIntersection. One difference is about the linemerge operation
> >happening in the RectangleIntersection class, that is a line going outside
> >and then back inside the clipping rectangle gets merged by
> >RectangleIntersection while it is not by standard intersection.
> >
> >The tests you provided expect the merging to happen, so if I drop the merging
> >those tests are going to fail. What's the rationale for that additional
> >operation ?
> 
> I assume you are referring to these comments:
> 
>  * Sample clip with a rectangle 0,0 --> 10,10 without reconnecting:
>  *
>  *   Input:   POLYGON ((5 10,0 0,10 0,5 10))
>  *   Output:  MULTILINESTRING ((5 10,0 0),(10 0,5 10))
>  *   Desired: LINESTRING (10 0,5 10,0 0)
> 
> If you recall, we wrote the algorithm for rendering. In this case if we
> do not reconnect the two linestrings line-join behaviour will be broken
> during rendering.

But this is not the ST_Intersection equivalent operation.
That one would output POLYGON from a POLYGON input, while it would
output LINESTRING if the input was a LINESTRING.

One failing test (when using ST_Intersection) is this one
(number 87 in the unit test):

    // triangle corner at left edge
    Input:   LINESTRING (3 3,0 6,3 9)
    Desired: LINESTRING (3 3,0 6,3 9)

ST_Intersection outputs this instead:

    Output:  MULTILINESTRING ((0 6, 3 9), (0 6, 3 3))

I guess line-join behavior would be broken also if the vertex was
slightly off the rectangle, if the join style would be visible inside
of it. It's tipical to use a somewhat larger clipping box to avoid these
issues (for rendering purposes).

Right now I'm trying to see if it's possible to transparently use
the RectangleIntersection clip from Geometry::intersection(), when one
of the operands is a Rectangle.

On a closer look the RectangleIntersection output is not even due to
clipping but rather to RectangleIntersection::clip_linestring_parts
considering "boundary" position the same as "internal" in the "else"
branch around line 248. There's actually no "Boundary" position known
in the Position enum in Rectangle.h, maybe should be added...

--strk;

 ()  ASCII ribbon campaign  --  Keep it simple !
 /\  http://strk.keybit.net/rants/ascii_mails.txt  


More information about the geos-devel mailing list