use std::{fmt, iter::Sum};
use std::hash::Hash;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::ResultPoint;
/**
*
Encapsulates a point of interest in an image containing a barcode. Typically, this
* would be the location of a finder pattern or the corner of the barcode, for example.
*
* @author Sean Owen
*/
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Default)]
pub struct PointT {
pub x: T,
pub y: T,
}
// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// #[derive(Debug, Clone, Copy, Default)]
// pub struct Point {
// pub(crate) x: f32,
// pub(crate) y: f32,
// }
pub type PointF = PointT;
pub type PointI = PointT;
pub type PointU = PointT;
pub type Point = PointF;
impl From for PointI {
fn from(val: Point) -> Self {
PointI {
x: val.x.floor() as i32,
y: val.y.floor() as i32,
}
}
}
impl From for Point {
fn from(val: PointI) -> Self {
Point {
x: val.x as f32,
y: val.y as f32,
}
}
}
impl From for PointU {
fn from(val: Point) -> Self {
PointU {
x: val.x.floor() as u32,
y: val.y.floor() as u32,
}
}
}
impl From for Point {
fn from(val: PointU) -> Self {
Point {
x: val.x as f32,
y: val.y as f32,
}
}
}
/** An alias for `Point::new`. */
pub const fn point_f(x: f32, y: f32) -> Point {
Point::new(x, y)
}
pub const fn point(x: T, y: T) -> PointT
where
T: Copy,
{
PointT::new(x, y)
}
pub fn point_i>(x: T, y: T) -> Point {
Point::new(x.into() as f32, y.into() as f32)
}
impl Hash for Point {
fn hash(&self, state: &mut H) {
self.x.to_string().hash(state);
self.y.to_string().hash(state);
}
}
impl PartialEq for Point {
fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y
}
}
impl Eq for Point {}
impl PointT
where
T: Copy,
{
pub const fn new(x: T, y: T) -> PointT {
PointT { x, y }
}
pub const fn with_single(x: T) -> Self {
Self { x, y: x }
}
}
impl std::ops::AddAssign for PointT
where
T: std::ops::Add