Keep explicit stroke wire defaults while fixing lint

This commit is contained in:
yoriswind committed 2026-11-28 10:43:57 -08:00
1 parent 671d0d0e3f
commit 4586629f83
2 files changed
+5 -3

No files matched your search

+3 -1
View File
@@ -30,13 +30,15 @@ fn missing_pressure_survives_serialization_without_reclassifying_explicit_one()
let absent: StrokePoint = serde_json::from_value(json!({"x": 20, "y": 30})).unwrap();
let supplied: StrokePoint = serde_json::from_value(json!({"x": 20, "y": 30, "pressure": 1})).unwrap();
assert_eq!(absent.pressure, supplied.pressure);
assert_eq!(absent.wheel, 1.0, "missing wire wheel keeps the legacy full input");
assert_eq!(supplied.wheel, 1.0, "explicit pen pressure does not change the wheel default");
assert!(!absent.pressure_present);
assert!(supplied.pressure_present);
let absent_half = StrokePoint { pressure: 0.5, ..absent };
for point in [absent, supplied, absent_half] {
let wire = serde_json::to_value(point).unwrap();
assert_eq!(wire.get("pressure").is_some(), point.pressure_present || point.pressure != 1.0);
assert_eq!(wire.get("pressurePresent").cloned(), (!point.pressure_present).then(|| json!(false)));
assert_eq!(wire.get("pressurePresent").cloned(), (!point.pressure_present).then_some(json!(false)));
assert_eq!(serde_json::from_value::<StrokePoint>(wire).unwrap(), point);
}
let points = [absent_half, StrokePoint { x: 155.0, ..absent_half }];
+2 -2
View File
@@ -110,8 +110,8 @@ fn present_pressure<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Option<f32
impl Default for StrokePointData {
fn default() -> Self {
// Missing wire fields must infer provenance from pressure, not inherit a false override.
Self { pressure: None, pressure_present: None, ..StrokePoint::without_pressure(0.0, 0.0).into() }
// Neutral provenance infers from pressure; missing stylus wheel retains its legacy 1.
Self { x: 0.0, y: 0.0, pressure: None, pressure_present: None, tilt_x: 0.0, tilt_y: 0.0, rotation: 0.0, wheel: 1.0, time: 0.0 }
}
}