-
Notifications
You must be signed in to change notification settings - Fork 1
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
utils3d: Supports dim != 3 #4
Conversation
WalkthroughThe update involves renaming a module from Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
==========================================
+ Coverage 99.54% 99.56% +0.01%
==========================================
Files 2 2
Lines 880 910 +30
==========================================
+ Hits 876 906 +30
Misses 4 4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- src/lib.rs (1 hunks)
- src/utils3d.rs (5 hunks)
Files skipped from review due to trivial changes (1)
- src/lib.rs
Additional comments: 6
src/utils3d.rs (6)
- 10-20: The implementation of the
normal
function has been updated to support variable dimensions by introducing adim
parameter. This change allows the function to work with dimensions other than 3, enhancing its flexibility. However, it's important to ensure that the logic correctly handles cases wheredim
is not 3, especially since the original code seems tailored for 3D calculations.- 52-61: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [43-76]
The
project3d_to_2d
function has been updated to use the newdim
parameter, allowing for projection from 3D to 2D space with consideration for variable dimensionality. This change is significant for enhancing the function's versatility. However, the logic within this function, particularly the handling of different cases based on the normal vector's direction and magnitude, seems to assume a 3D context. It's important to ensure that these assumptions still hold whendim
is not 3 and that the projection logic is correctly adapted for different dimensions.
- 90-101: The test
test_do_nothing
has been updated to include cases fordim=3
anddim=5
, ensuring that theproject3d_to_2d
function behaves as expected for different dimensions. This is a good practice for verifying the function's correctness across a range of inputs. However, it's important to ensure comprehensive coverage, including edge cases and invalid inputs, to fully validate the new functionality.- 107-118: The test
test_flip
includes cases fordim=3
anddim=4
, testing the behavior of theproject3d_to_2d
function when the normal vector's z-component is negative. This test is crucial for ensuring that the function correctly handles flipping in different dimensional contexts. It's well-implemented and contributes to the robustness of the test suite.- 124-135: The test
test_rotate
checks the rotation logic within theproject3d_to_2d
function fordim=3
anddim=4
. This test is important for verifying that the function correctly applies rotation transformations in different dimensional contexts. The inclusion of tests for different dimensions is commendable, as it helps ensure the function's behavior is consistent and correct across various inputs.- 141-149: The tests
test_invalid_input1
andtest_invalid_input2
are designed to verify the handling of invalid inputs, including insufficient vertex data and cases where the normal vector calculation results in a zero vector. These tests are essential for ensuring the robustness of thenormal
andproject3d_to_2d
functions by checking their behavior in edge cases and error conditions.
(ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx) | ||
} | ||
|
||
fn normal<T: Float + Debug>(vertices: &[T]) -> Option<(T, T, T)> { | ||
fn normal<T: Float + Debug>(vertices: &[T], dim: usize) -> Option<(T, T, T)> { | ||
let len = vertices.len(); | ||
if len < 9 { | ||
if len < dim * 3 { | ||
// At least 3 vertices required | ||
return None; | ||
} | ||
let last_point = (vertices[len - 3], vertices[len - 2], vertices[len - 1]); | ||
let last_point = ( | ||
vertices[len - dim], | ||
vertices[len - dim + 1], | ||
vertices[len - dim + 2], | ||
); | ||
|
||
let (sum, _) = vertices.chunks_exact(3).fold( | ||
let (sum, _) = vertices.chunks_exact(dim).fold( | ||
((T::zero(), T::zero(), T::zero()), last_point), | ||
|(acc, prev), data| { | ||
let (x, y, z) = (data[0], data[1], data[2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [22-34]
The calculation within the normal
function uses a fold operation to accumulate cross products of vertex differences. This logic appears sound for computing a normal vector in 3D space. However, given the introduction of variable dimensions, it's crucial to verify that this approach remains valid for dimensions other than 3. Specifically, the cross product and subsequent operations assume a 3D context, which may not generalize to other dimensions without modification.
Consider verifying the mathematical correctness of this approach for dimensions other than 3 or providing additional documentation on the expected behavior and limitations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is supposed to be used with data like position (3 dims) + texture uv (2 dims), and it just ignores non-positional dimentions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ciscorn Thank you for the clarification. It's clear now that the normal
function is designed to work with 3D positional data, even when additional dimensions (like texture UV coordinates) are present, by focusing on the first three dimensions and ignoring the rest. This approach ensures the mathematical operations remain valid for 3D space.
It might be beneficial to include comments or documentation in the code to explicitly state this intended behavior, ensuring that future developers understand how the function handles data with dimensions beyond 3D positional information.
Summary by CodeRabbit