avatar: split avatar.rs tests into avatar_tests files
- Commit
9996e7a471cfef405603144af51a1e1a3e028859- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 22:06 UTC (4 days ago)
- Parents
50cc091
avatar.rs was 504 lines, the only non-generated, non-test, non-example Rust source file in the workspace still over the 500-line Rust file limit. Its two inline test modules (avatar::tests, avatar::tests_extra, ~245 lines) are its natural seam: they already were separate modules with their own imports. Move both test bodies verbatim (dedented, plus a doc header) into avatar_tests.rs (109 lines) and avatar_tests_extra.rs (137 lines), declared from avatar.rs with #[cfg(test)] #[path] so the module paths avatar::tests / avatar::tests_extra and every test name are unchanged. avatar.rs drops to 265 lines. This follows the crate's existing split pattern (lib.rs + lib_tests.rs, engine/mesh include! parts). No production code moves; the public items of avatar.rs are byte-identical (grep parity checked). Verified: cargo test -p yuu_avatar 90 passed (same count and avatar:: test names as before), cargo clippy -p yuu_avatar --all-targets clean, cargo fmt -p yuu_avatar --check clean, structure line ratchet OK. AGENTS.md key-files updated.
Diff
library/avatar/AGENTS.md
diff --git a/library/avatar/AGENTS.md b/library/avatar/AGENTS.mdindex 038fd69442..e81cb9914c 100644--- a/library/avatar/AGENTS.md+++ b/library/avatar/AGENTS.md@@ -38,7 +38,7 @@ _Install: dev by default (library, no launcher)._ - com/vayunmathur/library/avatar/components/YuuAvatar3D.kt - com/vayunmathur/library/avatar/yuu/YuuPose.kt ### Rust — engine crate (see src/main/rust/AGENTS.md for the skeleton contract)-- src/main/rust/src/avatar.rs — joints, traits, poses, FK+- src/main/rust/src/avatar.rs — joints, traits, poses, FK (tests in `avatar_tests.rs` / `avatar_tests_extra.rs`, same `avatar::tests` / `avatar::tests_extra` modules via `#[path]`) - src/main/rust/src/engine.rs — per-surface lifecycle + camera - src/main/rust/src/mesh.rs — procedural fallback + glTF loader - src/main/rust/src/lib.rs — JNI entry points
library/avatar/src/main/rust/src/avatar.rs
diff --git a/library/avatar/src/main/rust/src/avatar.rs b/library/avatar/src/main/rust/src/avatar.rsindex f4a973894e..c349d3abe3 100644--- a/library/avatar/src/main/rust/src/avatar.rs+++ b/library/avatar/src/main/rust/src/avatar.rs@@ -257,248 +257,9 @@ fn rest_world_matrices() -> [Mat4; MAX_BONES] { } #[cfg(test)]-mod tests {- use super::*;- use crate::pose::YuuPose;- use crate::traits::YuuTraits;- use std::collections::HashMap;-- #[test]- fn skeleton_order_is_topological() {- for (i, joint) in ALL_JOINTS.iter().copied().enumerate() {- if let Some(p) = parent_of(joint) {- let pi = ALL_JOINTS.iter().position(|j| *j == p).unwrap();- assert!(pi < i);- }- }- }-- #[test]- fn idle_pose_is_identity_at_origin() {- let traits = YuuTraits::default();- let pose = YuuPose { id: "idle".into(), name: "Idle".into(), joints: HashMap::new() };- let bones = compute_bone_matrices(&traits, &pose, 0.0);- // Root stays at origin (sway is ~0 at t=0).- let t = bones[Joint::Root as usize].transform_point3(glam::Vec3::ZERO);- assert!(t.length() < 1e-5);- }-- #[test]- fn idle_bones_hold_model_space_points() {- // Regression: bone matrices must include the inverse bind pose, so an- // idle skeleton leaves model-space vertices where authored. (Without- // it, every part renders double-transformed — scattered/exploded.)- let traits = YuuTraits::default();- let pose = YuuPose { id: "idle".into(), name: "Idle".into(), joints: HashMap::new() };- let bones = compute_bone_matrices(&traits, &pose, 0.0);- // Head-center vertex (bound fully to head) must stay at its authored- // position under the idle pose.- let head_m = bones[Joint::Head as usize];- let p = head_m.transform_point3(glam::Vec3::new(0.0, 1.28, 0.0));- assert!((p - glam::Vec3::new(0.0, 1.28, 0.0)).length() < 1e-3, "head drifted to {p:?}");- // Hand-center vertex (bound fully to hand) likewise.- let hand_m = bones[Joint::HandR as usize];- let q = hand_m.transform_point3(glam::Vec3::new(0.31, 0.34, 0.0));- assert!((q - glam::Vec3::new(0.31, 0.34, 0.0)).length() < 1e-3, "hand drifted to {q:?}");- }-- #[test]- fn traits_parse_leniently() {- let t = YuuTraits::from_config_json("{}");- assert_eq!(t.body_height, 0.5);- let bad = YuuTraits::from_config_json("not json");- assert_eq!(bad.body_height, 0.5);- }-- #[test]- fn traits_parse_kotlin_camel_case() {- // Regression: Kotlin emits camelCase keys (YuuFaceConfig.encode()).- // Before the alias bridge these all silently defaulted, so no slider- // or selection ever reached the engine.- let json = r#"{"faceShape":5,"skinTone":4293457546,"bodyHeight":0.8,"bodyWeight":0.2,"hairStyle":3,"hairColor":4284510252}"#;- let t = YuuTraits::from_config_json(json);- assert_eq!(t.face_shape, 5);- assert_eq!(t.skin_tone, 4293457546);- assert!((t.body_height - 0.8).abs() < 1e-6);- assert!((t.body_weight - 0.2).abs() < 1e-6);- assert_eq!(t.hair_style, 3);- assert_eq!(t.hair_color, 4284510252);- }-- #[test]- fn traits_parse_full_kotlin_config() {- // Full 29-field Kotlin-shaped fixture: every field must parse (no- // silent drops), and the bone-driving subset must affect matrices.- let json = r#"{"faceShape":2,"skinTone":4293457546,"earSize":0.7,"bodyHeight":0.8,"bodyWeight":0.2,"hairStyle":3,"hairColor":4284510252,"eyeStyle":4,"eyeColor":4284510253,"eyeSize":0.6,"eyeSpacing":0.4,"eyeHeight":0.7,"eyeRotation":0.3,"browStyle":2,"browColor":4284510254,"browHeight":0.6,"browRotation":0.4,"noseStyle":3,"noseHeight":0.8,"mouthStyle":5,"mouthColor":4284510255,"mouthSize":0.7,"mouthHeight":0.3,"glassesStyle":2,"beardStyle":1,"moleStyle":1,"wrinkleStyle":2,"blushStyle":1,"poseId":"wave"}"#;- let t = YuuTraits::from_config_json(json);- assert_eq!(t.face_shape, 2);- assert_eq!(t.skin_tone, 4293457546);- assert!((t.ear_size - 0.7).abs() < 1e-6);- assert!((t.body_height - 0.8).abs() < 1e-6);- assert!((t.body_weight - 0.2).abs() < 1e-6);- assert_eq!(t.hair_style, 3);- assert_eq!(t.hair_color, 4284510252);- assert_eq!(t.eye_style, 4);- assert_eq!(t.eye_color, 4284510253);- assert!((t.eye_size - 0.6).abs() < 1e-6);- assert!((t.eye_spacing - 0.4).abs() < 1e-6);- assert!((t.eye_height - 0.7).abs() < 1e-6);- assert!((t.eye_rotation - 0.3).abs() < 1e-6);- assert_eq!(t.brow_style, 2);- assert_eq!(t.brow_color, 4284510254);- assert!((t.brow_height - 0.6).abs() < 1e-6);- assert!((t.brow_rotation - 0.4).abs() < 1e-6);- assert_eq!(t.nose_style, 3);- assert!((t.nose_height - 0.8).abs() < 1e-6);- assert_eq!(t.mouth_style, 5);- assert_eq!(t.mouth_color, 4284510255);- assert!((t.mouth_size - 0.7).abs() < 1e-6);- assert!((t.mouth_height - 0.3).abs() < 1e-6);- assert_eq!(t.glasses_style, 2);- assert_eq!(t.beard_style, 1);- assert_eq!(t.mole_style, 1);- assert_eq!(t.wrinkle_style, 2);- assert_eq!(t.blush_style, 1);- assert_eq!(t.pose_id.as_deref(), Some("wave"));- // Bone-driving subset spot-check: bodyHeight 0.8 → taller spine.- assert!((t.height_scale() - 1.06).abs() < 1e-6);- assert!((t.weight_scale() - 0.91).abs() < 1e-6);- }-}+#[path = "avatar_tests.rs"]+mod tests; #[cfg(test)]-mod tests_extra {- use super::*;- use crate::pose::{preset_by_id, JointRotation, YuuPose};- use crate::traits::YuuTraits;- use std::collections::HashMap;-- fn idle() -> YuuPose {- YuuPose { id: "idle".into(), name: "Idle".into(), joints: HashMap::new() }- }-- // `MAX_BONES >= JOINT_COUNT` relates two consts: it is an- // invariant guard that fires if either is retuned, so the- // constant assertion is intentional.- #[allow(clippy::assertions_on_constants)]- #[test]- fn name_roundtrip_and_discriminants_match_ubo_order() {- for (i, joint) in ALL_JOINTS.iter().copied().enumerate() {- assert_eq!(joint as usize, i, "UBO discriminant drifted for {joint:?}");- assert_eq!(joint_by_name(joint_name(joint)), Some(joint));- }- assert_eq!(JOINT_COUNT, 13);- assert_eq!(ALL_JOINTS.len(), JOINT_COUNT);- assert!(MAX_BONES >= JOINT_COUNT);- for bad in ["", "Head", "head ", "clavicle_l", "unknown"] {- assert_eq!(joint_by_name(bad), None, "{bad:?}");- }- }-- #[test]- fn parent_children_are_mutually_consistent() {- let mut edges = 0;- for joint in ALL_JOINTS {- for child in children_of(joint) {- assert_eq!(parent_of(*child), Some(joint), "{child:?}");- edges += 1;- }- if let Some(parent) = parent_of(joint) {- assert!(children_of(parent).contains(&joint), "{joint:?}");- }- }- assert_eq!(edges, JOINT_COUNT - 1, "skeleton must be a single tree");- assert_eq!(parent_of(Joint::Root), None);- assert!(children_of(Joint::Head).is_empty());- assert!(children_of(Joint::HandL).is_empty() && children_of(Joint::HandR).is_empty());- assert_eq!(children_of(Joint::Chest), &[Joint::Neck, Joint::ClavicleL, Joint::ClavicleR]);- }-- #[test]- fn rest_offsets_are_mirror_symmetric_and_form_chains() {- assert_eq!(rest_offset(Joint::Root), Vec3::ZERO);- for (l, r) in [- (Joint::ClavicleL, Joint::ClavicleR),- (Joint::UpperArmL, Joint::UpperArmR),- (Joint::ForearmL, Joint::ForearmR),- (Joint::HandL, Joint::HandR),- ] {- let (a, b) = (rest_offset(l), rest_offset(r));- assert_eq!(a.x, -b.x, "{l:?}/{r:?} x must mirror");- assert_eq!((a.y, a.z), (b.y, b.z));- }- // Head chain accumulates upward; arms hang downward from the clavicles.- let torso_y: f32 = [Joint::Spine, Joint::Chest, Joint::Neck, Joint::Head]- .iter()- .map(|j| rest_offset(*j).y)- .sum();- assert!((torso_y - 1.19).abs() < 1e-6, "head joint rest height {torso_y}");- assert!(rest_offset(Joint::ForearmL).y < 0.0 && rest_offset(Joint::HandR).y < 0.0);- }-- #[test]- fn bones_beyond_joint_count_are_identity_and_all_finite() {- for pose_id in ["idle", "wave", "thumbs_up", "thinking", "cheering"] {- let pose = preset_by_id(pose_id).expect("preset");- let bones = compute_bone_matrices(&YuuTraits::default(), &pose, 0.37);- for (i, m) in bones.iter().enumerate() {- assert!(m.to_cols_array().iter().all(|v| v.is_finite()), "{pose_id} bone {i}");- if i >= JOINT_COUNT {- assert_eq!(*m, Mat4::IDENTITY, "padding bone {i} must stay identity");- }- }- }- }-- #[test]- fn compute_is_deterministic_and_unknown_pose_joints_are_ignored() {- let mut pose = idle();- pose.joints.insert("not_a_joint".into(), JointRotation { x: 45.0, y: 0.0, z: 0.0 });- pose.joints.insert("head".into(), JointRotation { x: 0.0, y: 30.0, z: 0.0 });- let a = compute_bone_matrices(&YuuTraits::default(), &pose, 0.0);- let b = compute_bone_matrices(&YuuTraits::default(), &pose, 0.0);- assert_eq!(a, b);- // Head rotation actually moves the head bone vs idle.- let plain = compute_bone_matrices(&YuuTraits::default(), &idle(), 0.0);- assert_ne!(a[Joint::Head as usize], plain[Joint::Head as usize]);- }-- #[test]- fn taller_traits_raise_and_heavier_traits_widen_skinning() {- let short = YuuTraits { body_height: 0.0, ..Default::default() };- let tall = YuuTraits { body_height: 1.0, ..Default::default() };- let head_pt = Vec3::new(0.0, 1.28, 0.0);- let y = |t: &YuuTraits| {- compute_bone_matrices(t, &idle(), 0.0)[Joint::Head as usize].transform_point3(head_pt).y- };- assert!(y(&tall) > y(&short) + 0.05, "tall {} vs short {}", y(&tall), y(&short));- let lean = YuuTraits { body_weight: 0.0, ..Default::default() };- let heavy = YuuTraits { body_weight: 1.0, ..Default::default() };- let hand_pt = Vec3::new(0.31, 0.34, 0.0);- let x = |t: &YuuTraits| {- compute_bone_matrices(t, &idle(), 0.0)[Joint::HandR as usize]- .transform_point3(hand_pt)- .x- .abs()- };- assert!(x(&heavy) > x(&lean), "heavy {} vs lean {}", x(&heavy), x(&lean));- }-- #[test]- fn head_scale_applies_and_idle_sway_is_small_and_periodic_in_effect() {- let wide = YuuTraits { face_shape: 7, ..Default::default() };- let bones = compute_bone_matrices(&wide, &idle(), 0.0);- let p = bones[Joint::Head as usize].transform_point3(Vec3::new(0.1, 1.28, 0.0));- // Head-local +x point is scaled by head_scale().x = 1.12 about the head origin.- assert!(p.x > 0.1, "scaled head point {p:?}");- // Sway at t=0 is zero; a quarter period later the root bone has rotated- // but a point on the rotation axis (origin) stays put.- let t_quarter = std::f32::consts::FRAC_PI_2 / 1.2;- let swayed = compute_bone_matrices(&YuuTraits::default(), &idle(), t_quarter);- let origin = swayed[Joint::Root as usize].transform_point3(Vec3::ZERO);- assert!(origin.length() < 1e-5);- let off_axis = swayed[Joint::Root as usize].transform_point3(Vec3::new(1.0, 0.0, 0.0));- assert!((off_axis - Vec3::new(1.0, 0.0, 0.0)).length() > 1e-4, "sway must rotate");- assert!((off_axis - Vec3::new(1.0, 0.0, 0.0)).length() < 0.05, "sway must stay gentle");- }-}+#[path = "avatar_tests_extra.rs"]+mod tests_extra;
library/avatar/src/main/rust/src/avatar_tests.rs
diff --git a/library/avatar/src/main/rust/src/avatar_tests.rs b/library/avatar/src/main/rust/src/avatar_tests.rsnew file mode 100644index 0000000000..d362069005--- /dev/null+++ b/library/avatar/src/main/rust/src/avatar_tests.rs@@ -0,0 +1,109 @@+//! Tests for `avatar.rs` (skeleton, trait mapping, forward kinematics).+//! Split out of `avatar.rs` to keep that file under the 500-line Rust limit;+//! module path `avatar::tests` is unchanged.+use super::*;+use crate::pose::YuuPose;+use crate::traits::YuuTraits;+use std::collections::HashMap;++#[test]+fn skeleton_order_is_topological() {+ for (i, joint) in ALL_JOINTS.iter().copied().enumerate() {+ if let Some(p) = parent_of(joint) {+ let pi = ALL_JOINTS.iter().position(|j| *j == p).unwrap();+ assert!(pi < i);+ }+ }+}++#[test]+fn idle_pose_is_identity_at_origin() {+ let traits = YuuTraits::default();+ let pose = YuuPose { id: "idle".into(), name: "Idle".into(), joints: HashMap::new() };+ let bones = compute_bone_matrices(&traits, &pose, 0.0);+ // Root stays at origin (sway is ~0 at t=0).+ let t = bones[Joint::Root as usize].transform_point3(glam::Vec3::ZERO);+ assert!(t.length() < 1e-5);+}++#[test]+fn idle_bones_hold_model_space_points() {+ // Regression: bone matrices must include the inverse bind pose, so an+ // idle skeleton leaves model-space vertices where authored. (Without+ // it, every part renders double-transformed — scattered/exploded.)+ let traits = YuuTraits::default();+ let pose = YuuPose { id: "idle".into(), name: "Idle".into(), joints: HashMap::new() };+ let bones = compute_bone_matrices(&traits, &pose, 0.0);+ // Head-center vertex (bound fully to head) must stay at its authored+ // position under the idle pose.+ let head_m = bones[Joint::Head as usize];+ let p = head_m.transform_point3(glam::Vec3::new(0.0, 1.28, 0.0));+ assert!((p - glam::Vec3::new(0.0, 1.28, 0.0)).length() < 1e-3, "head drifted to {p:?}");+ // Hand-center vertex (bound fully to hand) likewise.+ let hand_m = bones[Joint::HandR as usize];+ let q = hand_m.transform_point3(glam::Vec3::new(0.31, 0.34, 0.0));+ assert!((q - glam::Vec3::new(0.31, 0.34, 0.0)).length() < 1e-3, "hand drifted to {q:?}");+}++#[test]+fn traits_parse_leniently() {+ let t = YuuTraits::from_config_json("{}");+ assert_eq!(t.body_height, 0.5);+ let bad = YuuTraits::from_config_json("not json");+ assert_eq!(bad.body_height, 0.5);+}++#[test]+fn traits_parse_kotlin_camel_case() {+ // Regression: Kotlin emits camelCase keys (YuuFaceConfig.encode()).+ // Before the alias bridge these all silently defaulted, so no slider+ // or selection ever reached the engine.+ let json = r#"{"faceShape":5,"skinTone":4293457546,"bodyHeight":0.8,"bodyWeight":0.2,"hairStyle":3,"hairColor":4284510252}"#;+ let t = YuuTraits::from_config_json(json);+ assert_eq!(t.face_shape, 5);+ assert_eq!(t.skin_tone, 4293457546);+ assert!((t.body_height - 0.8).abs() < 1e-6);+ assert!((t.body_weight - 0.2).abs() < 1e-6);+ assert_eq!(t.hair_style, 3);+ assert_eq!(t.hair_color, 4284510252);+}++#[test]+fn traits_parse_full_kotlin_config() {+ // Full 29-field Kotlin-shaped fixture: every field must parse (no+ // silent drops), and the bone-driving subset must affect matrices.+ let json = r#"{"faceShape":2,"skinTone":4293457546,"earSize":0.7,"bodyHeight":0.8,"bodyWeight":0.2,"hairStyle":3,"hairColor":4284510252,"eyeStyle":4,"eyeColor":4284510253,"eyeSize":0.6,"eyeSpacing":0.4,"eyeHeight":0.7,"eyeRotation":0.3,"browStyle":2,"browColor":4284510254,"browHeight":0.6,"browRotation":0.4,"noseStyle":3,"noseHeight":0.8,"mouthStyle":5,"mouthColor":4284510255,"mouthSize":0.7,"mouthHeight":0.3,"glassesStyle":2,"beardStyle":1,"moleStyle":1,"wrinkleStyle":2,"blushStyle":1,"poseId":"wave"}"#;+ let t = YuuTraits::from_config_json(json);+ assert_eq!(t.face_shape, 2);+ assert_eq!(t.skin_tone, 4293457546);+ assert!((t.ear_size - 0.7).abs() < 1e-6);+ assert!((t.body_height - 0.8).abs() < 1e-6);+ assert!((t.body_weight - 0.2).abs() < 1e-6);+ assert_eq!(t.hair_style, 3);+ assert_eq!(t.hair_color, 4284510252);+ assert_eq!(t.eye_style, 4);+ assert_eq!(t.eye_color, 4284510253);+ assert!((t.eye_size - 0.6).abs() < 1e-6);+ assert!((t.eye_spacing - 0.4).abs() < 1e-6);+ assert!((t.eye_height - 0.7).abs() < 1e-6);+ assert!((t.eye_rotation - 0.3).abs() < 1e-6);+ assert_eq!(t.brow_style, 2);+ assert_eq!(t.brow_color, 4284510254);+ assert!((t.brow_height - 0.6).abs() < 1e-6);+ assert!((t.brow_rotation - 0.4).abs() < 1e-6);+ assert_eq!(t.nose_style, 3);+ assert!((t.nose_height - 0.8).abs() < 1e-6);+ assert_eq!(t.mouth_style, 5);+ assert_eq!(t.mouth_color, 4284510255);+ assert!((t.mouth_size - 0.7).abs() < 1e-6);+ assert!((t.mouth_height - 0.3).abs() < 1e-6);+ assert_eq!(t.glasses_style, 2);+ assert_eq!(t.beard_style, 1);+ assert_eq!(t.mole_style, 1);+ assert_eq!(t.wrinkle_style, 2);+ assert_eq!(t.blush_style, 1);+ assert_eq!(t.pose_id.as_deref(), Some("wave"));+ // Bone-driving subset spot-check: bodyHeight 0.8 → taller spine.+ assert!((t.height_scale() - 1.06).abs() < 1e-6);+ assert!((t.weight_scale() - 0.91).abs() < 1e-6);+}
library/avatar/src/main/rust/src/avatar_tests_extra.rs
diff --git a/library/avatar/src/main/rust/src/avatar_tests_extra.rs b/library/avatar/src/main/rust/src/avatar_tests_extra.rsnew file mode 100644index 0000000000..4f1976fc2c--- /dev/null+++ b/library/avatar/src/main/rust/src/avatar_tests_extra.rs@@ -0,0 +1,137 @@+//! Additional coverage tests for `avatar.rs` (name round-trip, skeleton+//! consistency, bone-matrix invariants). Split out of `avatar.rs` to keep+//! that file under the 500-line Rust limit; module path+//! `avatar::tests_extra` is unchanged.+use super::*;+use crate::pose::{preset_by_id, JointRotation, YuuPose};+use crate::traits::YuuTraits;+use std::collections::HashMap;++fn idle() -> YuuPose {+ YuuPose { id: "idle".into(), name: "Idle".into(), joints: HashMap::new() }+}++// `MAX_BONES >= JOINT_COUNT` relates two consts: it is an+// invariant guard that fires if either is retuned, so the+// constant assertion is intentional.+#[allow(clippy::assertions_on_constants)]+#[test]+fn name_roundtrip_and_discriminants_match_ubo_order() {+ for (i, joint) in ALL_JOINTS.iter().copied().enumerate() {+ assert_eq!(joint as usize, i, "UBO discriminant drifted for {joint:?}");+ assert_eq!(joint_by_name(joint_name(joint)), Some(joint));+ }+ assert_eq!(JOINT_COUNT, 13);+ assert_eq!(ALL_JOINTS.len(), JOINT_COUNT);+ assert!(MAX_BONES >= JOINT_COUNT);+ for bad in ["", "Head", "head ", "clavicle_l", "unknown"] {+ assert_eq!(joint_by_name(bad), None, "{bad:?}");+ }+}++#[test]+fn parent_children_are_mutually_consistent() {+ let mut edges = 0;+ for joint in ALL_JOINTS {+ for child in children_of(joint) {+ assert_eq!(parent_of(*child), Some(joint), "{child:?}");+ edges += 1;+ }+ if let Some(parent) = parent_of(joint) {+ assert!(children_of(parent).contains(&joint), "{joint:?}");+ }+ }+ assert_eq!(edges, JOINT_COUNT - 1, "skeleton must be a single tree");+ assert_eq!(parent_of(Joint::Root), None);+ assert!(children_of(Joint::Head).is_empty());+ assert!(children_of(Joint::HandL).is_empty() && children_of(Joint::HandR).is_empty());+ assert_eq!(children_of(Joint::Chest), &[Joint::Neck, Joint::ClavicleL, Joint::ClavicleR]);+}++#[test]+fn rest_offsets_are_mirror_symmetric_and_form_chains() {+ assert_eq!(rest_offset(Joint::Root), Vec3::ZERO);+ for (l, r) in [+ (Joint::ClavicleL, Joint::ClavicleR),+ (Joint::UpperArmL, Joint::UpperArmR),+ (Joint::ForearmL, Joint::ForearmR),+ (Joint::HandL, Joint::HandR),+ ] {+ let (a, b) = (rest_offset(l), rest_offset(r));+ assert_eq!(a.x, -b.x, "{l:?}/{r:?} x must mirror");+ assert_eq!((a.y, a.z), (b.y, b.z));+ }+ // Head chain accumulates upward; arms hang downward from the clavicles.+ let torso_y: f32 = [Joint::Spine, Joint::Chest, Joint::Neck, Joint::Head]+ .iter()+ .map(|j| rest_offset(*j).y)+ .sum();+ assert!((torso_y - 1.19).abs() < 1e-6, "head joint rest height {torso_y}");+ assert!(rest_offset(Joint::ForearmL).y < 0.0 && rest_offset(Joint::HandR).y < 0.0);+}++#[test]+fn bones_beyond_joint_count_are_identity_and_all_finite() {+ for pose_id in ["idle", "wave", "thumbs_up", "thinking", "cheering"] {+ let pose = preset_by_id(pose_id).expect("preset");+ let bones = compute_bone_matrices(&YuuTraits::default(), &pose, 0.37);+ for (i, m) in bones.iter().enumerate() {+ assert!(m.to_cols_array().iter().all(|v| v.is_finite()), "{pose_id} bone {i}");+ if i >= JOINT_COUNT {+ assert_eq!(*m, Mat4::IDENTITY, "padding bone {i} must stay identity");+ }+ }+ }+}++#[test]+fn compute_is_deterministic_and_unknown_pose_joints_are_ignored() {+ let mut pose = idle();+ pose.joints.insert("not_a_joint".into(), JointRotation { x: 45.0, y: 0.0, z: 0.0 });+ pose.joints.insert("head".into(), JointRotation { x: 0.0, y: 30.0, z: 0.0 });+ let a = compute_bone_matrices(&YuuTraits::default(), &pose, 0.0);+ let b = compute_bone_matrices(&YuuTraits::default(), &pose, 0.0);+ assert_eq!(a, b);+ // Head rotation actually moves the head bone vs idle.+ let plain = compute_bone_matrices(&YuuTraits::default(), &idle(), 0.0);+ assert_ne!(a[Joint::Head as usize], plain[Joint::Head as usize]);+}++#[test]+fn taller_traits_raise_and_heavier_traits_widen_skinning() {+ let short = YuuTraits { body_height: 0.0, ..Default::default() };+ let tall = YuuTraits { body_height: 1.0, ..Default::default() };+ let head_pt = Vec3::new(0.0, 1.28, 0.0);+ let y = |t: &YuuTraits| {+ compute_bone_matrices(t, &idle(), 0.0)[Joint::Head as usize].transform_point3(head_pt).y+ };+ assert!(y(&tall) > y(&short) + 0.05, "tall {} vs short {}", y(&tall), y(&short));+ let lean = YuuTraits { body_weight: 0.0, ..Default::default() };+ let heavy = YuuTraits { body_weight: 1.0, ..Default::default() };+ let hand_pt = Vec3::new(0.31, 0.34, 0.0);+ let x = |t: &YuuTraits| {+ compute_bone_matrices(t, &idle(), 0.0)[Joint::HandR as usize]+ .transform_point3(hand_pt)+ .x+ .abs()+ };+ assert!(x(&heavy) > x(&lean), "heavy {} vs lean {}", x(&heavy), x(&lean));+}++#[test]+fn head_scale_applies_and_idle_sway_is_small_and_periodic_in_effect() {+ let wide = YuuTraits { face_shape: 7, ..Default::default() };+ let bones = compute_bone_matrices(&wide, &idle(), 0.0);+ let p = bones[Joint::Head as usize].transform_point3(Vec3::new(0.1, 1.28, 0.0));+ // Head-local +x point is scaled by head_scale().x = 1.12 about the head origin.+ assert!(p.x > 0.1, "scaled head point {p:?}");+ // Sway at t=0 is zero; a quarter period later the root bone has rotated+ // but a point on the rotation axis (origin) stays put.+ let t_quarter = std::f32::consts::FRAC_PI_2 / 1.2;+ let swayed = compute_bone_matrices(&YuuTraits::default(), &idle(), t_quarter);+ let origin = swayed[Joint::Root as usize].transform_point3(Vec3::ZERO);+ assert!(origin.length() < 1e-5);+ let off_axis = swayed[Joint::Root as usize].transform_point3(Vec3::new(1.0, 0.0, 0.0));+ assert!((off_axis - Vec3::new(1.0, 0.0, 0.0)).length() > 1e-4, "sway must rotate");+ assert!((off_axis - Vec3::new(1.0, 0.0, 0.0)).length() < 0.05, "sway must stay gentle");+}