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

utils3d: Supports dim != 3 #4

Merged
merged 1 commit into from
Feb 16, 2024
Merged

utils3d: Supports dim != 3 #4

merged 1 commit into from
Feb 16, 2024

Conversation

ciscorn
Copy link
Member

@ciscorn ciscorn commented Feb 16, 2024

Summary by CodeRabbit

  • Refactor
    • Renamed the 3D utilities module for consistency.
    • Enhanced 3D to 2D projection functionality with a new dimension parameter, improving flexibility in 3D computations.
  • Tests
    • Updated tests to accommodate new dimension parameter in 3D utility functions.

Copy link

coderabbitai bot commented Feb 16, 2024

Walkthrough

The update involves renaming a module from utils_3d to utils3d for consistency and enhancing the normal function within utils3d.rs to support a new dim parameter, allowing for more flexible calculations. Additionally, the project3d_to_2d function has been adjusted to utilize this dim parameter, optimizing 3D to 2D projection processes. Tests have been updated accordingly to align with these functional modifications, ensuring the changes are well-integrated and functional.

Changes

Files Change Summary
src/lib.rs, src/utils3d.rs Renamed module to utils3d, updated normal function to accept dim, and adjusted project3d_to_2d to use dim. Updated tests for new dim parameter.

🎉🐰✨
Changes abound, the code does leap,
From utils_3d to utils3d, a jump so deep.
A dim now added, with care and thought,
To normal and projections, improvements sought.
Tests all updated, with dim they comply,
A rabbit's work, under the code-filled sky.
🌟📚🐾

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c1b775b) 99.54% compared to head (1276cc5) 99.56%.

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.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between c1b775b and 1276cc5.
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 a dim 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 where dim 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 new dim 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 when dim 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 for dim=3 and dim=5, ensuring that the project3d_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 for dim=3 and dim=4, testing the behavior of the project3d_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 the project3d_to_2d function for dim=3 and dim=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 and test_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 the normal and project3d_to_2d functions by checking their behavior in edge cases and error conditions.

Comment on lines 7 to 25
(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]);
Copy link

@coderabbitai coderabbitai bot Feb 16, 2024

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.

Copy link
Member Author

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.

Copy link

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.

@MIERUNE MIERUNE deleted a comment from coderabbitai bot Feb 16, 2024
@ciscorn ciscorn merged commit 0303da0 into main Feb 16, 2024
3 checks passed
@ciscorn ciscorn deleted the utils3d-dim branch February 16, 2024 02:35
@ciscorn ciscorn self-assigned this Oct 5, 2024
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.

1 participant