-
Notifications
You must be signed in to change notification settings - Fork 20
Add volume and area calculations #12
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
Open
casperlamboo
wants to merge
1
commit into
hmeyer:main
Choose a base branch
from
casperlamboo:feature/volume-area
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this method should return an Optional[f32] or a Result[f32, SomeErrorType], and include a call to validate.
Furthermore, for this to be the true volume, I think we'd have to validate that the winding number of all triangles is the same, no?
Uh oh!
There was an error while loading. Please reload this page.
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.
I think I would switch it around; have the
volume > 0check in the validate function. but it is your call. (if you know your mesh to be valid it is annoying if a library spends computation on validation)I believe that the connected indices check in the validate function ensures that the winding order is the same for all tris.
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.
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.
In my opinion it is bad practice to combine these kinds of validate checks inside "computation functions". It is better to execute such validation checks only once during or just after the construction of the data type. For instance coding a ray tracer; the direction of the ray always needs to be a unit length vector, but i'm not going to normalise the vector every time I compute something. Instead the normalisation is executed once when constructing the ray.
I would propose something like this.
What you think about this? downside with my approach compared to yours is that if a user wants to know if a model is valid and want to know it's volume the volume is essentially computed twice.
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.
I think it is questionable to assume the one winding is the correct and thus the other winding is invalid.
Meaning even a mesh that has negative winding might be valid.
The thing about volume is, that the calculation is only correct, if the mesh is closed and has correct winding.
But the above volume() function will also return a volume for meshes that are not closed or have no correct winding. In my opinion this would be a bug.
If you really wouldn't want to include the other validation checks in volume(), then volume would have to renamed to:
fn volume_assuming_the_mesh_is_closed_and_has_clockwise_winding()