Add cross-runtime geometry v2 contract

This commit is contained in:
Meta Vens 2026-07-22 03:25:46 +01:00
commit 9293471630
9 changed files with 998 additions and 10 deletions

3
.gitignore vendored
View file

@ -206,6 +206,9 @@ PublishScripts/
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
!/packages/gamecult-geometry-rs/
!/packages/gamecult-geometry-rs/**
packages/gamecult-geometry-rs/target/
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed

View file

@ -56,8 +56,8 @@ Demotions:
| --- | --- | --- |
| 0. Freeze and baseline | Complete | Source bodies, contracts, consumers, licenses, fixtures, and focused baselines mapped |
| 1. Destination/dependency/formatters/SoA | Complete | NuGet and dedicated UPM artifacts prove dependency direction and owned vector integration |
| 2. Primitive deletion and v2 schemas | In progress | Delete duplicate vectors first, then publish corrected v2 contracts |
| 3. Planetary transfer | Pending | Requires destination packaging and preserved parity corpus |
| 2. Primitive deletion and v2 schemas | Complete | C# and Geometry-owned Rust emit identical v2 bytes and record keys for all four roots |
| 3. Planetary transfer | In progress | Transfer C#/tests first, then shaders and runtime projections; delete CultMath owners in the same stage |
| 4. Mine `vg-csg` | Pending | Requires v1 fixture capture and target Rust package seam |
| 5. CultCache/CultNet/CultMesh integration | Pending | Requires current schemas and runtime packages |
| 6. Consumer cutover/release | Pending | Requires local candidate feed and downstream passes |
@ -186,11 +186,24 @@ a broader stage gate.
stream. Domain/chunk round trips preserve record identity, while the checked-
in flat-mesh v1 payload is retained as negative evidence and rejected by the
v2 decoder. The Geometry suite passes 19/19 after the cohort cut.
- `packages/gamecult-geometry-rs` is the Geometry-owned Rust v2 destination.
It has no VibeGeometry, `vg-csg`, `bevy_math`, CultCache, or CultNet
dependency and preserves the MIT provenance of the mined `vg-csg` contract.
- C# and Rust pin identical exact MessagePack bytes and record keys for domain,
build request, selected cut, and chunk roots. C# decodes the Rust witnesses
and re-emits the same bytes. The Geometry suite passes 24/24; Rust passes 4/4,
doc tests, rustfmt, and warning-denied clippy.
- The parity pass exposed an old split identity: C# request scalar floats used
round-trip decimal text while `vg-csg` used IEEE-bit hex. v2 deliberately
standardizes every float on IEEE bits. The request key therefore changes at
the v2 boundary; signed zero, a chosen NaN payload, and infinity are pinned
across MessagePack so this cannot quietly diverge again.
## Next Actions
1. Rewrite Geometry primitives over CultMath and delete `CultVec2`/`CultVec3`
without aliases or forwarding types.
2. Publish v2 geometry documents with typed vectors/quaternion and deliberate
stable-key fixtures; keep v1 only as test evidence.
3. Run repository/package negative searches before beginning planetary transfer.
1. Establish the Geometry-owned planetary parity harness and move the 13 C#
source/test files while deleting the matching CultMath owners and `rect`.
2. Transfer and rename planetary/erosion HLSL ownership, then remove the
implicit geometry includes and bodies from `CultMath.hlsl`.
3. Transfer the CMPT tool/web decoder, Unity adapters/sample, docs, and license
notices; inspect both packages and run the complete negative gate.

194
packages/gamecult-geometry-rs/Cargo.lock generated Normal file
View file

@ -0,0 +1,194 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "autocfg"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cpufeatures"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "gamecult-geometry"
version = "0.1.0"
dependencies = [
"rmp-serde",
"serde",
"sha2",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rmp"
version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ba8be72d372b2c9b35542551678538b562e7cf86c3315773cae48dfbfe7790c"
dependencies = [
"num-traits",
]
[[package]]
name = "rmp-serde"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72f81bee8c8ef9b577d1681a70ebbc962c232461e397b22c208c43c04b67a155"
dependencies = [
"rmp",
"serde",
]
[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha2"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "syn"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "typenum"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"

View file

@ -0,0 +1,14 @@
[package]
name = "gamecult-geometry"
version = "0.1.0"
edition = "2024"
description = "GameCult.Geometry typed contracts and geometry runtime for Rust"
license = "MIT"
repository = "https://github.com/GameCult/CultLib"
readme = "README.md"
[dependencies]
rmp-serde = "1"
serde = { version = "1", features = ["derive"] }
sha2 = "0.10"

View file

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2026 GameCult
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,11 @@
# GameCult.Geometry for Rust
Rust projection of the GameCult.Geometry v2 document contract. It owns the
typed MessagePack layouts and stable geometry record identities used at the
Rust boundary; it does not depend on VibeGeometry or `vg-csg`.
The initial contract and stable-hash implementation were mined from the
MIT-licensed GameCult `vg-csg` crate at commit `8f070f4`. The implementation
was rewritten here under GameCult.Geometry ownership. The original copyright
and MIT terms are preserved in [LICENSE](LICENSE).

View file

@ -0,0 +1,578 @@
//! GameCult.Geometry's Rust contract and runtime surface.
//!
//! The v2 contract was mined from the MIT-licensed GameCult `vg-csg` crate at
//! commit `8f070f4`, then rewritten around typed vector values. This crate has
//! no runtime or build dependency on VibeGeometry or `vg-csg`.
use std::fmt::Write;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use sha2::{Digest, Sha256};
pub const GEOMETRY_DOMAIN_SCHEMA: &str = "gamecult.geometry.domain.v2";
pub const GEOMETRY_BUILD_REQUEST_SCHEMA: &str = "gamecult.geometry.build_request.v2";
pub const GEOMETRY_SELECTED_CUT_SCHEMA: &str = "gamecult.geometry.selected_cut.v2";
pub const GEOMETRY_CHUNK_ARTIFACT_SCHEMA: &str = "gamecult.geometry.chunk_artifact.v2";
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Float2(pub f32, pub f32);
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Float3(pub f32, pub f32, pub f32);
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct Quaternion(pub f32, pub f32, pub f32, pub f32);
impl Default for Quaternion {
fn default() -> Self {
Self(0.0, 0.0, 0.0, 1.0)
}
}
pub trait GeometryDocument: Serialize + DeserializeOwned + Sized {
const SCHEMA_VERSION: &'static str;
fn record_key(&self) -> String;
fn to_msgpack(&self) -> Result<Vec<u8>, rmp_serde::encode::Error> {
rmp_serde::to_vec(self)
}
fn from_msgpack(payload: &[u8]) -> Result<Self, rmp_serde::decode::Error> {
rmp_serde::from_slice(payload)
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GeometryDomainDocument(
pub String,
pub String,
pub String,
pub GeometryDomainNode,
pub String,
);
impl GeometryDocument for GeometryDomainDocument {
const SCHEMA_VERSION: &'static str = GEOMETRY_DOMAIN_SCHEMA;
fn record_key(&self) -> String {
format!(
"geometry:domain:{}",
stable_hash(&[&self.1, &self.2, &self.3.stable_fingerprint()])
)
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GeometryDomainNode(
pub String,
pub String,
pub Float3,
pub Quaternion,
pub u64,
pub Vec<GeometryFeatureClaim>,
pub Vec<GeometryDomainNode>,
);
impl GeometryDomainNode {
pub fn stable_fingerprint(&self) -> String {
let mut parts = vec![
self.0.clone(),
self.1.clone(),
stable_float3(self.2),
stable_quaternion(self.3),
self.4.to_string(),
];
parts.extend(self.5.iter().map(GeometryFeatureClaim::stable_fingerprint));
parts.extend(self.6.iter().map(GeometryDomainNode::stable_fingerprint));
stable_join(&parts)
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GeometryFeatureClaim(
pub String,
pub Float3,
pub Quaternion,
pub Float3,
pub Float3,
pub String,
pub u32,
pub String,
);
impl GeometryFeatureClaim {
pub fn stable_fingerprint(&self) -> String {
stable_join(&[
self.0.clone(),
stable_float3(self.1),
stable_quaternion(self.2),
stable_float3(self.3),
stable_float3(self.4),
self.5.clone(),
self.6.to_string(),
self.7.clone(),
])
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GeometryBuildRequest(
pub String,
pub String,
pub String,
pub Float3,
pub Float3,
pub Float3,
pub f32,
pub f32,
pub f32,
pub i32,
pub i32,
pub Vec<String>,
pub Vec<String>,
pub Vec<String>,
pub String,
);
impl GeometryDocument for GeometryBuildRequest {
const SCHEMA_VERSION: &'static str = GEOMETRY_BUILD_REQUEST_SCHEMA;
fn record_key(&self) -> String {
format!(
"geometry:request:{}",
stable_hash(&[
&self.1,
&self.2,
&stable_float3(self.3),
&stable_float3(self.4),
&stable_float3(self.5),
&stable_f32(self.6),
&stable_f32(self.7),
&stable_f32(self.8),
&self.9.to_string(),
&self.10.to_string(),
&stable_join(&self.11),
&stable_join(&self.12),
&stable_join(&self.13),
])
)
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GeometrySelectedCutManifest(
pub String,
pub String,
pub Vec<String>,
pub Vec<String>,
pub Vec<String>,
pub Vec<GeometryContributionRow>,
);
impl GeometryDocument for GeometrySelectedCutManifest {
const SCHEMA_VERSION: &'static str = GEOMETRY_SELECTED_CUT_SCHEMA;
fn record_key(&self) -> String {
format!(
"geometry:cut:{}",
stable_hash(&[
&self.1,
&self.0,
&stable_join(&self.2),
&stable_join(&self.3),
&stable_join(&self.4),
])
)
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GeometryContributionRow(
pub String,
pub String,
pub f32,
pub f32,
pub f32,
pub i32,
pub i32,
pub i32,
pub bool,
pub bool,
pub bool,
pub bool,
pub bool,
);
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GeometryChunkArtifact(
pub String,
pub String,
pub String,
pub Float3,
pub Float3,
pub Vec<String>,
pub Vec<String>,
pub GeometryTriangleMesh,
pub Option<GeometryTriangleMesh>,
pub i32,
pub i32,
pub i32,
pub u64,
pub bool,
);
impl GeometryDocument for GeometryChunkArtifact {
const SCHEMA_VERSION: &'static str = GEOMETRY_CHUNK_ARTIFACT_SCHEMA;
fn record_key(&self) -> String {
format!(
"geometry:chunk:{}",
stable_hash(&[
&self.1,
&self.0,
&self.2,
&stable_join(&self.5),
&stable_join(&self.6),
&self.7.stable_fingerprint(),
self.8
.as_ref()
.map(GeometryTriangleMesh::stable_fingerprint)
.as_deref()
.unwrap_or(""),
])
)
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct GeometryTriangleMesh(
pub Vec<Float3>,
pub Vec<Float3>,
pub Vec<Float2>,
pub Vec<u32>,
pub Vec<u32>,
);
impl GeometryTriangleMesh {
pub fn triangle_count(&self) -> usize {
self.3.len() / 3
}
pub fn stable_fingerprint(&self) -> String {
stable_hash(&[
&stable_float3_array(&self.0),
&stable_float3_array(&self.1),
&stable_float2_array(&self.2),
&stable_u32_array(&self.3),
&stable_u32_array(&self.4),
])
}
}
fn stable_hash(parts: &[&str]) -> String {
let mut hasher = Sha256::new();
hasher.update(parts.join("\u{1f}").as_bytes());
let mut output = String::with_capacity(64);
for byte in hasher.finalize() {
write!(&mut output, "{byte:02x}").expect("string write");
}
output
}
fn stable_join(parts: &[String]) -> String {
parts.join("\u{1e}")
}
fn stable_f32(value: f32) -> String {
format!("{:08x}", value.to_bits())
}
fn stable_float2(value: Float2) -> String {
format!("{},{}", stable_f32(value.0), stable_f32(value.1))
}
fn stable_float3(value: Float3) -> String {
format!(
"{},{},{}",
stable_f32(value.0),
stable_f32(value.1),
stable_f32(value.2)
)
}
fn stable_quaternion(value: Quaternion) -> String {
format!(
"{},{},{},{}",
stable_f32(value.0),
stable_f32(value.1),
stable_f32(value.2),
stable_f32(value.3)
)
}
fn stable_float2_array(values: &[Float2]) -> String {
values
.iter()
.map(|v| stable_float2(*v))
.collect::<Vec<_>>()
.join(",")
}
fn stable_float3_array(values: &[Float3]) -> String {
values
.iter()
.map(|v| stable_float3(*v))
.collect::<Vec<_>>()
.join(",")
}
fn stable_u32_array(values: &[u32]) -> String {
values
.iter()
.map(u32::to_string)
.collect::<Vec<_>>()
.join(",")
}
#[cfg(test)]
mod tests {
use super::*;
fn domain() -> GeometryDomainDocument {
GeometryDomainDocument(
"fixture-domain".into(),
"fixture/root".into(),
"gamecult-geometry-rs".into(),
GeometryDomainNode(
"root".into(),
"Root".into(),
Float3(1.0, -2.5, 0.0),
Quaternion::default(),
42,
vec![],
vec![],
),
"2026-07-22T00:00:00Z".into(),
)
}
fn chunk() -> GeometryChunkArtifact {
GeometryChunkArtifact(
"fixture/chunk".into(),
"geometry:cut:fixture".into(),
"cut-fixture".into(),
Float3(-1.0, -2.0, -3.0),
Float3(1.0, 2.0, 3.0),
vec!["fixture/root".into()],
vec!["fixture/root/claim".into()],
GeometryTriangleMesh(
vec![
Float3(0.0, 0.0, 0.0),
Float3(1.0, 0.0, 0.0),
Float3(0.0, 1.0, 0.0),
],
vec![Float3(0.0, 0.0, 1.0); 3],
vec![Float2(0.0, 0.0), Float2(1.0, 0.0), Float2(0.0, 1.0)],
vec![0, 1, 2],
vec![7],
),
None,
1,
0,
0,
0x0123_4567_89ab_cdef,
true,
)
}
fn request() -> GeometryBuildRequest {
GeometryBuildRequest(
"request-fixture".into(),
domain().record_key(),
"workers".into(),
Float3(1.0, 2.0, 3.0),
Float3(-4.0, -5.0, -6.0),
Float3(4.0, 5.0, 6.0),
1080.0,
1.0,
0.25,
100,
50,
vec!["Root".into()],
vec![],
vec![],
"2026-07-22T00:00:01Z".into(),
)
}
fn cut() -> GeometrySelectedCutManifest {
GeometrySelectedCutManifest(
"cut-fixture".into(),
"geometry:request:fixture".into(),
vec!["fixture/root".into()],
vec![],
vec![],
vec![],
)
}
#[test]
fn schema_versions_are_v2() {
assert_eq!(
GeometryDomainDocument::SCHEMA_VERSION,
"gamecult.geometry.domain.v2"
);
assert_eq!(
GeometryBuildRequest::SCHEMA_VERSION,
"gamecult.geometry.build_request.v2"
);
assert_eq!(
GeometrySelectedCutManifest::SCHEMA_VERSION,
"gamecult.geometry.selected_cut.v2"
);
assert_eq!(
GeometryChunkArtifact::SCHEMA_VERSION,
"gamecult.geometry.chunk_artifact.v2"
);
}
#[test]
fn domain_record_key_matches_csharp_v2_fixture() {
let document = GeometryDomainDocument(
"ragnarok-column".into(),
"ragnarok-column".into(),
"vg-csg".into(),
GeometryDomainNode(
"ragnarok-column".into(),
"Root".into(),
Float3::default(),
Quaternion::default(),
0x5eed,
vec![],
vec![GeometryDomainNode(
"stellarator-column-00".into(),
"Column".into(),
Float3::default(),
Quaternion::default(),
0xc011_0000,
vec![GeometryFeatureClaim(
"column-support-shell".into(),
Float3::default(),
Quaternion::default(),
Float3(0.0, 0.0, 45.0),
Float3(18.0, 18.0, 96.0),
"SupportShell".into(),
10,
"RenderAndCollider".into(),
)],
vec![],
)],
),
"2026-05-29T00:00:00.0000000Z".into(),
);
assert_eq!(
document.record_key(),
"geometry:domain:175899ea97548da0599e12bcaccd07fa1d6009ed450fadb3de229d47bab04431"
);
}
#[test]
fn exact_v2_messagepack_and_record_key_witnesses() {
let domain = domain();
let chunk = chunk();
let request = request();
let cut = cut();
assert_eq!(
domain.record_key(),
"geometry:domain:505c94e7393580a4e5b048b169aa4da955da606ffd28c054b766a4b94e50502e"
);
assert_eq!(
request.record_key(),
"geometry:request:36e25b80c04a6c54c8b3137abb4a8c961468a9b1c0e7dd4d5632cf5a6f847966"
);
assert_eq!(
cut.record_key(),
"geometry:cut:5614eae3fe2a17dca651d1e32f401c50e1c3b9cf941f5789655990325da64fb3"
);
assert_eq!(
chunk.record_key(),
"geometry:chunk:ca2874d3638800179c906087ec817ea715c43b70b99ead04edccce2a1b3d6ebb"
);
assert_eq!(
domain.to_msgpack().unwrap(),
[
149, 174, 102, 105, 120, 116, 117, 114, 101, 45, 100, 111, 109, 97, 105, 110, 172,
102, 105, 120, 116, 117, 114, 101, 47, 114, 111, 111, 116, 180, 103, 97, 109, 101,
99, 117, 108, 116, 45, 103, 101, 111, 109, 101, 116, 114, 121, 45, 114, 115, 151,
164, 114, 111, 111, 116, 164, 82, 111, 111, 116, 147, 202, 63, 128, 0, 0, 202, 192,
32, 0, 0, 202, 0, 0, 0, 0, 148, 202, 0, 0, 0, 0, 202, 0, 0, 0, 0, 202, 0, 0, 0, 0,
202, 63, 128, 0, 0, 42, 144, 144, 180, 50, 48, 50, 54, 45, 48, 55, 45, 50, 50, 84,
48, 48, 58, 48, 48, 58, 48, 48, 90
]
);
assert_eq!(
request.to_msgpack().unwrap(),
[
159, 175, 114, 101, 113, 117, 101, 115, 116, 45, 102, 105, 120, 116, 117, 114, 101,
217, 80, 103, 101, 111, 109, 101, 116, 114, 121, 58, 100, 111, 109, 97, 105, 110,
58, 53, 48, 53, 99, 57, 52, 101, 55, 51, 57, 51, 53, 56, 48, 97, 52, 101, 53, 98,
48, 52, 56, 98, 49, 54, 57, 97, 97, 52, 100, 97, 57, 53, 53, 100, 97, 54, 48, 54,
102, 102, 100, 50, 56, 99, 48, 53, 52, 98, 55, 54, 54, 97, 52, 98, 57, 52, 101, 53,
48, 53, 48, 50, 101, 167, 119, 111, 114, 107, 101, 114, 115, 147, 202, 63, 128, 0,
0, 202, 64, 0, 0, 0, 202, 64, 64, 0, 0, 147, 202, 192, 128, 0, 0, 202, 192, 160, 0,
0, 202, 192, 192, 0, 0, 147, 202, 64, 128, 0, 0, 202, 64, 160, 0, 0, 202, 64, 192,
0, 0, 202, 68, 135, 0, 0, 202, 63, 128, 0, 0, 202, 62, 128, 0, 0, 100, 50, 145,
164, 82, 111, 111, 116, 144, 144, 180, 50, 48, 50, 54, 45, 48, 55, 45, 50, 50, 84,
48, 48, 58, 48, 48, 58, 48, 49, 90
]
);
assert_eq!(
cut.to_msgpack().unwrap(),
[
150, 171, 99, 117, 116, 45, 102, 105, 120, 116, 117, 114, 101, 184, 103, 101, 111,
109, 101, 116, 114, 121, 58, 114, 101, 113, 117, 101, 115, 116, 58, 102, 105, 120,
116, 117, 114, 101, 145, 172, 102, 105, 120, 116, 117, 114, 101, 47, 114, 111, 111,
116, 144, 144, 144
]
);
assert_eq!(
chunk.to_msgpack().unwrap(),
[
158, 173, 102, 105, 120, 116, 117, 114, 101, 47, 99, 104, 117, 110, 107, 180, 103,
101, 111, 109, 101, 116, 114, 121, 58, 99, 117, 116, 58, 102, 105, 120, 116, 117,
114, 101, 171, 99, 117, 116, 45, 102, 105, 120, 116, 117, 114, 101, 147, 202, 191,
128, 0, 0, 202, 192, 0, 0, 0, 202, 192, 64, 0, 0, 147, 202, 63, 128, 0, 0, 202, 64,
0, 0, 0, 202, 64, 64, 0, 0, 145, 172, 102, 105, 120, 116, 117, 114, 101, 47, 114,
111, 111, 116, 145, 178, 102, 105, 120, 116, 117, 114, 101, 47, 114, 111, 111, 116,
47, 99, 108, 97, 105, 109, 149, 147, 147, 202, 0, 0, 0, 0, 202, 0, 0, 0, 0, 202, 0,
0, 0, 0, 147, 202, 63, 128, 0, 0, 202, 0, 0, 0, 0, 202, 0, 0, 0, 0, 147, 202, 0, 0,
0, 0, 202, 63, 128, 0, 0, 202, 0, 0, 0, 0, 147, 147, 202, 0, 0, 0, 0, 202, 0, 0, 0,
0, 202, 63, 128, 0, 0, 147, 202, 0, 0, 0, 0, 202, 0, 0, 0, 0, 202, 63, 128, 0, 0,
147, 202, 0, 0, 0, 0, 202, 0, 0, 0, 0, 202, 63, 128, 0, 0, 147, 146, 202, 0, 0, 0,
0, 202, 0, 0, 0, 0, 146, 202, 63, 128, 0, 0, 202, 0, 0, 0, 0, 146, 202, 0, 0, 0, 0,
202, 63, 128, 0, 0, 147, 0, 1, 2, 145, 7, 192, 1, 0, 0, 207, 1, 35, 69, 103, 137,
171, 205, 239, 195
]
);
assert_eq!(
GeometryDomainDocument::from_msgpack(&domain.to_msgpack().unwrap()).unwrap(),
domain
);
assert_eq!(
GeometryChunkArtifact::from_msgpack(&chunk.to_msgpack().unwrap()).unwrap(),
chunk
);
assert_eq!(
GeometryBuildRequest::from_msgpack(&request.to_msgpack().unwrap()).unwrap(),
request
);
assert_eq!(
GeometrySelectedCutManifest::from_msgpack(&cut.to_msgpack().unwrap()).unwrap(),
cut
);
}
#[test]
fn scalar_bit_identity_is_stable_through_messagepack() {
let mut signed_zero = request();
signed_zero.6 = -0.0;
signed_zero.7 = f32::from_bits(0x7fc0_1234);
signed_zero.8 = f32::NEG_INFINITY;
assert_eq!(
signed_zero.record_key(),
"geometry:request:978dd0913fc3e12c04766e065320d485d172d60d61be920a9a32637d1c439c81"
);
let decoded =
GeometryBuildRequest::from_msgpack(&signed_zero.to_msgpack().unwrap()).unwrap();
assert_eq!(decoded.6.to_bits(), 0x8000_0000);
assert_eq!(decoded.7.to_bits(), 0x7fc0_1234);
assert_eq!(decoded.8.to_bits(), f32::NEG_INFINITY.to_bits());
}
}

View file

@ -206,9 +206,9 @@ namespace GameCult.Geometry
StableVector(request.CameraPosition),
StableVector(request.FrustumMin),
StableVector(request.FrustumMax),
request.ViewportHeightPixels.ToString("R", CultureInfo.InvariantCulture),
request.VerticalFovRadians.ToString("R", CultureInfo.InvariantCulture),
request.TargetError.ToString("R", CultureInfo.InvariantCulture),
StableFloat(request.ViewportHeightPixels),
StableFloat(request.VerticalFovRadians),
StableFloat(request.TargetError),
request.TriangleBudget.ToString(CultureInfo.InvariantCulture),
request.ColliderBudget.ToString(CultureInfo.InvariantCulture),
StableArray(request.SemanticFilter),

View file

@ -0,0 +1,153 @@
using System;
using CultMath;
using FluentAssertions;
using GameCult.Caching.MessagePack;
using NUnit.Framework;
namespace GameCult.Geometry.Tests;
public sealed class GeometryV2WireParityTests
{
private const string DomainHex = "95AE666978747572652D646F6D61696EAC666978747572652F726F6F74B467616D6563756C742D67656F6D657472792D727397A4726F6F74A4526F6F7493CA3F800000CAC0200000CA0000000094CA00000000CA00000000CA00000000CA3F8000002A9090B4323032362D30372D32325430303A30303A30305A";
private const string RequestHex = "9FAF726571756573742D66697874757265D95067656F6D657472793A646F6D61696E3A35303563393465373339333538306134653562303438623136396161346461393535646136303666666432386330353462373636613462393465353035303265A7776F726B65727393CA3F800000CA40000000CA4040000093CAC0800000CAC0A00000CAC0C0000093CA40800000CA40A00000CA40C00000CA44870000CA3F800000CA3E800000643291A4526F6F749090B4323032362D30372D32325430303A30303A30315A";
private const string CutHex = "96AB6375742D66697874757265B867656F6D657472793A726571756573743A6669787475726591AC666978747572652F726F6F74909090";
private const string ChunkHex = "9EAD666978747572652F6368756E6BB467656F6D657472793A6375743A66697874757265AB6375742D6669787475726593CABF800000CAC0000000CAC040000093CA3F800000CA40000000CA4040000091AC666978747572652F726F6F7491B2666978747572652F726F6F742F636C61696D959393CA00000000CA00000000CA0000000093CA3F800000CA00000000CA0000000093CA00000000CA3F800000CA000000009393CA00000000CA00000000CA3F80000093CA00000000CA00000000CA3F80000093CA00000000CA00000000CA3F8000009392CA00000000CA0000000092CA3F800000CA0000000092CA00000000CA3F800000930001029107C0010000CF0123456789ABCDEFC3";
[Test]
public void Domain_MatchesRustV2BytesAndKey()
{
var document = Domain();
AssertWire(document, DomainHex);
CultGeometryDomainDocument.CreateRecordKey(document).Value.Should().Be(
"geometry:domain:505c94e7393580a4e5b048b169aa4da955da606ffd28c054b766a4b94e50502e");
}
[Test]
public void BuildRequest_MatchesRustV2BytesAndKey()
{
var document = Request();
AssertWire(document, RequestHex);
CultGeometryBuildRequest.CreateRecordKey(document).Value.Should().Be(
"geometry:request:36e25b80c04a6c54c8b3137abb4a8c961468a9b1c0e7dd4d5632cf5a6f847966");
}
[Test]
public void SelectedCut_MatchesRustV2BytesAndKey()
{
var document = Cut();
AssertWire(document, CutHex);
CultGeometrySelectedCutManifest.CreateRecordKey(document).Value.Should().Be(
"geometry:cut:5614eae3fe2a17dca651d1e32f401c50e1c3b9cf941f5789655990325da64fb3");
}
[Test]
public void Chunk_MatchesRustV2BytesAndKey()
{
var document = Chunk();
AssertWire(document, ChunkHex);
CultGeometryChunkArtifact.CreateRecordKey(document).Value.Should().Be(
"geometry:chunk:ca2874d3638800179c906087ec817ea715c43b70b99ead04edccce2a1b3d6ebb");
}
[Test]
public void BuildRequest_ScalarIdentityUsesExactIeeeBits()
{
var document = Request();
document.ViewportHeightPixels = -0f;
document.VerticalFovRadians = BitConverter.Int32BitsToSingle(unchecked((int)0x7fc01234));
document.TargetError = float.NegativeInfinity;
CultGeometryBuildRequest.CreateRecordKey(document).Value.Should().Be(
"geometry:request:978dd0913fc3e12c04766e065320d485d172d60d61be920a9a32637d1c439c81");
var payload = CultDocumentMessagePackSerialization.Serialize(document);
var decoded = CultDocumentMessagePackSerialization.Deserialize<CultGeometryBuildRequest>(payload);
BitConverter.SingleToInt32Bits(decoded.ViewportHeightPixels).Should().Be(unchecked((int)0x80000000));
BitConverter.SingleToInt32Bits(decoded.VerticalFovRadians).Should().Be(unchecked((int)0x7fc01234));
BitConverter.SingleToInt32Bits(decoded.TargetError).Should().Be(unchecked((int)0xff800000));
}
private static void AssertWire<T>(T document, string expectedHex)
{
var payload = CultDocumentMessagePackSerialization.Serialize(document);
Convert.ToHexString(payload).Should().Be(expectedHex);
var decoded = CultDocumentMessagePackSerialization.Deserialize<T>(payload);
Convert.ToHexString(CultDocumentMessagePackSerialization.Serialize(decoded)).Should().Be(expectedHex);
var rustPayload = Convert.FromHexString(expectedHex);
var decodedFromRust = CultDocumentMessagePackSerialization.Deserialize<T>(rustPayload);
Convert.ToHexString(CultDocumentMessagePackSerialization.Serialize(decodedFromRust)).Should().Be(expectedHex);
}
private static CultGeometryDomainDocument Domain() => new()
{
DomainId = "fixture-domain",
RootKey = "fixture/root",
SourceRuntime = "gamecult-geometry-rs",
Root = new CultGeometryDomainNode
{
Name = "root",
Kind = "Root",
Translation = new float3(1f, -2.5f, 0f),
Rotation = quaternion.identity,
Seed = 42,
Claims = [],
Children = [],
},
CreatedAt = "2026-07-22T00:00:00Z",
};
private static CultGeometryBuildRequest Request() => new()
{
RequestId = "request-fixture",
DomainKey = CultGeometryDomainDocument.CreateRecordKey(Domain()).Value,
WorkerGroup = "workers",
CameraPosition = new float3(1f, 2f, 3f),
FrustumMin = new float3(-4f, -5f, -6f),
FrustumMax = new float3(4f, 5f, 6f),
ViewportHeightPixels = 1080f,
VerticalFovRadians = 1f,
TargetError = 0.25f,
TriangleBudget = 100,
ColliderBudget = 50,
SemanticFilter = ["Root"],
RequestedChunkKeys = [],
DirtyDomainKeys = [],
CreatedAt = "2026-07-22T00:00:01Z",
};
private static CultGeometrySelectedCutManifest Cut() => new()
{
CutId = "cut-fixture",
RequestKey = "geometry:request:fixture",
SelectedNodes = ["fixture/root"],
DeferredChildRequests = [],
ParentFallbackNodes = [],
Diagnostics = [],
};
private static CultGeometryChunkArtifact Chunk() => new()
{
ChunkId = "fixture/chunk",
CutKey = "geometry:cut:fixture",
SelectedCutId = "cut-fixture",
BoundsMin = new float3(-1f, -2f, -3f),
BoundsMax = new float3(1f, 2f, 3f),
SourceDomainKeys = ["fixture/root"],
SourceClaimKeys = ["fixture/root/claim"],
RenderMesh = new CultGeometryTriangleMesh
{
Positions = [new float3(0f, 0f, 0f), new float3(1f, 0f, 0f), new float3(0f, 1f, 0f)],
Normals = [new float3(0f, 0f, 1f), new float3(0f, 0f, 1f), new float3(0f, 0f, 1f)],
Uvs = [new float2(0f, 0f), new float2(1f, 0f), new float2(0f, 1f)],
Indices = [0, 1, 2],
TriangleMaterials = [7],
},
ColliderMesh = null,
InputBrushes = 1,
CandidatePairs = 0,
RejectedPairs = 0,
StableClipSeed = 0x0123_4567_89ab_cdef,
SupportsParentChildCoexistence = true,
};
}