switch to using Point in one-d-derive macros

Also start updates to make point more generic, still not complete or fully implemented.

Some code cleanup
This commit is contained in:
Henry Schimke
2023-04-29 17:51:26 -05:00
parent e0305549e3
commit 74a830f462
8 changed files with 55 additions and 27 deletions

View File

@@ -15,9 +15,37 @@ use crate::ResultPoint;
*/
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Default)]
pub struct Point {
pub(crate) x: f32,
pub(crate) y: f32,
pub struct PointT<T> {
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<f32>;
pub type PointI = PointT<u32>;
pub type Point = PointF;
impl Into<PointI> for Point {
fn into(self) -> PointI {
PointI{
x: self.x.floor() as u32,
y: self.y.floor() as u32,
}
}
}
impl Into<Point> for PointI {
fn into(self) -> Point {
Point {
x: self.x as f32,
y: self.y as f32,
}
}
}
/** An alias for `Point::new`. */
@@ -33,9 +61,6 @@ pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point {
Point::new(x.into() as f32, y.into() as f32)
}
/** Currently necessary because the external OneDReader proc macro uses it. */
pub type RXingResultPoint = Point;
impl Hash for Point {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.x.to_string().hash(state);