Modify the concentric finder to guard array bounds

A potential resolution to Issue #36. In some cases the array positions suggested by the corner_positions array may be out of bounds for the points array. To resolve this, guard against out of bounds checks. In other cases, where the positions are matched, guard against having the start position of a slice go beyond the end position of the slice.
This commit is contained in:
Henry Schimke
2023-11-06 09:52:39 -06:00
parent 62e49b376d
commit 2664094767

View File

@@ -389,6 +389,18 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Qu
let try_get_range = |a: usize, b: usize| -> Option<&[Point]> {
if a > b {
None
}
// Added for Issue #36 where array is sometimes out of bounds
else if a + 1 >= points.len() || b >= points.len() {
if a + 1 >= points.len() {
None
} else {
Some(&points[a..])
}
}
// Added for Issue #36 where a sometimes equals b
else if a == b {
Some(&points[a..b])
} else {
Some(&points[a + 1..b])
}