LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-LIB-PEOPLE: leave empty face regions out of the catalog JSON
Brandon Thomas60a864977987
diff --git a/crates/catalog/src/model.rs b/crates/catalog/src/model.rsindex ec8d28d17..9248b2206 100644--- a/crates/catalog/src/model.rs+++ b/crates/catalog/src/model.rs@@ -183,8 +183,10 @@ pub struct Meta {pub copyright_url: String,pub creator: String,pub keywords: Vec<String>,- /// Face/pet/focus regions read from XMP (MWG-RS). Read-only today; nothing in- /// LightCraft writes regions yet.+ /// Face/pet/focus regions read from XMP (MWG-RS), on the upright (EXIF-oriented) photo.+ /// Removing or resizing one edits the catalog only; LightCraft never writes regions to XMP.+ /// Left out of the catalog JSON when empty (most photos), so older catalogs read unchanged.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]pub regions: Vec<lightcraft_meta::Region>,}diff --git a/crates/catalog/src/tests.rs b/crates/catalog/src/tests.rsindex 7897f7972..6f76b694e 100644--- a/crates/catalog/src/tests.rs+++ b/crates/catalog/src/tests.rs@@ -360,3 +360,23 @@ fn people_from_named_face_regions() {);assert_eq!(names(Filter { rating: 5, ..Default::default() }), vec![], "nobody in the filtered photos");}++/// Most photos have no regions: the field is left out of the catalog JSON then, and a catalog written+/// before regions existed (no `regions` key) reads with none.+#[test]+fn empty_regions_are_not_serialized_and_default_when_missing() {+ let m = Meta { keywords: vec!["k".into()], ..Default::default() };+ let v = serde_json::to_value(&m).unwrap();+ assert!(v.get("regions").is_none(), "{v}");+ let back: Meta = serde_json::from_value(v).unwrap();+ assert!(back.regions.is_empty());+ let mut with = m.clone();+ with.regions.push(lightcraft_meta::Region {+ rect: lightcraft_meta::Rect { x0: 0.1, y0: 0.1, x1: 0.2, y1: 0.2 },+ kind: lightcraft_meta::RegionKind::Face,+ name: Some("A".into()),+ description: None,+ });+ let back: Meta = serde_json::from_str(&serde_json::to_string(&with).unwrap()).unwrap();+ assert_eq!(back, with);+}