more generic point in result_point_util

This commit is contained in:
Henry Schimke
2023-05-04 14:15:14 -05:00
parent 326da6808a
commit b508698334
2 changed files with 8 additions and 8 deletions

View File

@@ -26,7 +26,7 @@ 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);
}
@@ -34,10 +34,3 @@ pub fn orderBestPatterns<T: Into<Point> + Copy>(patterns: &mut [T; 3]) {
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))
}

View File

@@ -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 {