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

Introduce Segment Intersection Primitive #778

Merged
merged 16 commits into from
Nov 15, 2022

Conversation

isVoid
Copy link
Contributor

@isVoid isVoid commented Nov 3, 2022

Description

Closes #763 , this PR introduces device primitive for segment-segment intersection.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@github-actions github-actions bot added cmake Related to CMake code or build configuration libcuspatial Relates to the cuSpatial C++ library labels Nov 3, 2022
@isVoid isVoid added 2 - In Progress Currenty a work in progress non-breaking Non-breaking change feature request New feature or request labels Nov 3, 2022
@isVoid isVoid marked this pull request as ready for review November 4, 2022 22:34
@isVoid isVoid requested review from a team as code owners November 4, 2022 22:34
@isVoid isVoid added this to the DE-9IM milestone Nov 4, 2022
@isVoid isVoid requested review from harrism and removed request for trxcllnt and jrhemstad November 4, 2022 22:34
@isVoid isVoid added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currenty a work in progress labels Nov 4, 2022
Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

The utility itself looks good. Some doc / utility suggestions.

cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
cpp/include/cuspatial/detail/utility/linestring.cuh Outdated Show resolved Hide resolved
cpp/include/cuspatial/traits.hpp Outdated Show resolved Hide resolved
@isVoid isVoid self-assigned this Nov 8, 2022
@isVoid isVoid requested a review from harrism November 8, 2022 23:22
Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

Docs only.

I do worry that operator< for vec_2d could be misused. The operators assume the vec_2ds are points. Using them on vectors might not do what users expect, since comparing points/vectors with < is not a canonical operation (one might expect to compare vectors by magnitude, for example). I don't expect you to change anything, I'm just making a note of this thought.

cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
cpp/include/cuspatial/vec_2d.hpp Outdated Show resolved Hide resolved
@isVoid
Copy link
Contributor Author

isVoid commented Nov 8, 2022

operator< for vec_2d could be misused

This definition is giving a total order to 2d points on a plane. Effectively lower left points are less than upper right points. cuSpatial currently still mixes up the concept of points and vectors and uses a single structure for both, which is problematic. I think we should introduce two separate type for these two distinct concepts.

Still, there might be other ways how user want to sort points on a plane - I believe user can provide custom comparator for sort if needed.

@isVoid isVoid requested a review from harrism November 8, 2022 23:42
@isVoid
Copy link
Contributor Author

isVoid commented Nov 11, 2022

@harrism as discussed, I added additional code to condition large floating points.

// Must be on the same line, test if intersect
if ((a < c && c < b) || (a < d && d < b)) {
// Compute smallest interval between the segments
auto a_ = a, b_ = b, c_ = c, d_ = d;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just making this function pass a, b, c, d by value instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the code is cleaner using pass by value.

* @brief Greater than operator for two 2D points.
*/
template <typename T>
bool CUSPATIAL_HOST_DEVICE operator>(vec_2d<T> const& lhs, vec_2d<T> const& rhs)
Copy link
Contributor

Choose a reason for hiding this comment

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

You could improve your compile time by making these operators hidden friends: https://www.justsoftwaresolutions.co.uk/cplusplus/hidden-friends.html

Copy link
Contributor Author

@isVoid isVoid Nov 12, 2022

Choose a reason for hiding this comment

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

Moved. I think a 2nd benefit of this is that, as @harrism pointed out, that the definition of these comparators is not canonical, and we want to avoid users who choose to use type convertible to vec_2d to misuse these operator. Making them hidden friend requires user to explicitly cast them before they can access these operators.

@isVoid
Copy link
Contributor Author

isVoid commented Nov 12, 2022

I have also replaced floating point == in linestring.cuh with the new ulp based util.

@harrism harrism added c++ libcuspatial Relates to the cuSpatial C++ library and removed libcuspatial Relates to the cuSpatial C++ library c++ labels Nov 14, 2022
@isVoid
Copy link
Contributor Author

isVoid commented Nov 15, 2022

I think the concern I raised in this comment is relevant. As I have found out in the on going intersection feature, using a custom struct can help make accessing element's type easier.

@isVoid
Copy link
Contributor Author

isVoid commented Nov 15, 2022

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 48aac76 into rapidsai:branch-22.12 Nov 15, 2022
rapids-bot bot pushed a commit that referenced this pull request Nov 21, 2022
#778 introduced segment intersection primitive, but there's a subtle bug in the code. This PR fixes that.

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - H. Thomson Comer (https://github.com/thomcom)
  - Mark Harris (https://github.com/harrism)

URL: #808
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team cmake Related to CMake code or build configuration feature request New feature or request libcuspatial Relates to the cuSpatial C++ library non-breaking Non-breaking change
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Device primitive for segment-segment intersection
3 participants