Skip to content

Symmetrize calls to intersects() and distance()#1329

Merged
aprokop merged 9 commits intoarborx:masterfrom
aprokop:symmetrize_intersects
Feb 27, 2026
Merged

Symmetrize calls to intersects() and distance()#1329
aprokop merged 9 commits intoarborx:masterfrom
aprokop:symmetrize_intersects

Conversation

@aprokop
Copy link
Contributor

@aprokop aprokop commented Jan 17, 2026

Currently, we are missing the following symmetric version of the calls:

struct intersects<PointTag, TetrahedronTag, Point, Tetrahedron>;
struct intersects<PointTag, TriangleTag, Point, Triangle>;
struct intersects<SphereTag, BoxTag, Sphere, Box>;
struct distance<PointTag, SegmentTag, Point, Segment>;
struct distance<PointTag, TriangleTag, Point, Triangle>;

It is apparently pretty hard for me to remember to provide the second version every time I add a new intersection or distance algorithm.

Thus, this PR automatically reverses the arguments if it detects that the specialization is missing arguments in the original order. This should take care of it fully.

@aprokop aprokop added the refactoring Code reorganization label Jan 17, 2026
@aprokop aprokop requested a review from dalg24 January 19, 2026 00:46
}

return ArborX::distance(geometry1, geometry2);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you consider defining a macro instead

#define ARBORX_TEST_DISTANCE_EQ(geometry1, geometry2, distance) \
BOOST_TEST(ArborX::distance(geometry1, geometry2) == distance);
BOOST_TEST(ArborX::distance(geometry1, geometry2) == ArborX::distance(geometry2, geometry1))

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 don't see any advantage to macros. In addition, it would require changing a ton of code to wrap things into parenthesis to be able to call the macro.

Copy link
Contributor

Choose a reason for hiding this comment

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

Quality of the error logging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will currently fail like

check sym_distance(Point{0.5, 0.5, 0.5}, box) == 1 has failed [0 != 1]

There's minimal difference with the original failure of

check distance(Point{0.5, 0.5, 0.5}, box) == 1 has failed [0 != 1]

Copy link
Contributor

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

I slightly prefer the macro approach but I can live with the function.
distance is fine with a negative value to report the issue but intersects needs update

if (ArborX::intersects(geometry1, geometry2) !=
// NOLINTNEXTLINE(readability-suspicious-call-argument)
ArborX::intersects(geometry2, geometry1))
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

How to we signify that the intersects(a, b) does not match intersects(b, a)?
We would need to report error by some other channel like abort or throw an exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct in that the function signature does not have a proper error channel. I don't think it is a big deal, though.

Copy link
Contributor

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

Fine

@aprokop aprokop merged commit c62ab9f into arborx:master Feb 27, 2026
2 checks passed
@aprokop aprokop deleted the symmetrize_intersects branch February 27, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Code reorganization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants