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

[WIP] Add traversal queries based on points #43

Closed
wants to merge 2 commits into from

Conversation

medakk
Copy link

@medakk medakk commented Apr 24, 2020

For issue #42

This is just some quick code I whipped up to get it working for my use case. It includes a traversal for the points, and it would make sense to add traverse for any Bounded object. What would be the best way to generalize the traversal for all these different use cases?

One way would be to have a single traverse function that takes an argument f, which is a function that takes an AABB and returns whether or not there was a "hit". So, the ray traversal could be implemented as:

    pub fn traverse<'a, Shape: Bounded>(&'a self, ray: &Ray, shapes: &'a [Shape]) -> Vec<&Shape> {
        let mut indices = Vec::new();
        BVHNode::traverse_recursive(&self.nodes, 0, |&aabb| ray.intersects(aabb), &mut indices);
        indices
            .iter()
            .map(|index| &shapes[*index])
            .collect::<Vec<_>>()
    }

@svenstaro svenstaro requested a review from marstaik May 4, 2023 12:17
@svenstaro
Copy link
Owner

@finnbear what do you think about this? It's pretty old at this point.

@finnbear
Copy link
Collaborator

finnbear commented Jan 7, 2025

I'm interested in this (point query) for my personal projects, and I can intuitively understand the implementation due to how simple it is. As early as tomorrow, I'll look into fixing conflicts, fuzzing, etc.

The general traversal function idea is also interesting and, while I don't have a direct use for it as public api, but I do want circle and AABB queries!

@svenstaro
Copy link
Owner

Excellent, I'm staying tuned!

@finnbear finnbear mentioned this pull request Jan 7, 2025
15 tasks
@svenstaro
Copy link
Owner

Superseded by #108.

@svenstaro svenstaro closed this Jan 9, 2025
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 96.15385% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.07%. Comparing base (4e91c5f) to head (5b9b798).
Report is 234 commits behind head on master.

Files with missing lines Patch % Lines
src/bvh/bvh.rs 91.66% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
- Coverage   85.51%   85.07%   -0.45%     
==========================================
  Files           8        8              
  Lines        1450     1487      +37     
==========================================
+ Hits         1240     1265      +25     
- Misses        210      222      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@finnbear
Copy link
Collaborator

*Actually, superseded by #128, which allows you to query for AABB's that contain a point.

#108 adds a different type of query, that finds the closest shapes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants