Skip to content

Commit

Permalink
Update resolution Ray and Rect implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DervexDev committed Aug 8, 2024
1 parent e96b571 commit 85a2759
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Config {
Self::new().clone()
}

/// This sould be called once, at the start of the program
/// This should be called once, at the start of the program
pub fn load() -> Result<()> {
let mut config = Self::default();

Expand Down
31 changes: 19 additions & 12 deletions src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,16 @@ impl UnresolvedValue {
}
Variant::PhysicalProperties(PhysicalProperties::Default) => AmbiguousValue::String(String::from("Default")),

Variant::Ray(ray) => AmbiguousValue::Ray(ray),
Variant::Ray(ray) => AmbiguousValue::Array3Array2([
[ray.origin.x as f64, ray.origin.y as f64, ray.origin.z as f64],
[ray.direction.x as f64, ray.direction.y as f64, ray.direction.z as f64],
]),

Variant::Rect(rect) => AmbiguousValue::Array2Array2([
[rect.min.x as f64, rect.min.y as f64],
[rect.max.x as f64, rect.max.y as f64],
Variant::Rect(rect) => AmbiguousValue::Array4([
rect.min.x as f64,
rect.min.y as f64,
rect.max.x as f64,
rect.max.y as f64,
]),
// TODO: Implement Ref
// Variant::Ref(reference) => AmbiguousValue::
Expand Down Expand Up @@ -262,7 +267,6 @@ pub enum AmbiguousValue {
NumberSequence(Vec<NumberSequenceKeypoint>),
Font(Font),
PhysicalProperties(CustomPhysicalProperties),
Ray(Ray),
Object(HashMap<String, UnresolvedValue>),
}

Expand Down Expand Up @@ -440,11 +444,15 @@ impl AmbiguousValue {
Ok(PhysicalProperties::Default.into())
}

(VariantType::Ray, AmbiguousValue::Ray(ray)) => Ok(ray.into()),
(VariantType::Ray, AmbiguousValue::Array3Array2(ray)) => Ok(Ray::new(
Vector3::new(ray[0][0] as f32, ray[0][1] as f32, ray[0][2] as f32),
Vector3::new(ray[1][0] as f32, ray[1][1] as f32, ray[1][2] as f32),
)
.into()),

(VariantType::Rect, AmbiguousValue::Array2Array2(rect)) => Ok(Rect::new(
Vector2::new(rect[0][0] as f32, rect[0][1] as f32),
Vector2::new(rect[1][0] as f32, rect[1][1] as f32),
(VariantType::Rect, AmbiguousValue::Array4(rect)) => Ok(Rect::new(
Vector2::new(rect[0] as f32, rect[1] as f32),
Vector2::new(rect[2] as f32, rect[3] as f32),
)
.into()),
// TODO: Implement Ref
Expand Down Expand Up @@ -517,20 +525,19 @@ impl AmbiguousValue {
AmbiguousValue::String(_) => "a string",
AmbiguousValue::StringArray(_) => "an array of strings",
AmbiguousValue::Number(_) => "a number",
AmbiguousValue::Object(_) => "a generic object",
AmbiguousValue::Array2(_) => "an array of two numbers",
AmbiguousValue::Array3(_) => "an array of three numbers",
AmbiguousValue::Array4(_) => "an array of four numbers",
AmbiguousValue::Array12(_) => "an array of twelve numbers",
AmbiguousValue::Array2Array2(_) => "an array of two arrays of two numbers",
AmbiguousValue::Array3Array2(_) => "an array of two arrays of three numbers",
AmbiguousValue::Attributes(_) => "an object containing attributes",
AmbiguousValue::Font(_) => "an object describing a Font",
AmbiguousValue::MaterialColors(_) => "an object describing MaterialColors",
AmbiguousValue::ColorSequence(_) => "an object describing a ColorSequence",
AmbiguousValue::NumberSequence(_) => "an object describing a NumberSequence",
AmbiguousValue::Font(_) => "an object describing a Font",
AmbiguousValue::PhysicalProperties(_) => "an object describing PhysicalProperties",
AmbiguousValue::Ray(_) => "an object describing a Ray",
AmbiguousValue::Object(_) => "a generic object",
}
}
}
Expand Down
17 changes: 5 additions & 12 deletions tests/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,15 @@ mod unresolved_value {
#[test]
fn ray() {
assert_eq!(
resolve(
"RayValue",
"Value",
r#"{"origin": [1.2, 3.4, 5.6], "direction": [1.2, 3.4, 5.6]}"#
),
resolve("RayValue", "Value", "[[1.2, 3.4, 5.6], [1.2, 3.4, 5.6]]"),
Ray::new(Vector3::new(1.2, 3.4, 5.6), Vector3::new(1.2, 3.4, 5.6)).into()
);
}

#[test]
fn rect() {
assert_eq!(
resolve("ImageButton", "SliceCenter", "[[1.2, 3.4], [5.6, 7.8]]"),
resolve("ImageButton", "SliceCenter", "[1.2, 3.4, 5.6, 7.8]"),
Rect::new(Vector2::new(1.2, 3.4), Vector2::new(5.6, 7.8)).into()
);
}
Expand Down Expand Up @@ -638,18 +634,15 @@ mod resolved_value {
fn ray() {
assert_eq(
from_variant(Ray::new(Vector3::new(1.2, 3.4, 5.6), Vector3::new(1.2, 3.4, 5.6))),
json!({
"origin": [1.2, 3.4, 5.6],
"direction": [1.2, 3.4, 5.6],
}),
)
json!([[1.2, 3.4, 5.6], [1.2, 3.4, 5.6]]),
);
}

#[test]
fn rect() {
assert_eq(
from_variant(Rect::new(Vector2::new(1.2, 3.4), Vector2::new(5.6, 7.8))),
json!([[1.2, 3.4], [5.6, 7.8]]),
json!([1.2, 3.4, 5.6, 7.8]),
);
}

Expand Down

0 comments on commit 85a2759

Please sign in to comment.