Skip to content

Commit e5dd9c5

Browse files
committed
Revert to safer Neg trait bound
1 parent c62deb4 commit e5dd9c5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

geo/src/algorithm/affine_ops.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<T: CoordNum> AffineTransform<T> {
279279
}
280280
}
281281

282-
impl<T: CoordNum + Neg<Output = T>> AffineTransform<T> {
282+
impl<T: CoordNum + Neg> AffineTransform<T> {
283283
/// Return the inverse of a given transform. Composing a transform with its inverse yields
284284
/// the [identity matrix](Self::identity)
285285
#[must_use]
@@ -300,16 +300,20 @@ impl<T: CoordNum + Neg<Output = T>> AffineTransform<T> {
300300
if determinant == T::zero() {
301301
return None; // The matrix is not invertible
302302
}
303-
304303
let inv_det = T::one() / determinant;
305-
Some(Self::new(
306-
e * inv_det,
307-
-b * inv_det,
308-
(b * yoff - e * xoff) * inv_det,
309-
-d * inv_det,
310-
a * inv_det,
311-
(d * xoff - a * yoff) * inv_det,
312-
))
304+
305+
// If conversion of either the b or d matrix value fails, bail out
306+
match (T::from(-b * inv_det), T::from(-d * inv_det)) {
307+
(Some(inv_b), Some(inv_d)) => Some(Self::new(
308+
e * inv_det,
309+
inv_b,
310+
(b * yoff - e * xoff) * inv_det,
311+
inv_d,
312+
a * inv_det,
313+
(d * xoff - a * yoff) * inv_det,
314+
)),
315+
_ => None,
316+
}
313317
}
314318
}
315319

0 commit comments

Comments
 (0)