mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
style(actions): apply Perspective Warp formatter
This commit is contained in:
1 parent
3feae0e0b6
commit
fbccaaeabb
3 files changed
+16
-20
No files matched your search
@@ -46,9 +46,8 @@ fn reference_rect(d: &Descriptor) -> Option<[f64; 4]> {
|
||||
|
||||
fn objects<'a>(d: &'a Descriptor, key: &str, class: &str, keys: &[&str], max: usize) -> Option<&'a [D]> {
|
||||
let D::List(items) = d.get(key)? else { return None };
|
||||
(!items.is_empty() && items.len() <= max
|
||||
&& items.iter().all(|item| matches!(item, D::Descriptor(d) if d.class_id.is(class) && exact_keys(d, keys))))
|
||||
.then_some(items)
|
||||
(!items.is_empty() && items.len() <= max && items.iter().all(|item| matches!(item, D::Descriptor(d) if d.class_id.is(class) && exact_keys(d, keys))))
|
||||
.then_some(items)
|
||||
}
|
||||
|
||||
/// Each recorded index must link exactly the corners the native command would link. Edges
|
||||
@@ -93,9 +92,7 @@ fn parameters(d: &Descriptor) -> Option<Value> {
|
||||
objects(d, "warpedVertices", "Pnt ", &["Hrzn", "Vrtc"], 4 * MAX_PLANES)?;
|
||||
objects(d, "quads", "perspectiveWarpQuad", &["indices"], MAX_PLANES)?;
|
||||
let (planes, indices) = perspective_warp_indexed_geometry(d)?;
|
||||
if !planes.iter().all(|p| {
|
||||
p.src.iter().chain(&p.dst).flatten().copied().all(coordinate) && convex_quad(&p.src) && convex_quad(&p.dst)
|
||||
}) {
|
||||
if !planes.iter().all(|p| p.src.iter().chain(&p.dst).flatten().copied().all(coordinate) && convex_quad(&p.src) && convex_quad(&p.dst)) {
|
||||
return None;
|
||||
}
|
||||
same_topology(&planes, &indices, src.len())?;
|
||||
@@ -129,13 +126,15 @@ fn canonical(p: &Value) -> Option<Descriptor> {
|
||||
let planes: Vec<Plane> = serde_json::from_value(Value::Array(planes.clone())).ok()?;
|
||||
let rect = desc("Rctn").with("Top ", px(top)).with("Left", px(left)).with("Btom", px(bottom)).with("Rght", px(right));
|
||||
let (src, dst, quads) = perspective_warp_geometry(&planes);
|
||||
Some(desc(EVENT)
|
||||
.with("null", layer_ref(p)?)
|
||||
.with("Md ", enm("perspectiveWarpMode", "warp"))
|
||||
.with("referenceRect", D::Descriptor(rect))
|
||||
.with("vertices", src)
|
||||
.with("warpedVertices", dst)
|
||||
.with("quads", quads))
|
||||
Some(
|
||||
desc(EVENT)
|
||||
.with("null", layer_ref(p)?)
|
||||
.with("Md ", enm("perspectiveWarpMode", "warp"))
|
||||
.with("referenceRect", D::Descriptor(rect))
|
||||
.with("vertices", src)
|
||||
.with("warpedVertices", dst)
|
||||
.with("quads", quads),
|
||||
)
|
||||
}
|
||||
|
||||
/// Reuses source bytes only while they still describe the same target, rectangle and planes.
|
||||
|
||||
@@ -42,7 +42,8 @@ fn fixture(name: Option<&str>) -> Descriptor {
|
||||
}
|
||||
|
||||
fn imported(d: Descriptor, with_dialog: bool, enabled: bool) -> atn_cmds::Imported {
|
||||
let item = AtnItem { event: AtnEvent::name(EVENT), dictionary: b"Perspective Warp".to_vec(), descriptor: Some(d), with_dialog, enabled, ..Default::default() };
|
||||
let item =
|
||||
AtnItem { event: AtnEvent::name(EVENT), dictionary: b"Perspective Warp".to_vec(), descriptor: Some(d), with_dialog, enabled, ..Default::default() };
|
||||
let file = AtnFile {
|
||||
name: UnicodeString::new_nul("Set"),
|
||||
actions: vec![AtnAction { name: UnicodeString::new_nul("Warp"), items: vec![item], ..Default::default() }],
|
||||
@@ -97,9 +98,7 @@ fn unsupported_recordings_are_kept_without_partial_mapping() {
|
||||
let mut layout = d.clone();
|
||||
*value_mut(&mut layout, "Md ") = D::Enumerated { type_id: Id::new("perspectiveWarpMode"), value: Id::new("layout") };
|
||||
let mut wrong_target = d.clone();
|
||||
*value_mut(&mut wrong_target, "null") = D::Reference(vec![ReferenceItem::Class(Class {
|
||||
class_id: Id::new("Chnl"), name: UnicodeString::new_nul(""),
|
||||
})]);
|
||||
*value_mut(&mut wrong_target, "null") = D::Reference(vec![ReferenceItem::Class(Class { class_id: Id::new("Chnl"), name: UnicodeString::new_nul("") })]);
|
||||
let mut bad_index = d.clone();
|
||||
*value_mut(&mut bad_index, "quads") = D::List(vec![quad([1, 4, 99, 3])]);
|
||||
let mut wrong_units = d.clone();
|
||||
|
||||
@@ -137,9 +137,7 @@ fn template(params: &J) -> Result<Option<Descriptor>, String> {
|
||||
/// The planes to write: as rendered, so a `straighten` is baked in.
|
||||
fn export_planes(params: &J) -> Result<Vec<Plane>, String> {
|
||||
let object = params.as_object().ok_or("Perspective Warp parameters must be an object")?;
|
||||
let supported = |k: &str| {
|
||||
super::is_meta(k) || ["planes", "straighten", "interpolation"].contains(&k) || (k == "target" && params["target"] == "pixels")
|
||||
};
|
||||
let supported = |k: &str| super::is_meta(k) || ["planes", "straighten", "interpolation"].contains(&k) || (k == "target" && params["target"] == "pixels");
|
||||
if let Some(k) = object.keys().find(|k| !supported(k)) {
|
||||
return Err(format!("Perspective Warp setting `{k}` has no PSD equivalent"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user