Skip to content

Simplify Implementation#3

Merged
alice-i-cecile merged 2 commits intobevyengine:mainfrom
bushrat011899:simplify
Jun 30, 2025
Merged

Simplify Implementation#3
alice-i-cecile merged 2 commits intobevyengine:mainfrom
bushrat011899:simplify

Conversation

@bushrat011899
Copy link
Copy Markdown
Contributor

Foreword

This PR makes substantial changes to the current implementation's structure, but it is byte-accurate with the original and the C implementation. Most changes are in the structure and control flow rather than the actual floating point operations. Reviewing the diff on GitHub itself my be challenging, so I recommend checking out the before and after in their entirety.

Objective

  • Simplify a somewhat non-standard Rust crate into something more idiomatic.
  • Remove libm as a dependency, allowing this crate to stabilize.

Solution

  • Removed several custom sorting implementations, opting for core::slice::sort. Since the original implementations were correct, we can use the language provided sorts instead.
  • Removed the custom hashtable implementation, opting to instead use alloc::collections::BTreeMap.
  • Removed libm as a dependency and removed all features, making this crate purely no_std. Instead, users must provide a VectorSpace implementation alongside the implementation of Geometry. This has the two-fold benefit of simplifying internal code and allowing users the freedom to choose their maths library (avoiding issues where glam was pegged to a particular version for example).
  • Reorganised code to favour slices over manually tracked buffers/offsets/lengths.
  • Used iterator constructs to provide clearer structure around intent.
  • Added documentation where only // comments existed.
  • Used lifetimes and core::slice::split_at(_mut) to track the relationship between indices and buffer regions.

Notes

This PR removes about a third of the code from this crate while adding customization options for the end user and paving a clear path to stabilization. But, it is also a substantial departure from the structure of the original C implementation. As such, I expect this to be somewhat controversial.

Copy link
Copy Markdown
Contributor

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

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

monumental! cursory review looks great, will go more in depth later. Is replacing C with mikktspace-sys gonna be a different PR?

Co-Authored-By: atlv <11307157+atlv24@users.noreply.github.com>
@bushrat011899
Copy link
Copy Markdown
Contributor Author

Is replacing C with mikktspace-sys gonna be a different PR?

Yeah a follow-up PR.

Copy link
Copy Markdown
Contributor

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

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

Fantastic cleanup, and I can't spot any functional deviation from the procedure. LGTM

@alice-i-cecile alice-i-cecile merged commit ae32804 into bevyengine:main Jun 30, 2025
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.

3 participants