From bf1d872f13ef77663b051b7c4b1a4f8f7ae65ed3 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 21 Jan 2026 16:13:46 -0600 Subject: [PATCH] Refactor AmbiguousValue handling for CFrame conversion - Introduced a new method `array12_to_cframe` to streamline the conversion of Array12 values to CFrame, improving code clarity and reducing redundancy. - Updated handling for both CFrame and OptionalCFrame variants to utilize the new conversion method, enhancing maintainability and consistency in value processing. --- src/resolution.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/resolution.rs b/src/resolution.rs index 59fcb592..6ac290e3 100644 --- a/src/resolution.rs +++ b/src/resolution.rs @@ -235,15 +235,11 @@ impl AmbiguousValue { } (VariantType::CFrame, AmbiguousValue::Array12(value)) => { - let value = value.map(|v| v as f32); - let pos = Vector3::new(value[0], value[1], value[2]); - let orientation = Matrix3::new( - Vector3::new(value[3], value[4], value[5]), - Vector3::new(value[6], value[7], value[8]), - Vector3::new(value[9], value[10], value[11]), - ); + Ok(Self::array12_to_cframe(value).into()) + } - Ok(CFrame::new(pos, orientation).into()) + (VariantType::OptionalCFrame, AmbiguousValue::Array12(value)) => { + Ok(Variant::OptionalCFrame(Some(Self::array12_to_cframe(value)))) } (VariantType::Attributes, AmbiguousValue::Attributes(value)) => Ok(value.into()), @@ -284,6 +280,17 @@ impl AmbiguousValue { } } + fn array12_to_cframe(value: [f64; 12]) -> CFrame { + let value = value.map(|v| v as f32); + let pos = Vector3::new(value[0], value[1], value[2]); + let orientation = Matrix3::new( + Vector3::new(value[3], value[4], value[5]), + Vector3::new(value[6], value[7], value[8]), + Vector3::new(value[9], value[10], value[11]), + ); + CFrame::new(pos, orientation) + } + fn describe(&self) -> &'static str { match self { AmbiguousValue::Bool(_) => "a bool",