ifc_lite_geometry/kernel/
manifest.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Cross-platform sign manifest (G2 L1 slice) — the determinism-bar proof for
6//! the predicate layer.
7//!
8//! A fixed-seed battery of every indirect + explicit predicate configuration,
9//! FNV-1a-hashed over the result SIGNS. Exact predicate signs are integer
10//! parity over FMA-free IEEE-754 arithmetic (Rust does not auto-contract float
11//! ops; the kernel has no `mul_add`), so the manifest MUST be byte-identical on
12//! x86_64 / aarch64 / wasm. The pinned constant catches any sign-logic
13//! regression; running the SAME value on all three targets (the CI matrix +
14//! the local wasm cross-check) proves the topology-determinism bar for L1.
15
16use super::predicates::{cmp_lex, orient2d, orient2d_2i, orient2d_3i, orient3d};
17use super::{DropAxis, ImplicitPoint, Lpi, Sign, Tpi};
18
19/// Deterministic LCG (fixed seed — reproducible across targets).
20struct ManifestRng(u64);
21impl ManifestRng {
22    fn u(&mut self) -> u64 {
23        self.0 = self.0.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
24        self.0
25    }
26    /// Building-scale coordinate in [-50, 50).
27    fn f(&mut self) -> f64 {
28        let unit = (self.u() >> 11) as f64 / (1u64 << 53) as f64;
29        -50.0 + 100.0 * unit
30    }
31    fn p(&mut self) -> [f64; 3] {
32        [self.f(), self.f(), self.f()]
33    }
34}
35
36#[inline]
37fn mix(h: &mut u64, s: Sign) {
38    let code: u8 = match s {
39        Sign::Negative => 0,
40        Sign::Zero => 1,
41        Sign::Positive => 2,
42    };
43    *h ^= code as u64;
44    *h = h.wrapping_mul(0x0000_0100_0000_01b3); // FNV-1a prime
45}
46
47/// FNV-1a hash over the signs of a fixed battery of predicate calls across all
48/// supported `ImplicitPoint` configurations. Platform-independent by the
49/// determinism argument above.
50pub fn indirect_sign_manifest() -> u64 {
51    let mut rng = ManifestRng(0x9e37_79b9_7f4a_7c15);
52    let mut h: u64 = 0xcbf2_9ce4_8422_2325; // FNV-1a offset basis
53    for _ in 0..1000 {
54        let l = Lpi { p: rng.p(), q: rng.p(), r: rng.p(), s: rng.p(), t: rng.p() };
55        let t = Tpi {
56            planes: [
57                [rng.p(), rng.p(), rng.p()],
58                [rng.p(), rng.p(), rng.p()],
59                [rng.p(), rng.p(), rng.p()],
60            ],
61        };
62        let l2 = Lpi { p: rng.p(), q: rng.p(), r: rng.p(), s: rng.p(), t: rng.p() };
63        let ea = ImplicitPoint::Explicit(rng.p());
64        let eb = ImplicitPoint::Explicit(rng.p());
65        let ec = ImplicitPoint::Explicit(rng.p());
66        let il = ImplicitPoint::Lpi(l);
67        let it = ImplicitPoint::Tpi(t);
68        let il2 = ImplicitPoint::Lpi(l2);
69        // orient3d (explicit, LPI-1I, TPI-1I)
70        mix(&mut h, orient3d(&ea, &eb, &ec, &ImplicitPoint::Explicit(l.p)));
71        mix(&mut h, orient3d(&il, &ea, &eb, &ec));
72        mix(&mut h, orient3d(&it, &ea, &eb, &ec));
73        // orient2d 1I
74        mix(&mut h, orient2d(&il, &ea, &eb, DropAxis::Z));
75        mix(&mut h, orient2d(&it, &ea, &eb, DropAxis::X));
76        mix(&mut h, orient2d(&il, &eb, &ec, DropAxis::Y));
77        // mixed-implicit configs: orient2d 2I / 3I + cmp_lex (all through the cascade)
78        mix(&mut h, orient2d_2i(&il, &il2, rng.p(), DropAxis::Z));
79        mix(&mut h, orient2d_2i(&it, &il2, rng.p(), DropAxis::X));
80        mix(&mut h, orient2d_3i(&il, &it, &il2, DropAxis::Y));
81        mix(&mut h, cmp_lex(&il, &it));
82        mix(&mut h, cmp_lex(&il, &il2));
83        mix(&mut h, cmp_lex(&it, &ImplicitPoint::Explicit(l.p)));
84    }
85    h
86}
87
88#[cfg(test)]
89mod tests {
90    use super::indirect_sign_manifest;
91
92    /// Pinned cross-platform determinism fingerprint (G2 L1 slice). If this
93    /// changes: either the predicate sign logic changed (intended → re-pin and
94    /// re-run the wasm/ARM cross-check) or determinism broke (investigate).
95    const SIGN_MANIFEST: u64 = 0xdd1d_d6b0_0013_0af5;
96
97    #[test]
98    fn indirect_sign_manifest_is_pinned() {
99        let m = indirect_sign_manifest();
100        assert_eq!(
101            m, SIGN_MANIFEST,
102            "indirect predicate sign manifest changed: 0x{m:016x} (re-pin if intended, then re-run the cross-platform check)"
103        );
104    }
105}