Boost logo

Geometry :

Subject: Re: [geometry] boost::geometry::equals and the ring model
From: Alexandre Pretyman (alexandre.pretyman_at_[hidden])
Date: 2015-04-04 23:10:49


Hi Menelaos,

Thank you for the information.

It stepped into the code for equality for rings using the cartesian
coordinate system and realized that the area was used for a trivial check,
as if they had a different area, they must be different shapes, this is
very possibly done before since the algorithm is Theta(n) for the number of
coordinates. If the area is the same, then a copy of the ring is made
without duplicate points and with only points that change direction of the
segments, which is what I believe this is what you mean by “geometric
equality”. The sort is done in average O(n log n) time, and then both set
of points “geometrically equal” are compared for equality comparing each
element.

To make the equals work, I “cheated” (because I am sure this is not
correct) and added the following code before calling
boost::geometry::equals:

#include <boost/geometry/strategies/cartesian/area_surveyor.hpp>

*namespace *boost { *namespace *geometry {

*namespace *strategy { *namespace *area {

*namespace *services
{
    *template *<*typename *Point>
    *struct *default_strategy<*geographic_tag*, Point>
    {
        *typedef *strategy::area::surveyor<Point> type;
    };
}
}}
}}

but I guess the area must not make much sense. For my trivial case, at
least for now, it seems enough.

Thanks once again, I wouldn’t know where to start without your help,

Alexandre Pretyman

On 2 April 2015 at 01:59, Menelaos Karavelas <menelaos.karavelas_at_[hidden]>
wrote:

> Hi Alexandre.
>
>
> On 02/04/2015 07:02 πμ, Alexandre Pretyman wrote:
>
> Hello list!
>
> I am having trouble using the equals method on a ring model, maybe I
> missed something in the documentation. Can you guys give me some directions
> on how can I fix the error below?
>
> I have the following code (also attached):
>
> using point = bg::model::point<double, 2,
> bg::cs::geographic<bg::degree>>;
> using ring = bg::model::ring<point, true, true>;
> ring r1;
> r1.push_back(bg::make<point>(0, 0));
> r1.push_back(bg::make<point>(0, 1));
> r1.push_back(bg::make<point>(1, 1));
> r1.push_back(bg::make<point>(1, 0));
> r1.push_back(bg::make<point>(0, 0));
> ring r2;
> r2.push_back(bg::make<point>(0, 0));
> r2.push_back(bg::make<point>(0, 1));
> r2.push_back(bg::make<point>(1, 1));
> r2.push_back(bg::make<point>(1, 0));
> r2.push_back(bg::make<point>(0, 0));
> // equals with ring doesn't work ;(
> std::cout << "ring equals:" << bg::equals(r1, r2) << std::endl;
>
> And it fails with the following message (full log also attached):
>
> n file included from /usr/include/boost/mpl/aux_/na_assert.hpp:23:0,
> from /usr/include/boost/mpl/arg.hpp:25,
> from /usr/include/boost/mpl/placeholders.hpp:24,
> from /usr/include/boost/mpl/apply.hpp:24,
> from /usr/include/boost/mpl/for_each.hpp:19,
> from /usr/include/boost/test/unit_test_suite_impl.hpp:29,
> from /usr/include/boost/test/unit_test_suite.hpp:19,
> from /usr/include/boost/test/unit_test.hpp:20,
> from
> /unit-tests/geometry-equals/cxx/geometry-equals.cxx:3:
> /usr/include/boost/geometry/strategies/area.hpp: In instantiation of
> ‘struct
> boost::geometry::strategy::area::services::default_strategy<boost::geometry::geographic_tag,
> boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> > >’:
> /usr/include/boost/geometry/strategies/default_area_result.hpp:42:17:
> required from ‘struct
> boost::geometry::default_area_result<boost::geometry::model::ring<boost::geometry::model::point<double,
> 2ul, boost::geometry::cs::geographic<boost::geometry::degree> >, true,
> true> >’
> /usr/include/boost/geometry/algorithms/area.hpp:266:53: required by
> substitution of ‘template<class Geometry> typename
> boost::geometry::default_area_result<Geometry>::type
> boost::geometry::area(const Geometry&) [with Geometry =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>]’
> /usr/include/boost/geometry/algorithms/equals.hpp:122:41: required from
> ‘static bool boost::geometry::detail::equals::area_check::apply(const
> Geometry1&, const Geometry2&) [with Geometry1 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>;
> Geometry2 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>]’
> /usr/include/boost/geometry/algorithms/equals.hpp:146:55: required from
> ‘static bool
> boost::geometry::detail::equals::equals_by_collection<TrivialCheck>::apply(const
> Geometry1&, const Geometry2&) [with Geometry1 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>;
> Geometry2 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>;
> TrivialCheck = boost::geometry::detail::equals::area_check]’
> /usr/include/boost/geometry/algorithms/equals.hpp:344:52: required from
> ‘static bool boost::geometry::resolve_variant::equals<Geometry1,
> Geometry2>::apply(const Geometry1&, const Geometry2&) [with Geometry1 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>;
> Geometry2 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>]’
> /usr/include/boost/geometry/algorithms/equals.hpp:460:55: required from
> ‘bool boost::geometry::equals(const Geometry1&, const Geometry2&) [with
> Geometry1 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>;
> Geometry2 =
> boost::geometry::model::ring<boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >, true, true>]’
> /unit-tests/geometry-equals/cxx/geometry-equals.cxx:44:51: required from
> here
> /usr/include/boost/geometry/strategies/area.hpp:37:5: error: no matching
> function for call to ‘assertion_failed(mpl_::failed************
> (boost::geometry::strategy::area::services::default_strategy<boost::geometry::geographic_tag,
> boost::geometry::model::point<double, 2ul,
> boost::geometry::cs::geographic<boost::geometry::degree> >
> >::NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE::************)(mpl_::assert_::types<boost::geometry::model::point<double,
> 2ul, boost::geometry::cs::geographic<boost::geometry::degree> >, mpl_::na,
> mpl_::na, mpl_::na>))’
> BOOST_MPL_ASSERT_MSG
>
>
> I have not looked at the code, but I think this is what is happening: area
> (which is required apparently for the equality testing) is not yet
> implemented for points in the geographic coordinate system.
> Please bear in mind that bg::equals is testing for geometric equality
> (i.e., whether two point sets coincide), which means that simply checking
> the vertices of a ring for equality is not really enough, as you might
> define the same ring in many different ways.
>
> Best,
>
> - m.
>
> Thanks for any insight!
> --
> Alexandre Pretyman
>
>
> _______________________________________________
> Geometry mailing listGeometry_at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/geometry
>
>
>
> _______________________________________________
> Geometry mailing list
> Geometry_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/geometry
>
>

-- 
Alexandre Pretyman


Geometry list run by mateusz at loskot.net