From ea00eed31f7c650c274205b9afd96990cb4d1c93 Mon Sep 17 00:00:00 2001 From: Fu Wang Date: Mon, 4 Aug 2025 22:25:44 +0800 Subject: [PATCH 1/2] Implement PartialEq and related traits for core structs Added PartialEq (and Eq, Hash, Clone, Copy where appropriate) to Point, BoundingBox, Resolution, OcrOptions, and OcrWord structs to enable value comparisons and usage in collections. This improves testability and interoperability for OCR-related data types. --- src/bounding_box.rs | 4 ++-- src/ocr_options.rs | 4 ++-- src/ocr_word.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bounding_box.rs b/src/bounding_box.rs index 1a7f9bf..73eef3c 100644 --- a/src/bounding_box.rs +++ b/src/bounding_box.rs @@ -3,7 +3,7 @@ use serde::Serialize; use crate::ffi::RawBBox; /// This `Point` struct represents a point in 2D space with X and Y coordinates. -#[derive(Debug, Clone, Copy, Default, Serialize)] +#[derive(Debug, Clone, Copy, Default, Serialize, PartialEq)] pub struct Point { pub x: f32, pub y: f32, @@ -16,7 +16,7 @@ impl std::fmt::Display for Point { } /// This `BoundingBox` struct represents a bounding box in 2D space, used for OCR to tightly enclose detected text. -#[derive(Debug, Clone, Copy, Default, Serialize)] +#[derive(Debug, Clone, Copy, Default, Serialize, PartialEq)] pub struct BoundingBox { pub top_left: Point, pub top_right: Point, diff --git a/src/ocr_options.rs b/src/ocr_options.rs index a982b0b..49e6f62 100644 --- a/src/ocr_options.rs +++ b/src/ocr_options.rs @@ -1,12 +1,12 @@ /// A simple width×height pair. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Resolution { pub width: i32, pub height: i32, } /// Configuration for OCR processing behavior. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct OcrOptions { /// The maximum number of lines that can be recognized. /// Default is 100, range is 0-1000. diff --git a/src/ocr_word.rs b/src/ocr_word.rs index 2ec7636..970035e 100644 --- a/src/ocr_word.rs +++ b/src/ocr_word.rs @@ -11,7 +11,7 @@ use crate::check_ocr_call; /// The `OcrWord` struct represents a word recognized by the OCR engine. /// It contains the recognized word, its confidence score, and its bounding box. -#[derive(Debug, Serialize)] +#[derive(Debug, Clone, Serialize, PartialEq)] pub struct OcrWord { pub text: String, pub confidence: f32, From b7b23fd54ab3a37bc281fb592ffc553d5e7b2a99 Mon Sep 17 00:00:00 2001 From: Fu Wang Date: Tue, 5 Aug 2025 22:50:17 +0800 Subject: [PATCH 2/2] Update src/ocr_options.rs Remove the `Copy` trait from the' OcrOptions' struct, as it may contain non-Copy fields in the future. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/ocr_options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocr_options.rs b/src/ocr_options.rs index 49e6f62..5f63f04 100644 --- a/src/ocr_options.rs +++ b/src/ocr_options.rs @@ -6,7 +6,7 @@ pub struct Resolution { } /// Configuration for OCR processing behavior. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct OcrOptions { /// The maximum number of lines that can be recognized. /// Default is 100, range is 0-1000.