#[cfg(test)]
mod tests {
use super::super::obj;
use crate::{Boundaries, CityJSON, CityObject, Geometry, GeometryType, Transform};
#[test]
fn test_to_obj_simple() {
let mut city_json = CityJSON::new();
city_json.transform = Transform {
scale: vec![1.0, 1.0, 1.0],
translate: vec![0.0, 0.0, 0.0],
};
city_json.vertices = vec![
vec![0, 0, 0], vec![1, 0, 0], vec![1, 1, 0], vec![0, 1, 0], vec![0, 0, 1], vec![1, 0, 1], vec![1, 1, 1], vec![0, 1, 1], ];
let boundaries = Boundaries::Nested(vec![
Boundaries::Nested(vec![
Boundaries::Nested(vec![Boundaries::Indices(vec![0, 1, 2, 3])]),
Boundaries::Nested(vec![Boundaries::Indices(vec![0, 1, 5, 4])]),
Boundaries::Nested(vec![Boundaries::Indices(vec![1, 2, 6, 5])]),
Boundaries::Nested(vec![Boundaries::Indices(vec![2, 3, 7, 6])]),
Boundaries::Nested(vec![Boundaries::Indices(vec![3, 0, 4, 7])]),
Boundaries::Nested(vec![Boundaries::Indices(vec![4, 5, 6, 7])]),
]),
]);
let geometry = Geometry {
thetype: GeometryType::Solid,
lod: Some("2.0".to_string()),
boundaries,
semantics: None,
material: None,
texture: None,
template: None,
transformation_matrix: None,
};
let city_object = CityObject::new(
"Building".to_string(),
None,
None,
Some(vec![geometry]),
None,
None,
None,
None,
);
city_json
.city_objects
.insert("Building1".to_string(), city_object);
let obj_string = obj::to_obj_string(&city_json);
println!("Generated OBJ:\n{}", obj_string);
assert!(obj_string.contains("v 0 0 0"));
assert!(obj_string.contains("v 1 0 0"));
assert!(obj_string.contains("v 1 1 0"));
assert!(obj_string.contains("v 0 1 0"));
assert!(obj_string.contains("v 0 0 1"));
assert!(obj_string.contains("v 1 0 1"));
assert!(obj_string.contains("v 1 1 1"));
assert!(obj_string.contains("v 0 1 1"));
assert!(obj_string.contains("f 1 2 3 4"));
assert!(obj_string.contains("f 1 2 6 5"));
assert!(obj_string.contains("f 2 3 7 6"));
assert!(obj_string.contains("f 3 4 8 7"));
assert!(obj_string.contains("f 4 1 5 8"));
assert!(obj_string.contains("f 5 6 7 8"));
}
}