mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
move maxicode detector to Point
This commit is contained in:
@@ -451,9 +451,7 @@ fn decode_command(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(search_err) => {
|
Err(search_err) => {
|
||||||
println!(
|
println!("Error while attempting to locate barcode in '{file_name}': {search_err}");
|
||||||
"Error while attempting to locate barcode in '{file_name}': {search_err}"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fn impl_one_d_reader_macro(ast: &syn::DeriveInput) -> TokenStream {
|
|||||||
fn decode(&mut self, image: &mut crate::BinaryBitmap) -> Result<crate::RXingResult, Exceptions> {
|
fn decode(&mut self, image: &mut crate::BinaryBitmap) -> Result<crate::RXingResult, Exceptions> {
|
||||||
self.decode_with_hints(image, &HashMap::new())
|
self.decode_with_hints(image, &HashMap::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that we don't try rotation without the try harder flag, even if rotation was supported.
|
// Note that we don't try rotation without the try harder flag, even if rotation was supported.
|
||||||
fn decode_with_hints(
|
fn decode_with_hints(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -67,7 +67,7 @@ fn impl_one_d_reader_macro(ast: &syn::DeriveInput) -> TokenStream {
|
|||||||
points[i] = RXingResultPoint::new(height as f32- points[i].getY() - 1.0, points[i].getX());
|
points[i] = RXingResultPoint::new(height as f32- points[i].getY() - 1.0, points[i].getX());
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
return Err(Exceptions::NotFoundException(None))
|
return Err(Exceptions::NotFoundException(None))
|
||||||
@@ -81,101 +81,101 @@ fn impl_one_d_reader_macro(ast: &syn::DeriveInput) -> TokenStream {
|
|||||||
|
|
||||||
#[proc_macro_derive(EANReader)]
|
#[proc_macro_derive(EANReader)]
|
||||||
pub fn ean_reader_derive(input: TokenStream) -> TokenStream {
|
pub fn ean_reader_derive(input: TokenStream) -> TokenStream {
|
||||||
// Construct a representation of Rust code as a syntax tree
|
// Construct a representation of Rust code as a syntax tree
|
||||||
// that we can manipulate
|
// that we can manipulate
|
||||||
let ast = syn::parse(input).unwrap();
|
let ast = syn::parse(input).unwrap();
|
||||||
|
|
||||||
// Build the trait implementation
|
// Build the trait implementation
|
||||||
impl_ean_reader_macro(&ast)
|
impl_ean_reader_macro(&ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impl_ean_reader_macro(ast: &syn::DeriveInput) -> TokenStream {
|
fn impl_ean_reader_macro(ast: &syn::DeriveInput) -> TokenStream {
|
||||||
let name = &ast.ident;
|
let name = &ast.ident;
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
impl super::OneDReader for #name {
|
impl super::OneDReader for #name {
|
||||||
fn decodeRow(
|
fn decodeRow(
|
||||||
&mut self,
|
&mut self,
|
||||||
rowNumber: u32,
|
rowNumber: u32,
|
||||||
row: &crate::common::BitArray,
|
row: &crate::common::BitArray,
|
||||||
hints: &crate::DecodingHintDictionary,
|
hints: &crate::DecodingHintDictionary,
|
||||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||||
self.decodeRowWithGuardRange(rowNumber, row, &self.findStartGuardPattern(row)?, hints)
|
self.decodeRowWithGuardRange(rowNumber, row, &self.findStartGuardPattern(row)?, hints)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
gen.into()
|
||||||
gen.into()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_derive(OneDWriter)]
|
#[proc_macro_derive(OneDWriter)]
|
||||||
pub fn one_d_writer_derive(input: TokenStream) -> TokenStream {
|
pub fn one_d_writer_derive(input: TokenStream) -> TokenStream {
|
||||||
// Construct a representation of Rust code as a syntax tree
|
// Construct a representation of Rust code as a syntax tree
|
||||||
// that we can manipulate
|
// that we can manipulate
|
||||||
let ast = syn::parse(input).unwrap();
|
let ast = syn::parse(input).unwrap();
|
||||||
|
|
||||||
// Build the trait implementation
|
// Build the trait implementation
|
||||||
impl_one_d_writer_macro(&ast)
|
impl_one_d_writer_macro(&ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impl_one_d_writer_macro(ast: &syn::DeriveInput) -> TokenStream {
|
fn impl_one_d_writer_macro(ast: &syn::DeriveInput) -> TokenStream {
|
||||||
let name = &ast.ident;
|
let name = &ast.ident;
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
use crate::{
|
use crate::{
|
||||||
EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
impl Writer for #name {
|
impl Writer for #name {
|
||||||
fn encode(
|
fn encode(
|
||||||
&self,
|
&self,
|
||||||
contents: &str,
|
contents: &str,
|
||||||
format: &crate::BarcodeFormat,
|
format: &crate::BarcodeFormat,
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||||
self.encode_with_hints(contents, format, width, height, &HashMap::new())
|
self.encode_with_hints(contents, format, width, height, &HashMap::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_with_hints(
|
fn encode_with_hints(
|
||||||
&self,
|
&self,
|
||||||
contents: &str,
|
contents: &str,
|
||||||
format: &crate::BarcodeFormat,
|
format: &crate::BarcodeFormat,
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
hints: &crate::EncodingHintDictionary,
|
hints: &crate::EncodingHintDictionary,
|
||||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||||
if contents.is_empty() {
|
if contents.is_empty() {
|
||||||
return Err(Exceptions::IllegalArgumentException(
|
return Err(Exceptions::IllegalArgumentException(
|
||||||
Some("Found empty contents".to_owned()),
|
Some("Found empty contents".to_owned()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if width < 0 || height < 0 {
|
if width < 0 || height < 0 {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||||
"Negative size is not allowed. Input: {}x{}",
|
"Negative size is not allowed. Input: {}x{}",
|
||||||
width, height
|
width, height
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
if let Some(supportedFormats) = self.getSupportedWriteFormats() {
|
if let Some(supportedFormats) = self.getSupportedWriteFormats() {
|
||||||
if !supportedFormats.contains(format) {
|
if !supportedFormats.contains(format) {
|
||||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||||
"Can only encode {:?}, but got {:?}",
|
"Can only encode {:?}, but got {:?}",
|
||||||
supportedFormats, format
|
supportedFormats, format
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sidesMargin = self.getDefaultMargin();
|
let mut sidesMargin = self.getDefaultMargin();
|
||||||
if let Some(EncodeHintValue::Margin(margin)) = hints.get(&EncodeHintType::MARGIN) {
|
if let Some(EncodeHintValue::Margin(margin)) = hints.get(&EncodeHintType::MARGIN) {
|
||||||
sidesMargin = margin.parse::<u32>().unwrap();
|
sidesMargin = margin.parse::<u32>().unwrap();
|
||||||
}
|
}
|
||||||
// if hints.contains_key(&EncodeHintType::MARGIN) {
|
// if hints.contains_key(&EncodeHintType::MARGIN) {
|
||||||
// sidesMargin = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
|
// sidesMargin = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let code = self.encode_oned_with_hints(contents, hints)?;
|
let code = self.encode_oned_with_hints(contents, hints)?;
|
||||||
|
|
||||||
Self::renderRXingResult(&code, width, height, sidesMargin)
|
Self::renderRXingResult(&code, width, height, sidesMargin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ impl Circle<'_> {
|
|||||||
let point_3 = self.find_width_at_degree(97.0).1[0];
|
let point_3 = self.find_width_at_degree(97.0).1[0];
|
||||||
let guessed_center_point = Self::find_center(point_1, point_2, point_3);
|
let guessed_center_point = Self::find_center(point_1, point_2, point_3);
|
||||||
self.center = (
|
self.center = (
|
||||||
guessed_center_point.0.round() as u32,
|
guessed_center_point.x.round() as u32,
|
||||||
guessed_center_point.1.round() as u32,
|
guessed_center_point.y.round() as u32,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ impl Circle<'_> {
|
|||||||
/// returns (ellipse, center, semi_major, semi_minor, linear_eccentricity)
|
/// returns (ellipse, center, semi_major, semi_minor, linear_eccentricity)
|
||||||
pub fn detect_ellipse(&self) -> (bool, (u32, u32), u32, u32, u32) {
|
pub fn detect_ellipse(&self) -> (bool, (u32, u32), u32, u32, u32) {
|
||||||
// find semi-major and semi-minor axi
|
// find semi-major and semi-minor axi
|
||||||
let mut lengths = [(0, 0.0, [(0.0_f32, 0.0); 2]); 72];
|
let mut lengths = [(0, 0.0, [Point::default(); 2]); 72];
|
||||||
let mut circle_points = Vec::new();
|
let mut circle_points = Vec::new();
|
||||||
// for i_rotation in 0..72 {
|
// for i_rotation in 0..72 {
|
||||||
for (i_rotation, length_set) in lengths.iter_mut().enumerate() {
|
for (i_rotation, length_set) in lengths.iter_mut().enumerate() {
|
||||||
@@ -193,7 +193,7 @@ impl Circle<'_> {
|
|||||||
let guessed_center_point = Self::find_center(point_1, point_2, point_3);
|
let guessed_center_point = Self::find_center(point_1, point_2, point_3);
|
||||||
(
|
(
|
||||||
false,
|
false,
|
||||||
(guessed_center_point.0 as u32, guessed_center_point.1 as u32),
|
(guessed_center_point.x as u32, guessed_center_point.y as u32),
|
||||||
self.radius,
|
self.radius,
|
||||||
self.radius,
|
self.radius,
|
||||||
0,
|
0,
|
||||||
@@ -213,7 +213,7 @@ impl Circle<'_> {
|
|||||||
);
|
);
|
||||||
(
|
(
|
||||||
true,
|
true,
|
||||||
(ellipse_center.0 as u32, ellipse_center.1 as u32),
|
(ellipse_center.x as u32, ellipse_center.y as u32),
|
||||||
major_axis.0 / 2,
|
major_axis.0 / 2,
|
||||||
minor_axis.0 / 2,
|
minor_axis.0 / 2,
|
||||||
linear_eccentricity,
|
linear_eccentricity,
|
||||||
@@ -222,10 +222,10 @@ impl Circle<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_center(p1: (f32, f32), p2: (f32, f32), p3: (f32, f32)) -> (f32, f32) {
|
fn find_center(p1: Point, p2: Point, p3: Point) -> Point {
|
||||||
let (x1, y1) = p1;
|
let Point { x: x1, y: y1 } = p1;
|
||||||
let (x2, y2) = p2;
|
let Point { x: x2, y: y2 } = p2;
|
||||||
let (x3, y3) = p3;
|
let Point { x: x3, y: y3 } = p3;
|
||||||
|
|
||||||
let a = x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2);
|
let a = x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2);
|
||||||
let bx = (x1 * x1 + y1 * y1) * (y3 - y2)
|
let bx = (x1 * x1 + y1 * y1) * (y3 - y2)
|
||||||
@@ -238,22 +238,16 @@ impl Circle<'_> {
|
|||||||
let x = bx / (2.0 * a);
|
let x = bx / (2.0 * a);
|
||||||
let y = by / (2.0 * a);
|
let y = by / (2.0 * a);
|
||||||
|
|
||||||
(x.abs(), y.abs())
|
(x.abs(), y.abs()).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_ellipse_center(
|
fn calculate_ellipse_center(a: f32, _b: f32, p1: Point, p2: Point, p3: Point) -> Point {
|
||||||
a: f32,
|
let x1 = p1.x;
|
||||||
_b: f32,
|
let y1 = p1.y;
|
||||||
p1: (f32, f32),
|
let x2 = p2.x;
|
||||||
p2: (f32, f32),
|
let y2 = p2.y;
|
||||||
p3: (f32, f32),
|
let x3 = p3.x;
|
||||||
) -> (f32, f32) {
|
let y3 = p3.y;
|
||||||
let x1 = p1.0;
|
|
||||||
let y1 = p1.1;
|
|
||||||
let x2 = p2.0;
|
|
||||||
let y2 = p2.1;
|
|
||||||
let x3 = p3.0;
|
|
||||||
let y3 = p3.1;
|
|
||||||
|
|
||||||
let ma = (x1 * x1 + y1 * y1 - a * a) / 2.0;
|
let ma = (x1 * x1 + y1 * y1 - a * a) / 2.0;
|
||||||
let mb = (x2 * x2 + y2 * y2 - a * a) / 2.0;
|
let mb = (x2 * x2 + y2 * y2 - a * a) / 2.0;
|
||||||
@@ -264,20 +258,20 @@ impl Circle<'_> {
|
|||||||
let x = (ma * y2 + mb * y3 + mc * y1) / determinant;
|
let x = (ma * y2 + mb * y3 + mc * y1) / determinant;
|
||||||
let y = (x1 * mb + x2 * mc + x3 * ma) / determinant;
|
let y = (x1 * mb + x2 * mc + x3 * ma) / determinant;
|
||||||
|
|
||||||
(x, y)
|
(x, y).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_ellipse_point(
|
fn check_ellipse_point(
|
||||||
center: (u32, u32),
|
center: (u32, u32),
|
||||||
point: &(f32, f32),
|
point: &Point,
|
||||||
semi_major_axis: u32,
|
semi_major_axis: u32,
|
||||||
semi_minor_axis: u32,
|
semi_minor_axis: u32,
|
||||||
) -> f64 {
|
) -> f64 {
|
||||||
((point.0 as f64 - center.0 as f64).powf(2.0) / (semi_major_axis as f64).powf(2.0))
|
((point.x as f64 - center.0 as f64).powf(2.0) / (semi_major_axis as f64).powf(2.0))
|
||||||
+ ((point.1 as f64 - center.1 as f64).powf(2.0) / (semi_minor_axis as f64).powf(2.0))
|
+ ((point.y as f64 - center.1 as f64).powf(2.0) / (semi_minor_axis as f64).powf(2.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_width_at_degree(&self, rotation: f32) -> (u32, [(f32, f32); 2]) {
|
fn find_width_at_degree(&self, rotation: f32) -> (u32, [Point; 2]) {
|
||||||
let mut x = self.center.0;
|
let mut x = self.center.0;
|
||||||
let y = self.center.1;
|
let y = self.center.1;
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
@@ -285,7 +279,7 @@ impl Circle<'_> {
|
|||||||
// count left
|
// count left
|
||||||
while {
|
while {
|
||||||
let point = get_point(self.center, (x, y), rotation);
|
let point = get_point(self.center, (x, y), rotation);
|
||||||
!self.image.get(point.0 as u32, point.1 as u32) && x > 0
|
!self.image.get(point.x as u32, point.y as u32) && x > 0
|
||||||
} {
|
} {
|
||||||
x -= 1;
|
x -= 1;
|
||||||
length += 1;
|
length += 1;
|
||||||
@@ -297,7 +291,7 @@ impl Circle<'_> {
|
|||||||
// count right
|
// count right
|
||||||
while {
|
while {
|
||||||
let point = get_point(self.center, (x, y), rotation);
|
let point = get_point(self.center, (x, y), rotation);
|
||||||
!self.image.get(point.0 as u32, point.1 as u32)
|
!self.image.get(point.x as u32, point.y as u32)
|
||||||
} {
|
} {
|
||||||
x += 1;
|
x += 1;
|
||||||
length += 1;
|
length += 1;
|
||||||
@@ -344,7 +338,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
|||||||
};
|
};
|
||||||
let grid_sampler = DefaultGridSampler::default();
|
let grid_sampler = DefaultGridSampler::default();
|
||||||
|
|
||||||
let [tl, bl, tr, br] = &symbol_box.0;
|
let [tl, bl, tr, br] = symbol_box.0;
|
||||||
|
|
||||||
let target_width = Point::distance(tl.into(), tr.into());
|
let target_width = Point::distance(tl.into(), tr.into());
|
||||||
let target_height = Point::distance(br.into(), tr.into());
|
let target_height = Point::distance(br.into(), tr.into());
|
||||||
@@ -364,14 +358,14 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
|||||||
target_height,
|
target_height,
|
||||||
0.0,
|
0.0,
|
||||||
target_height,
|
target_height,
|
||||||
tl.0,
|
tl.x,
|
||||||
tl.1,
|
tl.y,
|
||||||
tr.0,
|
tr.x,
|
||||||
tr.1,
|
tr.y,
|
||||||
br.0,
|
br.x,
|
||||||
br.1,
|
br.y,
|
||||||
bl.0,
|
bl.x,
|
||||||
bl.1,
|
bl.y,
|
||||||
) else {
|
) else {
|
||||||
if try_harder {
|
if try_harder {
|
||||||
continue;
|
continue;
|
||||||
@@ -384,7 +378,8 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
|||||||
points: symbol_box
|
points: symbol_box
|
||||||
.0
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| Point { x: p.0, y: p.1 })
|
// .map(|p| Point { x: p.x, y: p.y })
|
||||||
|
.copied()
|
||||||
.collect(),
|
.collect(),
|
||||||
rotation: symbol_box.1,
|
rotation: symbol_box.1,
|
||||||
});
|
});
|
||||||
@@ -709,7 +704,7 @@ const LEFT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
|
|||||||
const RIGHT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
|
const RIGHT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
|
||||||
const ACCEPTED_SCALES: [f64; 5] = [0.065, 0.069, 0.07, 0.075, 0.08];
|
const ACCEPTED_SCALES: [f64; 5] = [0.065, 0.069, 0.07, 0.075, 0.08];
|
||||||
|
|
||||||
fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4], f32)> {
|
fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([Point; 4], f32)> {
|
||||||
let (left_boundary, right_boundary, top_boundary, bottom_boundary) =
|
let (left_boundary, right_boundary, top_boundary, bottom_boundary) =
|
||||||
calculate_simple_boundary(circle, Some(image), None, false);
|
calculate_simple_boundary(circle, Some(image), None, false);
|
||||||
|
|
||||||
@@ -743,10 +738,10 @@ fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4]
|
|||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
[
|
[
|
||||||
(result_box[0].x, result_box[0].y),
|
(result_box[0].x, result_box[0].y).into(),
|
||||||
(result_box[1].x, result_box[1].y),
|
(result_box[1].x, result_box[1].y).into(),
|
||||||
(result_box[2].x, result_box[2].y),
|
(result_box[2].x, result_box[2].y).into(),
|
||||||
(result_box[3].x, result_box[3].y),
|
(result_box[3].x, result_box[3].y).into(),
|
||||||
],
|
],
|
||||||
final_rotation,
|
final_rotation,
|
||||||
))
|
))
|
||||||
@@ -845,9 +840,9 @@ fn attempt_rotation_box(
|
|||||||
let p1_rot = get_point(circle.center, topl_p1, rotation);
|
let p1_rot = get_point(circle.center, topl_p1, rotation);
|
||||||
let p2_rot = get_point(circle.center, topl_p2, rotation);
|
let p2_rot = get_point(circle.center, topl_p2, rotation);
|
||||||
let p3_rot = get_point(circle.center, topl_p3, rotation);
|
let p3_rot = get_point(circle.center, topl_p3, rotation);
|
||||||
let found_tl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
let found_tl = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||||
&& image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
&& image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||||
if !found_tl {
|
if !found_tl {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -858,9 +853,9 @@ fn attempt_rotation_box(
|
|||||||
let p1_rot = get_point(circle.center, topr_p1, rotation);
|
let p1_rot = get_point(circle.center, topr_p1, rotation);
|
||||||
let p2_rot = get_point(circle.center, topr_p2, rotation);
|
let p2_rot = get_point(circle.center, topr_p2, rotation);
|
||||||
let p3_rot = get_point(circle.center, topr_p3, rotation);
|
let p3_rot = get_point(circle.center, topr_p3, rotation);
|
||||||
let found_tr = !image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
let found_tr = !image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||||
&& !image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
&& !image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||||
if !found_tr {
|
if !found_tr {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -871,9 +866,9 @@ fn attempt_rotation_box(
|
|||||||
let p1_rot = get_point(circle.center, l_p1, rotation);
|
let p1_rot = get_point(circle.center, l_p1, rotation);
|
||||||
let p2_rot = get_point(circle.center, l_p2, rotation);
|
let p2_rot = get_point(circle.center, l_p2, rotation);
|
||||||
let p3_rot = get_point(circle.center, l_p3, rotation);
|
let p3_rot = get_point(circle.center, l_p3, rotation);
|
||||||
let found_l = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
let found_l = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||||
if !found_l {
|
if !found_l {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -884,9 +879,9 @@ fn attempt_rotation_box(
|
|||||||
let p1_rot = get_point(circle.center, r_p1, rotation);
|
let p1_rot = get_point(circle.center, r_p1, rotation);
|
||||||
let p2_rot = get_point(circle.center, r_p2, rotation);
|
let p2_rot = get_point(circle.center, r_p2, rotation);
|
||||||
let p3_rot = get_point(circle.center, r_p3, rotation);
|
let p3_rot = get_point(circle.center, r_p3, rotation);
|
||||||
let found_r = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
let found_r = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||||
if !found_r {
|
if !found_r {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -897,9 +892,9 @@ fn attempt_rotation_box(
|
|||||||
let p1_rot = get_point(circle.center, bottoml_p1, rotation);
|
let p1_rot = get_point(circle.center, bottoml_p1, rotation);
|
||||||
let p2_rot = get_point(circle.center, bottoml_p2, rotation);
|
let p2_rot = get_point(circle.center, bottoml_p2, rotation);
|
||||||
let p3_rot = get_point(circle.center, bottoml_p3, rotation);
|
let p3_rot = get_point(circle.center, bottoml_p3, rotation);
|
||||||
let found_bl = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
let found_bl = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||||
if !found_bl {
|
if !found_bl {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -910,9 +905,9 @@ fn attempt_rotation_box(
|
|||||||
let p1_rot = get_point(circle.center, bottomr_p1, rotation);
|
let p1_rot = get_point(circle.center, bottomr_p1, rotation);
|
||||||
let p2_rot = get_point(circle.center, bottomr_p2, rotation);
|
let p2_rot = get_point(circle.center, bottomr_p2, rotation);
|
||||||
let p3_rot = get_point(circle.center, bottomr_p3, rotation);
|
let p3_rot = get_point(circle.center, bottomr_p3, rotation);
|
||||||
let found_br = image.try_get_area(p1_rot.0 as u32, p1_rot.1 as u32, 3)?
|
let found_br = image.try_get_area(p1_rot.x as u32, p1_rot.y as u32, 3)?
|
||||||
&& !image.try_get_area(p2_rot.0 as u32, p2_rot.1 as u32, 3)?
|
&& !image.try_get_area(p2_rot.x as u32, p2_rot.y as u32, 3)?
|
||||||
&& image.try_get_area(p3_rot.0 as u32, p3_rot.1 as u32, 3)?;
|
&& image.try_get_area(p3_rot.x as u32, p3_rot.y as u32, 3)?;
|
||||||
if !found_br {
|
if !found_br {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -952,10 +947,10 @@ fn attempt_rotation_box(
|
|||||||
|
|
||||||
Some((
|
Some((
|
||||||
[
|
[
|
||||||
point(new_1.0, new_1.1),
|
point(new_1.x, new_1.y),
|
||||||
point(new_2.0, new_2.1),
|
point(new_2.x, new_2.y),
|
||||||
point(new_3.0, new_3.1),
|
point(new_3.x, new_3.y),
|
||||||
point(new_4.0, new_4.1),
|
point(new_4.x, new_4.y),
|
||||||
],
|
],
|
||||||
final_rotation,
|
final_rotation,
|
||||||
))
|
))
|
||||||
@@ -977,7 +972,7 @@ fn get_adjusted_points(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_point(center: (u32, u32), original: (u32, u32), angle: f32) -> (f32, f32) {
|
fn get_point(center: (u32, u32), original: (u32, u32), angle: f32) -> Point {
|
||||||
let radians = angle.to_radians();
|
let radians = angle.to_radians();
|
||||||
let x = radians.cos() * (original.0 as f32 - center.0 as f32)
|
let x = radians.cos() * (original.0 as f32 - center.0 as f32)
|
||||||
- radians.sin() * (original.1 as f32 - center.1 as f32)
|
- radians.sin() * (original.1 as f32 - center.1 as f32)
|
||||||
@@ -986,7 +981,7 @@ fn get_point(center: (u32, u32), original: (u32, u32), angle: f32) -> (f32, f32)
|
|||||||
+ radians.cos() * (original.1 as f32 - center.1 as f32)
|
+ radians.cos() * (original.1 as f32 - center.1 as f32)
|
||||||
+ center.1 as f32;
|
+ center.1 as f32;
|
||||||
|
|
||||||
(x.abs(), y.abs())
|
Point::new(x.abs(), y.abs())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn adjust_point_alternate(point: (u32, u32), circle: &Circle, center_scale: f64) -> (u32, u32) {
|
fn adjust_point_alternate(point: (u32, u32), circle: &Circle, center_scale: f64) -> (u32, u32) {
|
||||||
|
|||||||
Reference in New Issue
Block a user