Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for empty polydata topology #46

Merged
merged 3 commits into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,11 @@ impl DataArray {
buf
}
DataArrayFormat::Ascii => {
let string = data[0].clone().into_string();
let string = if data.is_empty() {
"".to_string()
} else {
data[0].clone().into_string()
};
let slice = string.as_str();
fn parse_num_seq<E, T>(s: &str) -> std::result::Result<Vec<T>, ValidationError>
where
Expand Down Expand Up @@ -3797,4 +3801,41 @@ mod tests {
assert_eq!(xml_round_trip.clone(), vtk_round_trip.try_into()?);
Ok(())
}

#[test]
fn empty_polydata_topology() {
use super::Data::Data;
use super::DataArray as XMLDataArray;
use crate::IOBuffer;
let data = XMLDataArray {
name: "PolyData".to_string(),
scalar_type: ScalarType::Float32,
format: DataArrayFormat::Ascii,
offset: None,
num_comp: 1,
range_min: Some(0.1),
range_max: Some(0.3),
data: vec![Data("0.1 0.2 0.3".to_string())],
};
let data_empty = XMLDataArray {
name: "PolyData".to_string(),
scalar_type: ScalarType::Float32,
format: DataArrayFormat::Ascii,
offset: None,
num_comp: 1,
range_min: None,
range_max: None,
data: vec![],
};
let encoding_info = EncodingInfo {
byte_order: model::ByteOrder::BigEndian,
header_type: ScalarType::Float64,
compressor: Compressor::None,
compression_level: 0,
};
let data_fa = data.into_field_array(3, None, encoding_info);
let data_empty_fa = data_empty.into_field_array(0, None, encoding_info);
assert_eq!(data_fa.unwrap().data, IOBuffer::F32(vec![0.1, 0.2, 0.3]));
assert_eq!(data_empty_fa.unwrap().data, IOBuffer::F32(vec![]));
}
}