Fix the 'Bounding Box' node crashing on empty or single-point vector data input (#2529)

* Make Bounding Box have empty output on empty input

Fixes a crash when using the text tool and the Text node is connected to
a Bounding Box node.

* Use .map().unwrap_or_default()

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
kythyria 2025-04-10 10:48:44 +01:00 committed by GitHub
parent 93f7004ece
commit c137e44b71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -942,8 +942,10 @@ async fn bounding_box(_: impl Ctx, vector_data: VectorDataTable) -> VectorDataTa
let vector_data_transform = vector_data.transform();
let vector_data = vector_data.one_instance().instance;
let bounding_box = vector_data.bounding_box_with_transform(vector_data_transform).unwrap();
let mut result = VectorData::from_subpath(Subpath::new_rect(bounding_box[0], bounding_box[1]));
let mut result = vector_data
.bounding_box_with_transform(vector_data_transform)
.map(|bounding_box| VectorData::from_subpath(Subpath::new_rect(bounding_box[0], bounding_box[1])))
.unwrap_or_default();
result.style = vector_data.style.clone();
result.style.set_stroke_transform(DAffine2::IDENTITY);