agent-image-diff 0.2.4

Structured image diff with JSON output for agent workflows
Documentation
use serde::Serialize;

use crate::region::{BoundingBox, DiffResult, DimensionMismatch};

/// Compact output for agent consumption — only actionable fields.
#[derive(Serialize)]
pub struct CompactDiffResult {
    #[serde(rename = "match")]
    pub is_match: bool,
    pub diff_percentage: f64,
    pub regions: Vec<CompactRegion>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dimension_mismatch: Option<DimensionMismatch>,
}

#[derive(Serialize)]
pub struct CompactRegion {
    pub id: u32,
    pub bounding_box: BoundingBox,
    pub label: String,
}

impl From<&DiffResult> for CompactDiffResult {
    fn from(r: &DiffResult) -> Self {
        CompactDiffResult {
            is_match: r.is_match,
            diff_percentage: (r.stats.diff_percentage * 10.0).round() / 10.0,
            regions: r
                .regions
                .iter()
                .map(|reg| CompactRegion {
                    id: reg.id,
                    bounding_box: reg.bounding_box.clone(),
                    label: reg.label.clone(),
                })
                .collect(),
            dimension_mismatch: r.dimension_mismatch.clone(),
        }
    }
}