Skip to content

Commit 3d25fbe

Browse files
newinnovationsginnyTheCat
authored andcommitted
refactor IRect::union, undo style changes
1 parent 71d9f09 commit 3d25fbe

File tree

1 file changed

+21
-56
lines changed

1 file changed

+21
-56
lines changed

src/rect.rs

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use std::fmt;
22

3-
use mupdf_sys::{
4-
fz_intersect_irect, fz_intersect_rect, fz_irect, fz_irect_from_rect, fz_rect, fz_round_rect,
5-
fz_transform_rect, fz_union_rect, mupdf_adjust_rect_for_stroke,
6-
};
3+
use mupdf_sys::*;
74

85
use crate::{context, Error, Matrix, Point, Quad, Size, StrokeState};
96

@@ -78,26 +75,10 @@ impl IRect {
7875
*self
7976
} else {
8077
IRect {
81-
x0: if other.x0 < self.x0 {
82-
other.x0
83-
} else {
84-
self.x0
85-
},
86-
y0: if other.y0 < self.y0 {
87-
other.y0
88-
} else {
89-
self.y0
90-
},
91-
x1: if other.x1 > self.x1 {
92-
other.x1
93-
} else {
94-
self.x1
95-
},
96-
y1: if other.y1 > self.y1 {
97-
other.y1
98-
} else {
99-
self.y1
100-
},
78+
x0: self.x0.min(other.x0),
79+
y0: self.y0.min(other.y0),
80+
x1: self.x1.max(other.x1),
81+
y1: self.y1.max(other.y1),
10182
}
10283
}
10384
}
@@ -115,23 +96,15 @@ impl fmt::Display for IRect {
11596

11697
impl From<fz_irect> for IRect {
11798
fn from(r: fz_irect) -> IRect {
118-
IRect {
119-
x0: r.x0,
120-
y0: r.y0,
121-
x1: r.x1,
122-
y1: r.y1,
123-
}
99+
let fz_irect { x0, y0, x1, y1 } = r;
100+
IRect { x0, y0, x1, y1 }
124101
}
125102
}
126103

127104
impl From<IRect> for fz_irect {
128-
fn from(r: IRect) -> Self {
129-
fz_irect {
130-
x0: r.x0,
131-
y0: r.y0,
132-
x1: r.x1,
133-
y1: r.y1,
134-
}
105+
fn from(val: IRect) -> Self {
106+
let IRect { x0, y0, x1, y1 } = val;
107+
fz_irect { x0, y0, x1, y1 }
135108
}
136109
}
137110

@@ -251,33 +224,25 @@ impl From<IRect> for Rect {
251224

252225
impl From<Quad> for Rect {
253226
fn from(q: Quad) -> Rect {
254-
Rect {
255-
x0: q.ul.x.min(q.ur.x).min(q.ll.x).min(q.lr.x),
256-
y0: q.ul.y.min(q.ur.y).min(q.ll.y).min(q.lr.y),
257-
x1: q.ul.x.max(q.ur.x).max(q.ll.x).max(q.lr.x),
258-
y1: q.ul.y.max(q.ur.y).max(q.ll.y).max(q.lr.y),
259-
}
227+
let Quad { ul, ur, ll, lr } = q;
228+
let x0 = ul.x.min(ur.x).min(ll.x).min(lr.x);
229+
let y0 = ul.y.min(ur.y).min(ll.y).min(lr.y);
230+
let x1 = ul.x.max(ur.x).max(ll.x).max(lr.x);
231+
let y1 = ul.y.max(ur.y).max(ll.y).max(lr.y);
232+
Rect { x0, y0, x1, y1 }
260233
}
261234
}
262235

263236
impl From<fz_rect> for Rect {
264237
fn from(r: fz_rect) -> Rect {
265-
Rect {
266-
x0: r.x0,
267-
y0: r.y0,
268-
x1: r.x1,
269-
y1: r.y1,
270-
}
238+
let fz_rect { x0, y0, x1, y1 } = r;
239+
Rect { x0, y0, x1, y1 }
271240
}
272241
}
273242

274243
impl From<Rect> for fz_rect {
275-
fn from(r: Rect) -> Self {
276-
fz_rect {
277-
x0: r.x0,
278-
y0: r.y0,
279-
x1: r.x1,
280-
y1: r.y1,
281-
}
244+
fn from(val: Rect) -> Self {
245+
let Rect { x0, y0, x1, y1 } = val;
246+
fz_rect { x0, y0, x1, y1 }
282247
}
283248
}

0 commit comments

Comments
 (0)