Skip to content

Commit

Permalink
more generic point in result_point_util
Browse files Browse the repository at this point in the history
  • Loading branch information
hschimke committed May 4, 2023
1 parent 326da68 commit b508698
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/result_point_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@ pub fn orderBestPatterns<T: Into<Point> + Copy>(patterns: &mut [T; 3]) {
// This asks whether BC x BA has a positive z component, which is the arrangement
// we want for A, B, C. If it's negative, then we've got it flipped around and
// should swap A and C.
if crossProductZ(pointA.into(), pointB.into(), pointC.into()) < 0.0 {
if Point::crossProductZ(pointA.into(), pointB.into(), pointC.into()) < 0.0 {
std::mem::swap(&mut pointA, &mut pointC);
}

patterns[0] = pointA;
patterns[1] = pointB;
patterns[2] = pointC;
}

/**
* Returns the z component of the cross product between vectors BC and BA.
*/
fn crossProductZ(a: Point, b: Point, c: Point) -> f32 {
((c.x - b.x) * (a.y - b.y)) - ((c.y - b.y) * (a.x - b.x))
}
7 changes: 7 additions & 0 deletions src/rxing_result_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ where
y: self.y.floor(),
}
}

/**
* Returns the z component of the cross product between vectors BC and BA.
*/
pub fn crossProductZ(a: PointT<T>, b: PointT<T>, c: PointT<T>) -> T {
((c.x - b.x) * (a.y - b.y)) - ((c.y - b.y) * (a.x - b.x))
}
}

impl From<(i32, i32)> for Point {
Expand Down

0 comments on commit b508698

Please sign in to comment.