Small code cleanup

This commit is contained in:
daa 2017-04-23 13:42:05 +03:00
parent 37c8b48015
commit 83b5798f6f
2 changed files with 10 additions and 7 deletions

View File

@ -533,9 +533,7 @@ fn draw(state: &State, ctx: &cairo::Context) {
ctx.move_to(line_x, line_y); ctx.move_to(line_x, line_y);
for (col_idx, cell) in line.iter() { for (col_idx, cell) in line.iter() {
let double_width = line.get(col_idx + 1) let double_width = line.is_double_width(col_idx);
.map(|c| c.attrs.double_width)
.unwrap_or(false);
let current_point = ctx.get_current_point(); let current_point = ctx.get_current_point();
let (bg, fg) = state.colors(cell); let (bg, fg) = state.colors(cell);

View File

@ -310,9 +310,7 @@ impl ModelRect {
} }
fn contains(&self, other: &ModelRect) -> bool { fn contains(&self, other: &ModelRect) -> bool {
self.top <= other.top && self.top <= other.top && self.bot >= other.bot && self.left <= other.left &&
self.bot >= other.bot &&
self.left <= other.left &&
self.right >= other.right self.right >= other.right
} }
@ -435,6 +433,13 @@ impl<'a> ClipLine<'a> {
} }
} }
#[inline]
pub fn is_double_width(&self, col_idx: usize) -> bool {
self.get(col_idx + 1)
.map(|c| c.attrs.double_width)
.unwrap_or(false)
}
pub fn get(&self, idx: usize) -> Option<&Cell> { pub fn get(&self, idx: usize) -> Option<&Cell> {
self.line.get(idx) self.line.get(idx)
} }
@ -477,7 +482,7 @@ mod tests {
#[test] #[test]
fn test_vec_join_inside() { fn test_vec_join_inside() {
let mut list = ModelRectVec::new(ModelRect::new(0, 23, 0, 69)); let mut list = ModelRectVec::new(ModelRect::new(0, 23, 0, 69));
let inside = ModelRect::new(23, 23, 68, 69); let inside = ModelRect::new(23, 23, 68, 69);