mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
port concentric finder (no test)
This commit is contained in:
@@ -1,34 +1,19 @@
|
||||
use crate::common::Result;
|
||||
use crate::{Exceptions, Point};
|
||||
|
||||
use super::{DMRegressionLine, Direction, RegressionLine};
|
||||
use super::{Direction, RegressionLineTrait};
|
||||
|
||||
#[inline(always)]
|
||||
pub fn float_min<T: PartialOrd>(a: T, b: T) -> T {
|
||||
if a > b {
|
||||
b
|
||||
} else {
|
||||
a
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn float_max<T: PartialOrd>(a: T, b: T) -> T {
|
||||
if a < b {
|
||||
b
|
||||
} else {
|
||||
a
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result<Point> {
|
||||
pub fn intersect<T: RegressionLineTrait, T2: RegressionLineTrait>(
|
||||
l1: &T,
|
||||
l2: &T2,
|
||||
) -> Result<Point> {
|
||||
if !(l1.isValid() && l2.isValid()) {
|
||||
return Err(Exceptions::ILLEGAL_STATE);
|
||||
}
|
||||
let d = l1.a * l2.b - l1.b * l2.a;
|
||||
let x = (l1.c * l2.b - l1.b * l2.c) / d;
|
||||
let y = (l1.a * l2.c - l1.c * l2.a) / d;
|
||||
let d = l1.a() * l2.b() - l1.b() * l2.a();
|
||||
let x = (l1.c() * l2.b() - l1.b() * l2.c()) / d;
|
||||
let y = (l1.a() * l2.c() - l1.c() * l2.a()) / d;
|
||||
Ok(Point { x, y })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user