Skip to content

AABB_tree: Adding sphere primitive #9463

Open
soesau wants to merge 2 commits intoCGAL:mainfrom
soesau:AABB-Spheres_Primitive-GF
Open

AABB_tree: Adding sphere primitive #9463
soesau wants to merge 2 commits intoCGAL:mainfrom
soesau:AABB-Spheres_Primitive-GF

Conversation

@soesau
Copy link
Copy Markdown
Member

@soesau soesau commented May 5, 2026

Summary of Changes

Adding a primitive type allowing to create an AABBtree of Sphere_3.

Release Management

  • Affected package(s): AABB_tree

Copy link
Copy Markdown
Member

@lrineau lrineau left a comment

Choose a reason for hiding this comment

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

I know this is a work-in-progress. I have a few suggestions anyway.

Comment on lines +3288 to +3290
operator()(const typename K::Ray_3& ray,
const typename K::Point_3& query,
const K& k)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not change the indentation. It was correct.

Suggested change
operator()(const typename K::Ray_3& ray,
const typename K::Point_3& query,
const K& k)
operator()(const typename K::Ray_3& ray,
const typename K::Point_3& query,
const K& k)

Comment on lines +3300 to +3304
typename K::Point_3
operator()(const typename K::Sphere_3& sphere,
const typename K::Point_3& query,
const K& k)
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
typename K::Point_3
operator()(const typename K::Sphere_3& sphere,
const typename K::Point_3& query,
const K& k)
{
typename K::Point_3
operator()(const typename K::Sphere_3& sphere,
const typename K::Point_3& query,
const K& k)
{

Comment on lines +3305 to +3312
typename K::Construct_point_3 point = k.construct_point_3_object();
typename K::Compute_x_3 x = k.compute_x_3_object();
typename K::Compute_y_3 y = k.compute_y_3_object();
typename K::Compute_z_3 z = k.compute_z_3_object();
typename K::Construct_vector_3 vector = k.construct_vector_3_object();
typename K::Construct_center_3 center = k.construct_center_3_object();
typename K::Compute_squared_radius_3 squared_radius = k.compute_squared_radius_3_object();
typename K::Compute_squared_length_3 squared_length = k.compute_squared_length_3_object();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a note: you can use auto instead of typing all those types.

Comment on lines +3323 to +3324
if (sq_len < sq_rad)
return query;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So, if the query is inside the sphere, it stays where it is? Does this mean the project of query to the sphere is actually a projection to the ball?

Comment on lines +3328 to +3330
if (sq_len == 0) {
return point(x(c), y(c), z(c) + rad);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Before there was already

  • if (sq_rad == 0) return c;
  • if (sq_len < sq_rad) return query;

so I think sq_len == 0 is not possible. Can we assume that squared_radius(sphere)>=0?

Comment on lines +3331 to +3332
const typename K::FT len = CGAL::sqrt(sq_len);
const typename K::FT f = rad / len;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In generate I do no really like short names, especially when the longer names are already short:

Suggested change
const typename K::FT len = CGAL::sqrt(sq_len);
const typename K::FT f = rad / len;
const typename K::FT length = CGAL::sqrt(sq_len);
const typename K::FT fraction = radius / length;

const typename K::FT len = CGAL::sqrt(sq_len);
const typename K::FT f = rad / len;

return point(x(c) + f * x(v), y(c) + f * y(v), z(c) + f * z(v));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should not use the x/y/z coordinates. Use higher-level constructions from the kernel:

Suggested change
return point(x(c) + f * x(v), y(c) + f * y(v), z(c) + f * z(v));
auto scaled_vector = k.construct_scaled_vector_3_object();
auto translated_vector = l.construct_translated_vector_3_object();
return translated_vector(center, scaled_vector(v, factor));

@lrineau lrineau added the Not yet approved The feature or pull-request has not yet been approved. label May 5, 2026
@@ -0,0 +1,99 @@
// Copyright (c) 2012 INRIA Sophia-Antipolis (France).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this correct?
See also #9449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Not yet approved The feature or pull-request has not yet been approved. Pkg::AABB_tree Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants