Repository navigation
rust: Port graphics/math-extra.c to obs-graphics - #352
Merged
Merged
Conversation
Pins the current exports of graphics/math-extra.c before the Rust port. Header-inline helpers stay C. Tests do not read the uninitialized w lane from polar_to_cart or a non-zero cart_to_polar. Refs obs-rust#351
test_polar_to_cart_plus_z fails because polar_to_cart returns a zero vector: left (0, 0, 0), right (0, 0, 2). 10 of 12 Tier 1 tests fail. test_polar_to_cart_zero_radius and test_cart_to_polar_within_epsilon pass because the empty result is also the right one. Refs obs-rust#351
Safe core, C shims, Tier 3 parity, and the ENABLE_RUST_LIBOBS guard. Header-inline helpers stay C. Exports are in libobs/cmake/rust-exports.d/obs-graphics-math_extra.txt. The oracle no longer defines the unrenamed rand_float; the shim does. Refs obs-rust#351 Local-Gate: v1 tree=5fe221c580d30315c45db536a88de063a2880649 secs=107 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791797032,"gate":"rust/all/fmt","host":"linux-x86_64","key":"55e953d2fba6a439a344d276a7a0c040af6d2347aeb328dd3f38ad2c143eed9f","lane":"lint","parents":["e996564448f2ceb991f0e633d3ff193297d1ba42"],"secs":16,"stamp":"0fddddeadd811f0a58d78c33ba12ebc0","tree":"5fe221c580d30315c45db536a88de063a2880649","v":1,"via":"run"} Ci-Attestation: {"at":1791797032,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"55e953d2fba6a439a344d276a7a0c040af6d2347aeb328dd3f38ad2c143eed9f","lane":"lint","parents":["e996564448f2ceb991f0e633d3ff193297d1ba42"],"secs":16,"stamp":"c2453111d2364ca577eeebf8e570e900","tree":"5fe221c580d30315c45db536a88de063a2880649","v":1,"via":"run"} Ci-Attestation: {"at":1791797032,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"5abaf406b47699f9aa8d3f767cc7bdee63998e0cee4fb38b96ae7c8832566631","lane":"rust-test","parents":["e996564448f2ceb991f0e633d3ff193297d1ba42"],"secs":47,"stamp":"7ae5a90bbfc6ba6bc177ae47917e75c8","tree":"5fe221c580d30315c45db536a88de063a2880649","v":1,"via":"run"} Ci-Attestation: {"at":1791797032,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"4f27af4194ed261416a9812baca8846fe9136c1889d6fa9604afe8003e799508","lane":"tier2-linux","parents":["e996564448f2ceb991f0e633d3ff193297d1ba42"],"secs":44,"stamp":"feb537950e7720b242360b51ff2b70e0","tree":"5fe221c580d30315c45db536a88de063a2880649","v":1,"via":"run"}
zackees
force-pushed
the
port/math-extra
branch
from
October 12, 2026 09:23
c15b11e to
76c1333
Compare
Member
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 12, 2026
…-extra ports copied Upstream obs-rust#338 (plane) and obs-rust#352 (math-extra) landed after this branch's base, and both ports deliberately copied the C aliasing bugs so they would match it: plane_from_tri detected `v1 == &dst->dir` and set the distance to `dir·dir`, and calc_torque stored the scaled direction and then re-read `v1` through the pointer to add it. Their characterization tests pinned those results, marked "Characterized, not endorsed". With the C fixed, neither emulation is needed. plane_from_tri now reads all three vertices and builds the plane from the copies, like every other shim in the crate, and calc_torque uses the safe core's calc_torque, which already reads v1 before writing. The two characterization tests are updated to the fixed values, and each now also runs the non-aliased call and asserts the aliased result equals it, so the property (not just a constant) is checked. The Rust parity tests do the same against the oracle. Tested by reverting the C and shim fixes to the versions in this merge base and rebuilding: test_graphics_math_alias fails 19/19, test_math_extra fails test_calc_torque_dst_aliases_v1, test_plane fails test_plane_from_tri_v1_aliases_dir, and calc_torque_dst_aliases_v1_matches_c fails against the unfixed oracle. With the fixes in place all pass, in debug and release.
10 of 22 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #351. Refs #45.
Ports
libobs/graphics/math-extra.ctoobs-graphics. Header-inlineget_percentageandget_percentageistay C.ENABLE_RUST_LIBOBSdropsgraphics/math-extra.c. Exports are inlibobs/cmake/rust-exports.d/obs-graphics-math_extra.txt. No new public struct, so there is no layout test.vec2andvec3layouts are already tested.Commits
2c32c8e9acharacterization:test/cmocka/test_math_extra.c. It does not readwafterpolar_to_cartor a non-zerocart_to_polar(that lane is uninitialized in C).e99656444RED.test_polar_to_cart_plus_zfails becausepolar_to_cartreturns a zero vector: left(0, 0, 0), right(0, 0, 2). 10 of 12 Tier 1 tests fail.test_polar_to_cart_zero_radiusandtest_cart_to_polar_within_epsilonpass because the empty result is also the right one.c15b11e7fGREEN.What passed here
math_extratests.math_extra_paritytests, 1024 cases, bit-exact (NaN equals NaN). xyz only forpolar_to_cartandcart_to_polar.export_list(3 tests).vec3rand_matches_c_oraclestill passes now thatrand_floatis the Rust shim.soldr cargo test --workspace --lockedpassed.soldr cargo clippy -p obs-graphics -p obs-c-oracle --all-targets --locked -- -D warningspassed.vec3_closean absolute comparison madetest_calc_torque_one_sided_close_copies_targetfail (left(2, 1, 4, 0), right(4, 2, 8, 5)). That break was reverted.Intentional differences
polar_to_cartandcart_to_polarsetwto 0. C leaves that lane uninitialized except whencart_to_polarzeros a length withinEPSILON.polar_to_normdoes not writew.vec3_closeis one-sided (v1 - v2 < EPSILONon each of xyz), socalc_torquecopiesv2for some far-apart pairs. The shim stores the scaled step and then re-readsv1, sodst == v1matches C ((10, 0, 0)stepped halfway becomes(-10, 0, 0)).rand_floatcalls the C libraryrand/RAND_MAX. Any non-zeropositive_onlytakes the[0, 1]branch.Not run
Docker is not installed, so Tier 2 cmocka (
./unittest) and the local-gate stamp were not run. This does not claim CI is green. Please add theclaimedlabel on #351. If this branch is behind master at review, rebase onto master and stamp.