Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DynamicGeometry and GeometryCollection. #850

Merged
merged 22 commits into from Jun 3, 2021

Conversation

awulkiew
Copy link
Member

@awulkiew awulkiew commented May 17, 2021

After: #843

This PR adds DynamicGeometry and GeometryCollection and usage in several algorithms.

List of changes:

  • Added DynamicGeometry concept
    • Required specialization of traits::tag<> defining type as dynamic_geometry_tag
    • Required specialization of 1-parameter traits::visit<>
    • Required specialization of traits::geometry_types<>
    • Optional specialization of 2-parameter traits::visit<>
    • [mutable] Must be assignable from types specified in traits::geometry_types<>
  • Added GeometryCollection concept
    • Required specialization of traits::tag<> defining type as geometry_collection_tag
    • Required adaptation to ForwardRange concept
    • Optional specialization of traits::geometry_types<> (by default using traits::geometry_types<> for range_value<>::type)
    • Optional specialization of traits::iter_visit<> (by default calling traits::visit<> for range_value<>::type)
    • [mutable] Required specialization of traits::emplace_back<> allowing to add objects of types specified in traits::geometry_types<>
    • [mutable] Optional specialization of traits::clear<> (by default calling collection.clear())
    • May be recursive
  • Added adaptations of DynamicGeometry
    • boost::variant<>
    • boost::variant2::variant<>
    • boost::any<> (requires additional user specialization of traits::geometry_types<>)
    • std::variant<>
    • std::any<> (requires additional user specialization of traits::geometry_types<>)
  • Added GeometryCollection models
    • model::geometry_collection<>
  • Added concept checks for DynamicGeometry and GeometryCollection
    • added new util concepts::concept_type<> defining concept of Geometry in a generic way
    • refactored concepts::check(), dispatches replaced with concepts::concept_type<>
  • Added algorithms:
    • detail::visit()
    • detail::visit_breadth_first()
  • Added support for DynamicGeometry and GeometryCollection in:
    • append() (only DynamicGeometry)
    • area()
    • clear()
    • disjoint() (the algorithm for 2 GeometryCollections has quadratic complexity so should probably be refactored)
    • length()
    • read_wkt()
    • wkt()
    • comparable_distance_result<>
    • distance_result<>
  • Other
    • Added support for rvalue references to range value_type in traits::push_back and range::push_back to support move semantics (the support for rvalue reference for the Range itself should still be added in a different PR)
    • boost::variant workarounds previously implemented for VS2015 now works with all compilers #ifdef BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES (in various algorithms)

I'm open to suggestions.

@awulkiew awulkiew linked an issue May 17, 2021 that may be closed by this pull request
…t in several algorithms.

Also add basic support for GeometryCollection.
Copy link
Member

@mloskot mloskot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've skimmed the code trying to understand the core parts and nothing looks suspicious.
Nice feature!

@awulkiew
Copy link
Member Author

@mloskot Thanks for the review!

The thing that I don't like about it is the fact that traits::visit has to be specialized for a specific number of geometries, one or two. Do you have a different idea how this trait could be implemented to allow specialization for e.g. any number of arbitrary variants (potentially holding different geometries)?

Do you think that rvalue references should be handled in visit too?

Do you think visit should be able to return a value?

@mloskot
Copy link
Member

mloskot commented May 25, 2021

Do you have a different idea how this trait could be implemented to allow specialization for e.g. any number of arbitrary variants

My C++ is getting rusty, but it generally should be feasible (https://stackoverflow.com/q/24687026/151641 or https://bitbashing.io/std-visit.html), but I'm sure you've looked at the variadics.

Do you think that rvalue references should be handled in visit too?
Do you think visit should be able to return a value?

I think it is generally a good idea to keep interfaces aligned with the standard stuff, i.e. similar to std::visit

I wish I could be more helpful, but can't afford any experiments on my own right now.

Copy link
Collaborator

@barendgehrels barendgehrels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

I think at least some of the TODO's should be done, or rephrased, and some commented code can go or be uncommented, so I set this to Request changes for now, but apart from that, I'm fine.

include/boost/geometry/algorithms/append.hpp Show resolved Hide resolved
include/boost/geometry/algorithms/append.hpp Outdated Show resolved Hide resolved
include/boost/geometry/algorithms/area.hpp Outdated Show resolved Hide resolved
include/boost/geometry/geometries/concepts/check.hpp Outdated Show resolved Hide resolved
include/boost/geometry/geometries/geometry_collection.hpp Outdated Show resolved Hide resolved
Add support for rvalue references in visit traits and algorithms.
Move visit algorithms to detail namespace.
Rename visit_iterator trait to iter_visit.
Add tests for visit traits and algorithms.
Remove unneeded comments.
Remove unneeded comments.
Replace typedef with using.
Change names and formatting.
@awulkiew
Copy link
Member Author

@mloskot I added support for rvalue references because it is possible we'll want to move something inside visit. I didn't implement returning values though because:

  • in some cases the implementation would be complicated and still not 100% bulletproof, e.g. for boost::variant forcing to define return value as template argument of boost::static_visitor<>,
  • this would be a requirement for the users adapting their classes and this requirement would make this more complicated as well.

So I don't think it's worth it only to be able to save 2 lines of code now and then.

Add concepts::concept_type<> utility for generic concept definitions.

Replace tag dispatching in concepts::check() with
concepts::concept_type<>.
@awulkiew
Copy link
Member Author

@barendgehrels I made the PR more complete. I added the list of changes in the description.

…the compiler.

Variadic templates can be disabled in Boost.Variant by defining
BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES.

Also support DG and GC in:
- comparable_distance_result
- default_length_result
- distance_result
Copy link
Collaborator

@barendgehrels barendgehrels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

@vissarion vissarion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks and sorry for late reviewing, I am OK for merging.

include/boost/geometry/algorithms/append.hpp Outdated Show resolved Hide resolved
include/boost/geometry/algorithms/append.hpp Outdated Show resolved Hide resolved
include/boost/geometry/algorithms/append.hpp Outdated Show resolved Hide resolved
include/boost/geometry/algorithms/append.hpp Outdated Show resolved Hide resolved
test/algorithms/clear_multi.cpp Show resolved Hide resolved
test/algorithms/disjoint/test_disjoint.hpp Outdated Show resolved Hide resolved
@awulkiew
Copy link
Member Author

awulkiew commented Jun 3, 2021

Thanks for the reviews!

@awulkiew awulkiew merged commit e1571b3 into boostorg:develop Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: GeometryCollection, DynamicGeometry
4 participants