mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
in_progress port from cpp
This commit is contained in:
@@ -499,6 +499,24 @@ impl std::ops::Sub for ConcentricPattern {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add for ConcentricPattern {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
let new_p = self.p - rhs.p;
|
||||
Self {
|
||||
p: new_p,
|
||||
size: self.size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Point> for ConcentricPattern {
|
||||
fn from(value: Point) -> Self {
|
||||
Self { p: value, size: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl ConcentricPattern {
|
||||
pub fn dot(self, other: ConcentricPattern) -> f32 {
|
||||
Point::dot(self.p, other.p)
|
||||
|
||||
@@ -223,6 +223,12 @@ impl RegressionLineTrait for DMRegressionLine {
|
||||
}
|
||||
|
||||
impl DMRegressionLine {
|
||||
pub fn new(point_1: Point, point_2: Point) -> Self {
|
||||
let mut new = Self::default();
|
||||
RegressionLineTrait::evaluate(&mut new, &[point_1, point_1]);
|
||||
new
|
||||
}
|
||||
|
||||
// template <typename Container, typename Filter>
|
||||
fn average<T>(c: &[f64], f: T) -> f64
|
||||
where
|
||||
|
||||
106
src/common/cpp_essentials/matrix.rs
Normal file
106
src/common/cpp_essentials/matrix.rs
Normal file
@@ -0,0 +1,106 @@
|
||||
use crate::common::Result;
|
||||
use crate::{Exceptions, Point};
|
||||
|
||||
#[derive(Default, Clone, PartialEq, Eq)]
|
||||
pub struct Matrix<T: Default + Clone + Copy> {
|
||||
width: usize,
|
||||
height: usize,
|
||||
data: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: Default + Clone + Copy> Matrix<T> {
|
||||
pub fn with_data(width: usize, height: usize, data: Vec<T>) -> Result<Matrix<T>> {
|
||||
if (width != 0 && data.len() / width as usize != height as usize) {
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"invalid size: width * height is too big",
|
||||
));
|
||||
}
|
||||
Ok(Self {
|
||||
width,
|
||||
height,
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new(width: usize, height: usize) -> Result<Matrix<T>> {
|
||||
if (width != 0 && height != 0) {
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"invalid size: width * height is too big",
|
||||
));
|
||||
}
|
||||
Ok(Self {
|
||||
width,
|
||||
height,
|
||||
data: vec![T::default(); width * height],
|
||||
})
|
||||
}
|
||||
|
||||
pub fn height(&self) -> usize {
|
||||
self.height
|
||||
}
|
||||
|
||||
pub fn width(&self) -> usize {
|
||||
self.width
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
// value_t& operator()(int x, int y)
|
||||
// {
|
||||
// assert(x >= 0 && x < _width && y >= 0 && y < _height);
|
||||
// return _data[y * _width + x];
|
||||
// }
|
||||
|
||||
// const T& operator()(int x, int y) const
|
||||
// {
|
||||
// assert(x >= 0 && x < _width && y >= 0 && y < _height);
|
||||
// return _data[y * _width + x];
|
||||
// }
|
||||
|
||||
fn get_offset(x: usize, y: usize, width: usize) -> usize {
|
||||
(y * width + x) as usize
|
||||
}
|
||||
|
||||
pub fn get(&self, x: usize, y: usize) -> Option<T> {
|
||||
if x >= 0 && x < self.width && y >= 0 && y < self.height {
|
||||
None
|
||||
} else {
|
||||
Some(self.data[Self::get_offset(x, y, self.width)])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, x: usize, y: usize, value: T) -> T {
|
||||
self.data[Self::get_offset(x, y, self.width)] = value;
|
||||
self.get(x, y).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_point(&self, p: Point) -> Option<T> {
|
||||
self.get(p.x as usize, p.y as usize)
|
||||
}
|
||||
|
||||
pub fn set_point(&mut self, p: Point, value: T) -> T {
|
||||
self.set(p.x as usize, p.y as usize, value)
|
||||
}
|
||||
|
||||
pub fn data(&self) -> &[T] {
|
||||
&self.data
|
||||
}
|
||||
|
||||
// const value_t* begin() const {
|
||||
// return _data.data();
|
||||
// }
|
||||
|
||||
// const value_t* end() const {
|
||||
// return _data.data() + _width * _height;
|
||||
// }
|
||||
|
||||
pub fn clear_with(&mut self, value: T) {
|
||||
self.data.fill(value)
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.data.fill(T::default())
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ pub mod direction;
|
||||
pub mod dm_regression_line;
|
||||
pub mod edge_tracer;
|
||||
pub mod fast_edge_to_edge_counter;
|
||||
pub mod matrix;
|
||||
pub mod pattern;
|
||||
pub mod regression_line;
|
||||
pub mod regression_line_trait;
|
||||
@@ -19,6 +20,7 @@ pub use direction::*;
|
||||
pub use dm_regression_line::*;
|
||||
pub use edge_tracer::*;
|
||||
pub use fast_edge_to_edge_counter::*;
|
||||
pub use matrix::*;
|
||||
pub use pattern::*;
|
||||
pub use regression_line::*;
|
||||
pub use regression_line_trait::*;
|
||||
|
||||
Reference in New Issue
Block a user