Skip to content

Commit

Permalink
chore: fix things from merge && adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RobWalt authored and dabreegster committed Feb 20, 2024
1 parent 61e28c6 commit fb6acc9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 39 deletions.
37 changes: 3 additions & 34 deletions geo/src/algorithm/affine_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,37 +216,6 @@ impl<T: CoordNum + Neg> AffineTransform<T> {
)
}

/// Return the inverse of a given transform. Composing a transform with its inverse yields
/// the [identity matrix](Self::identity)
pub fn inverse(&self) -> Option<Self>
where
<T as Neg>::Output: Mul<T>,
<<T as Neg>::Output as Mul<T>>::Output: ToPrimitive,
{
let a = self.0[0][0];
let b = self.0[0][1];
let xoff = self.0[0][2];
let d = self.0[1][0];
let e = self.0[1][1];
let yoff = self.0[1][2];

let determinant = a * e - b * d;

if determinant == T::zero() {
return None; // The matrix is not invertible
}

let inv_det = T::one() / determinant;
Some(Self::new(
e * inv_det,
T::from(-b * inv_det).unwrap(),
(b * yoff - e * xoff) * inv_det,
T::from(-d * inv_det).unwrap(),
a * inv_det,
(d * xoff - a * yoff) * inv_det,
))
}

/// Whether the transformation is equivalent to the [identity matrix](Self::identity),
/// that is, whether it's application will be a a no-op.
///
Expand Down Expand Up @@ -376,7 +345,7 @@ impl<T: CoordNum + Neg> AffineTransform<T> {
}
}

impl<T: CoordNum> fmt::Debug for AffineTransform<T> {
impl<T: CoordNum + Neg> fmt::Debug for AffineTransform<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AffineTransform")
.field("a", &self.0[0][0])
Expand Down Expand Up @@ -489,7 +458,7 @@ impl<U: CoordFloat> AffineTransform<U> {
#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for AffineTransform<T>
where
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq,
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq + Neg,
{
#[inline]
fn default_max_relative() -> Self::Epsilon {
Expand Down Expand Up @@ -525,7 +494,7 @@ where
#[cfg(any(feature = "approx", test))]
impl<T> AbsDiffEq for AffineTransform<T>
where
T: AbsDiffEq<Epsilon = T> + CoordNum,
T: AbsDiffEq<Epsilon = T> + CoordNum + Neg,
T::Epsilon: Copy,
{
type Epsilon = T;
Expand Down
9 changes: 7 additions & 2 deletions geo/src/algorithm/spade_boolops/tests/legacy_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ fn test_rect_overlapping() {
let wkt1 = "POLYGON((0 0,1 0,1 1,0 1,0 0))";
let wkt2 = "POLYGON((0.5 1,2 1,2 2,0.5 2,0.5 1))";

let wkt_union = "MULTIPOLYGON(((0.5 2,0.5 1,0 1,0 0,1 0,1 1,2 1,2 2,0.5 2)))";
let wkt_union = "MULTIPOLYGON(((0.5 1,0 1,0 0,1 0,1 1,2 1,2 2,0.5 2, 0.5 1)))";
let [p1, p2] = check_op::<f64>(wkt1, wkt2);
let output = MultiPolygon::union(&p1, &p2).expect("boolop works");
assert_eq!(output, MultiPolygon::try_from_wkt_str(wkt_union).unwrap());
let expected = MultiPolygon::try_from_wkt_str(wkt_union).unwrap();
assert_eq!(
output, expected,
"out: {output:?} vs expected: {expected:?}"
);
}

#[test]
Expand Down Expand Up @@ -141,6 +145,7 @@ fn test_issue_885_big_simplified() {

// care: This test highlights that the SpadeBoolops algo is awfully slow! :S
#[test]
#[ignore = "takes too long for CI"]
fn test_issue_894() {
_ = pretty_env_logger::try_init();
use geo_test_fixtures::multi_polygon;
Expand Down
10 changes: 7 additions & 3 deletions geo/src/algorithm/spade_boolops/tests/spade_boolops_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ macro_rules! define_test {
} else {
is_multipolygon_nonempty(&res);
}

use wkt::ToWkt;
println!("{}", res.to_wkt());

has_num_polygons(&res, $num_polys);
has_num_holes(&res, $num_holes);
has_num_vertices(&res, $num_verts);
Expand Down Expand Up @@ -596,9 +600,9 @@ define_test!(
},
results:
empty = false,
num_polys = 2,
num_holes = vec![0, 0],
num_verts = vec![10, 5],
num_polys = 1,
num_holes = vec![0],
num_verts = vec![14],
);

define_test!(
Expand Down

0 comments on commit fb6acc9

Please sign in to comment.