Boost logo

Geometry :

Subject: Re: [geometry] error in touches()
From: Barend Gehrels (barend_at_[hidden])
Date: 2013-09-24 09:28:05


Hi Adam,

On 24-9-2013 14:20, Adam Wulkiewicz wrote:
> Adam Wulkiewicz wrote:
>> And diving into the touches() implementation I discovered that there
>> is a bug, or am I missing something? E.g. 2 bottom tests fails.
>>
>> template <typename Geometry>
>> Geometry from_wkt(std::string const& wkt)
>> {
>> Geometry res;
>> boost::geometry::read_wkt(wkt, res);
>> return res;
>> }
>>
>> typedef bgm::point<float, 2, bg::cs::cartesian> Pt;
>> typedef bgm::polygon<Pt, false, false> P;
>>
>> BOOST_CHECK(!bg::touches(from_wkt<P>("POLYGON((1 1, 5 1, 5 5, 1
>> 5))"), from_wkt<P>("POLYGON((0 0, 9 0, 9 9, 0 9),(5 5,8 5,8 8,5
>> 8))"))); // OK
>> BOOST_CHECK(bg::touches(from_wkt<P>("POLYGON((0 0, 1 0, 1 1, 0 1))"),
>> from_wkt<P>("POLYGON((1 1, 9 1, 9 9, 1 9),(5 5,8 5,8 8,5 8))"))); //
>> FAIL
>> BOOST_CHECK(bg::touches(from_wkt<P>("POLYGON((0 0, 1 0, 1 5, 0 5))"),
>> from_wkt<P>("POLYGON((1 1, 9 1, 9 9, 1 9),(5 5,8 5,8 8,5 8))"))); //
>> FAIL
>>
>> In detail::touches::has_only_turns()
>> the condition it->has(detail::overlay::operation_intersection)
>> is true for all cases so the function returns false.
>>
>> Is it a bug or am I missing something? If it is a bug I may try to
>> fix it, after I figure out how get_turns() works.
>
> For CW rings and polygons it works, e.g. those tests are passed:
>
> typedef bgm::ring<Pt, true, false> RCW;
> typedef bgm::polygon<Pt, true, false> PCW;
>
> BOOST_CHECK(!bg::touches(from_wkt<PCW>("POLYGON((1 1, 1 5, 5 5, 5
> 1))"), from_wkt<PCW>("POLYGON((0 0, 0 9, 9 9, 9 0),(5 5,5 8,8 8,8
> 5))")));
> BOOST_CHECK(bg::touches(from_wkt<PCW>("POLYGON((0 0, 0 1, 1 1, 1
> 0))"), from_wkt<PCW>("POLYGON((1 1, 1 9, 9 9, 9 1),(5 5,5 8,8 8,8
> 5))")));
> BOOST_CHECK(bg::touches(from_wkt<PCW>("POLYGON((0 0, 0 5, 1 5, 1
> 0))"), from_wkt<PCW>("POLYGON((1 1, 1 9, 9 9, 9 1),(5 5,5 8,8 8,8
> 5))")));
> BOOST_CHECK(bg::touches(from_wkt<RCW>("POLYGON((0 0, 0 5, 1 5, 1
> 0))"), from_wkt<RCW>("POLYGON((1 1, 1 9, 9 9, 9 1))")));
> BOOST_CHECK(bg::touches(from_wkt<RCW>("POLYGON((0 0, 0 1, 1 1, 1
> 0))"), from_wkt<RCW>("POLYGON((1 1, 1 9, 9 9, 9 1))")));
>
> And after passing values based on the point_order of Geometries as
> Reversed1 and Reversed2 parameters of boost::geometry::get_turns<> the
> touches() for CCW polygons works as well. Something like in the
> attached patch.
> Do you think this solution is valid?

Thanks for spotting this. Yes this was probably unfinished. Can you fix
this?

W.r.t. your patch, looks OK but is duplicate code with overlay.hpp, last
part, do_reverse.

Regards, Barend


Geometry list run by mateusz at loskot.net