use crate::{Point, point};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AlignmentPattern {
estimatedModuleSize: f32,
point: Point,
}
impl From<&AlignmentPattern> for Point {
fn from(value: &AlignmentPattern) -> Self {
value.point
}
}
impl From<AlignmentPattern> for Point {
fn from(value: AlignmentPattern) -> Self {
value.point
}
}
impl AlignmentPattern {
pub fn new(posX: f32, posY: f32, estimatedModuleSize: f32) -> Self {
Self {
estimatedModuleSize,
point: point(posX, posY),
}
}
pub fn aboutEquals(&self, moduleSize: f32, i: f32, j: f32) -> bool {
if (i - self.point.y).abs() <= moduleSize && (j - self.point.x).abs() <= moduleSize {
let moduleSizeDiff = (moduleSize - self.estimatedModuleSize).abs();
return moduleSizeDiff <= 1.0 || moduleSizeDiff <= self.estimatedModuleSize;
}
false
}
pub fn combineEstimate(&self, i: f32, j: f32, newModuleSize: f32) -> AlignmentPattern {
let combinedX = (self.point.x + j) / 2.0;
let combinedY = (self.point.y + i) / 2.0;
let combinedModuleSize = (self.estimatedModuleSize + newModuleSize) / 2.0;
AlignmentPattern::new(combinedX, combinedY, combinedModuleSize)
}
}