Skip to content

Commit

Permalink
Fix argument ordering in rect transform (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
jermy authored Jul 24, 2024
1 parent b59a73c commit eec0a47
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions path/src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,18 @@ impl Rect {
Some(*self)
} else if ts.has_skew() {
// we need to transform all 4 corners
let tl = Point::from_xy(self.top(), self.left());
let tr = Point::from_xy(self.top(), self.right());
let bl = Point::from_xy(self.bottom(), self.left());
let br = Point::from_xy(self.bottom(), self.right());
let mut pts = [tl, tr, bl, br];
let lt = Point::from_xy(self.left(), self.top());
let rt = Point::from_xy(self.right(), self.top());
let lb = Point::from_xy(self.left(), self.bottom());
let rb = Point::from_xy(self.right(), self.bottom());
let mut pts = [lt, rt, lb, rb];
ts.map_points(&mut pts);
Self::from_points(&pts)
} else {
// Faster (more common) case
let tl = Point::from_xy(self.top(), self.left());
let br = Point::from_xy(self.bottom(), self.right());
let mut pts = [tl, br];
let lt = Point::from_xy(self.left(), self.top());
let rb = Point::from_xy(self.right(), self.bottom());
let mut pts = [lt, rb];
ts.map_points(&mut pts);
Self::from_points(&pts)
}
Expand Down Expand Up @@ -539,6 +539,31 @@ mod rect_tests {
assert_eq!(rect.round(), None);
assert_eq!(rect.round_out(), None);
}

#[test]
fn transform() {
// Tests based on 2x2 rectangle
let rect = Rect::from_ltrb(1.0, 2.0, 3.0, 4.0).unwrap();

let ts = Transform::identity();
assert_eq!(rect.transform(ts).unwrap(), rect);

// Scale x by 1x, y by 2x
let ts = Transform::from_scale(1.0, 2.0);
let rect_ts: Rect = Rect::from_ltrb(1.0, 4.0, 3.0, 8.0).unwrap();
assert_eq!(rect.transform(ts).unwrap(), rect_ts);

// Skew box along x-axis - vertical lines at y=c go to y=c+x and
// horizonal lines stay put. Result is bounding box
let ts = Transform::from_skew(1.0, 0.0);
let bounding_rect: Rect = Rect::from_ltrb(3.0, 2.0, 7.0, 4.0).unwrap();
assert_eq!(rect.transform(ts).unwrap(), bounding_rect);

// Skew box along y-axis - horizonal lines at x=c go to x=c+2y
let ts = Transform::from_skew(0.0, 2.0);
let bounding_rect: Rect = Rect::from_ltrb(1.0, 4.0, 3.0, 10.0).unwrap();
assert_eq!(rect.transform(ts).unwrap(), bounding_rect);
}
}

/// A rectangle defined by left, top, right and bottom edges.
Expand Down

0 comments on commit eec0a47

Please sign in to comment.