Skip to content

Mesh::face_arities becomes Option<Vec<u32>> - #80

Open
virtualritz wants to merge 2 commits into
Twinklebear:masterfrom
virtualritz:pr/face-arities
Open

Mesh::face_arities becomes Option<Vec<u32>>#80
virtualritz wants to merge 2 commits into
Twinklebear:masterfrom
virtualritz:pr/face-arities

Conversation

@virtualritz

Copy link
Copy Markdown
Contributor

Summary

Stacks on #79 (progress-callback) — this diff includes both commits until #79 merges; the second commit is the one this PR is actually about.

  • Mesh::face_arities changes from Vec<u32> to Option<Vec<u32>>. None now means "all faces are triangles" instead of an empty Vec, which skips the allocation for triangle-only meshes — the common case, especially with triangulate: true.
  • New Mesh::{face_count, face_arity, is_triangulated, face_indices} helper methods replace manual index-arithmetic over face_arities at call sites (see the updated examples/print_mesh.rs and the crate's module-doc example) — the offset math for finding a given face's indices was previously left to every caller to get right.
  • Also tidies two loops (parse_face, TmpMaterials::extend) into iterator chains while in the area — no behavior change there.

BREAKING CHANGE: any caller reading Mesh::face_arities directly as a Vec needs to match on the Option, or switch to the new helper methods. Happy to gate this behind a semver-major bump on your end, or split differently if you'd rather land it separately from #79 for that reason.

Test plan

  • cargo test --all-features: 21 lib tests + 5 doctests pass, including updated non_triangulated_quad coverage for the None/Some cases
  • cargo build --example print_mesh --all-features
  • cargo fmt --all -- --check: clean
  • cargo clippy --all-targets --all-features -- -D warnings: clean (exit 0)

LoadOptions gains progress_callback: Option<LoadProgressCallback>
(Arc<dyn Fn(&LoadProgress) -> ControlFlow<()> + Send + Sync>, an options
field rather than a second _with_progress function), invoked every 1000
lines during load_obj_buf's parse loop. Returning ControlFlow::Break stops
the load and returns the new LoadError::Cancelled. No behavior change when
progress_callback is None (the default): verified by a test comparing
output with and without a no-op callback. load_obj_buf_async is untouched.
None now means "all faces are triangles" instead of an empty Vec, saving
the allocation for triangle-only meshes -- the common case. New
Mesh::{face_count, face_arity, is_triangulated, face_indices} helpers
replace manual index-arithmetic over face_arities at call sites (see
print_mesh.rs and the module doc example). Also tidies two loops
(parse_face, TmpMaterials::extend) into iterator chains while in the area.

BREAKING CHANGE: any caller reading Mesh::face_arities directly (as a Vec)
needs to match on the Option, or switch to the new helper methods.
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