mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-26 06:30:29 +00:00
fix: round canvas coordinates to nearest grid cell
Previously the canvas coordinates were rounded towards zero, which causes the rendering to be off by one pixel in some cases. It also meant that pixels at the extreme edges of the canvas can only be drawn if the point was exactly on the edge of the canvas. This commit rounds the coordinates to the nearest integer instead.
This commit is contained in:
parent
a41c97b413
commit
cac4306ca4
5 changed files with 129 additions and 130 deletions
|
@ -389,20 +389,18 @@ impl<'a, 'b> Painter<'a, 'b> {
|
||||||
/// assert_eq!(point, Some((0, 0)));
|
/// assert_eq!(point, Some((0, 0)));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_point(&self, x: f64, y: f64) -> Option<(usize, usize)> {
|
pub fn get_point(&self, x: f64, y: f64) -> Option<(usize, usize)> {
|
||||||
let left = self.context.x_bounds[0];
|
let [left, right] = self.context.x_bounds;
|
||||||
let right = self.context.x_bounds[1];
|
let [bottom, top] = self.context.y_bounds;
|
||||||
let top = self.context.y_bounds[1];
|
|
||||||
let bottom = self.context.y_bounds[0];
|
|
||||||
if x < left || x > right || y < bottom || y > top {
|
if x < left || x > right || y < bottom || y > top {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let width = (self.context.x_bounds[1] - self.context.x_bounds[0]).abs();
|
let width = right - left;
|
||||||
let height = (self.context.y_bounds[1] - self.context.y_bounds[0]).abs();
|
let height = top - bottom;
|
||||||
if width == 0.0 || height == 0.0 {
|
if width <= 0.0 || height <= 0.0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let x = ((x - left) * (self.resolution.0 - 1.0) / width) as usize;
|
let x = ((x - left) * (self.resolution.0 - 1.0) / width).round() as usize;
|
||||||
let y = ((top - y) * (self.resolution.1 - 1.0) / height) as usize;
|
let y = ((top - y) * (self.resolution.1 - 1.0) / height).round() as usize;
|
||||||
Some((x, y))
|
Some((x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,10 @@ mod tests {
|
||||||
.y_bounds([-10.0, 10.0]);
|
.y_bounds([-10.0, 10.0]);
|
||||||
canvas.render(buffer.area, &mut buffer);
|
canvas.render(buffer.area, &mut buffer);
|
||||||
let expected = Buffer::with_lines([
|
let expected = Buffer::with_lines([
|
||||||
" ⢀⣠⢤⣀ ",
|
" ⣀⣀⣀ ",
|
||||||
" ⢰⠋ ⠈⣇",
|
" ⡞⠁ ⠈⢣",
|
||||||
" ⠘⣆⡀ ⣠⠇",
|
" ⢇⡀ ⢀⡼",
|
||||||
" ⠉⠉⠁ ",
|
" ⠉⠉⠉ ",
|
||||||
" ",
|
" ",
|
||||||
]);
|
]);
|
||||||
assert_eq!(buffer, expected);
|
assert_eq!(buffer, expected);
|
||||||
|
|
|
@ -124,9 +124,9 @@ mod tests {
|
||||||
use crate::canvas::Canvas;
|
use crate::canvas::Canvas;
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[case::off_grid(&Line::new(-1.0, -1.0, 10.0, 10.0, Color::Red), [" "; 10])]
|
#[case::off_grid1(&Line::new(-1.0, -1.0, 10.0, 10.0, Color::Red), [" "; 10])]
|
||||||
#[case::off_grid(&Line::new(0.0, 0.0, 11.0, 11.0, Color::Red), [" "; 10])]
|
#[case::off_grid2(&Line::new(0.0, 0.0, 11.0, 11.0, Color::Red), [" "; 10])]
|
||||||
#[case::horizontal(&Line::new(0.0, 0.0, 10.0, 0.0, Color::Red), [
|
#[case::horizontal1(&Line::new(0.0, 0.0, 10.0, 0.0, Color::Red), [
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
|
@ -138,7 +138,7 @@ mod tests {
|
||||||
" ",
|
" ",
|
||||||
"••••••••••",
|
"••••••••••",
|
||||||
])]
|
])]
|
||||||
#[case::horizontal(&Line::new(10.0, 10.0, 0.0, 10.0, Color::Red), [
|
#[case::horizontal2(&Line::new(10.0, 10.0, 0.0, 10.0, Color::Red), [
|
||||||
"••••••••••",
|
"••••••••••",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
|
@ -150,36 +150,36 @@ mod tests {
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
])]
|
])]
|
||||||
#[case::vertical(&Line::new(0.0, 0.0, 0.0, 10.0, Color::Red), ["• "; 10])]
|
#[case::vertical1(&Line::new(0.0, 0.0, 0.0, 10.0, Color::Red), ["• "; 10])]
|
||||||
#[case::vertical(&Line::new(10.0, 10.0, 10.0, 0.0, Color::Red), [" •"; 10])]
|
#[case::vertical2(&Line::new(10.0, 10.0, 10.0, 0.0, Color::Red), [" •"; 10])]
|
||||||
// dy < dx, x1 < x2
|
// dy < dx, x1 < x2
|
||||||
#[case::diagonal(&Line::new(0.0, 0.0, 10.0, 5.0, Color::Red), [
|
#[case::diagonal1(&Line::new(0.0, 0.0, 10.0, 5.0, Color::Red), [
|
||||||
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" •",
|
|
||||||
" ••",
|
" ••",
|
||||||
" •• ",
|
" •• ",
|
||||||
" •• ",
|
" •• ",
|
||||||
" •• ",
|
" •• ",
|
||||||
"• ",
|
"•• ",
|
||||||
])]
|
])]
|
||||||
// dy < dx, x1 > x2
|
// dy < dx, x1 > x2
|
||||||
#[case::diagonal(&Line::new(10.0, 0.0, 0.0, 5.0, Color::Red), [
|
#[case::diagonal2(&Line::new(10.0, 0.0, 0.0, 5.0, Color::Red), [
|
||||||
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
" ",
|
" ",
|
||||||
"• ",
|
|
||||||
"•• ",
|
"•• ",
|
||||||
" •• ",
|
" •• ",
|
||||||
" •• ",
|
" •• ",
|
||||||
" •• ",
|
" •• ",
|
||||||
" •",
|
" ••",
|
||||||
])]
|
])]
|
||||||
// dy > dx, y1 < y2
|
// dy > dx, y1 < y2
|
||||||
#[case::diagonal(&Line::new(0.0, 0.0, 5.0, 10.0, Color::Red), [
|
#[case::diagonal3(&Line::new(0.0, 0.0, 5.0, 10.0, Color::Red), [
|
||||||
" • ",
|
" • ",
|
||||||
" • ",
|
" • ",
|
||||||
" • ",
|
" • ",
|
||||||
|
@ -192,7 +192,7 @@ mod tests {
|
||||||
"• ",
|
"• ",
|
||||||
])]
|
])]
|
||||||
// dy > dx, y1 > y2
|
// dy > dx, y1 > y2
|
||||||
#[case::diagonal(&Line::new(0.0, 10.0, 5.0, 0.0, Color::Red), [
|
#[case::diagonal4(&Line::new(0.0, 10.0, 5.0, 0.0, Color::Red), [
|
||||||
"• ",
|
"• ",
|
||||||
" • ",
|
" • ",
|
||||||
" • ",
|
" • ",
|
||||||
|
|
|
@ -102,44 +102,44 @@ mod tests {
|
||||||
canvas.render(buffer.area, &mut buffer);
|
canvas.render(buffer.area, &mut buffer);
|
||||||
let expected = Buffer::with_lines([
|
let expected = Buffer::with_lines([
|
||||||
" ",
|
" ",
|
||||||
" ••••••• •• •• •• • ",
|
" • ",
|
||||||
" • •• •••••••• •• •••• ••••• ••• •• ••• ",
|
" • •• •••••••• •• •••• ••••• ••• •• ••• ",
|
||||||
" •••••••••••••••• •• ••• ••••••• •• •• ••• ",
|
" ••••••••••••••• • •••• • • ••••••• ••• ",
|
||||||
"• • •• •••••• •••••••••••• •• ••• • ••••• ••••••••• •• • • • • ",
|
" • •••• ••••••••••••••• •• •• • ••• •• •••• •• ••••••• ••• ",
|
||||||
"••••• •••• •••••••• •• •• ••• •••• •••• •• • • ",
|
"••••• •••••••••••• •••• • •••••• •••• • ••• ••••• •",
|
||||||
" •••••••• ••••••• ••••• ••• •••••••• • ••••• ",
|
" •• • • •••• •••••••• •••• •• • •• • ••• •• •••",
|
||||||
" •• •• •• ••••••• •• ••• •••• •• • ",
|
" •••• ••• •••••• ••••• • •• •••••• • ••••• ",
|
||||||
"••• ••• •••••• •••• •••• •• • •• ",
|
"••••• ••• • •• •• ••••••• •• •• •• ",
|
||||||
" • ••••••••• •• • ••• • •• •• •• ",
|
" •• •••• ••••• •• • • • •• ",
|
||||||
" • • •••• •• ••••••••• ••• • • • •• ",
|
" • • ••••••• •• •••• ••• •• • •• • •• ",
|
||||||
" • • ••••• •••• •• •••••• ",
|
" • •• ••••••••• • •• •••• • ",
|
||||||
|
" •• •• • • • •• • ••••• ",
|
||||||
" •• ••• • •••• • • • ",
|
" •• ••• • •••• • • • ",
|
||||||
" • • •• • •• •• • • ",
|
" • • •• • •• •• • • ",
|
||||||
" •• ••• ••• • • ••••• • ••• ",
|
" •• • ••••••• • • • • • •• • ",
|
||||||
" • •••• ••• • • • • • •• ",
|
" ••••••••• • •• • • • •• • •• ",
|
||||||
" •• •• • ••• • ••• •• ",
|
" •• •• • ••• • ••• •• ",
|
||||||
" ••• • • • • • •• ••• ••• ",
|
" ••• • • • • • •• ••• ••• ",
|
||||||
" • • • •• • • • • • ",
|
|
||||||
" • • • • • • ••• • • ",
|
|
||||||
" • • • • •• • • • ",
|
|
||||||
" • • •• ••• • ",
|
|
||||||
" • • • • • • • • ",
|
|
||||||
" • • • •• • • • • • ",
|
|
||||||
" • • • • ",
|
|
||||||
" • • • • • • ",
|
|
||||||
" • •• • • • • •• • ",
|
|
||||||
" • • • •••• •• ",
|
|
||||||
" • • •• • •• ",
|
" • • •• • •• ",
|
||||||
" •• • ",
|
|
||||||
" •• • ",
|
|
||||||
" •• ",
|
|
||||||
" ",
|
|
||||||
" • • ••• • • ••• ••• ",
|
" • • ••• • • ••• ••• ",
|
||||||
" •••• •••••• •••••• •••••• • ••• ",
|
" • • • • • ••• ",
|
||||||
" •• •••••• ••••• •• • ••• • •• ",
|
|
||||||
"• ••••• •• •• •••••• • •• ",
|
|
||||||
" • • • • • • • ",
|
" • • • • • • • ",
|
||||||
" • ",
|
" • • • • ••• •• •",
|
||||||
|
" • • • • •• • • • ",
|
||||||
|
" • • • • • ",
|
||||||
|
" • • • • • ",
|
||||||
|
" •• •• •• •• • • ",
|
||||||
|
" • • ••• •• ",
|
||||||
|
" • • •• •• ",
|
||||||
|
" • • ",
|
||||||
|
" ••••• ",
|
||||||
|
" ",
|
||||||
|
" •• ",
|
||||||
|
" ••• • • ••••• • •••• • • •• •• •• ",
|
||||||
|
" • • • •••••• ••••••••• • •• •• ••• ",
|
||||||
|
"• ••• •••• •••• • • • ••• • • ••• •",
|
||||||
|
" •• • • •• • •• •• ",
|
||||||
|
"• • • ",
|
||||||
" ",
|
" ",
|
||||||
]);
|
]);
|
||||||
assert_eq!(buffer, expected);
|
assert_eq!(buffer, expected);
|
||||||
|
@ -161,44 +161,44 @@ mod tests {
|
||||||
canvas.render(buffer.area, &mut buffer);
|
canvas.render(buffer.area, &mut buffer);
|
||||||
let expected = Buffer::with_lines([
|
let expected = Buffer::with_lines([
|
||||||
" ",
|
" ",
|
||||||
" ⢀⣠⠤⠤⠤⠔⢤⣤⡄⠤⡠⣄⠢⠂⢢⠰⣠⡄⣀⡀ ⣀ ",
|
" ⢀⣀⣤⠄⠤⠤⣤⣀⡀⣀⣀⡄⠄⢄⣀⣄⡄⢀⡀ ",
|
||||||
" ⢀⣀⡤⣦⠲⢶⣿⣮⣿⡉⣰⢶⢏⡂ ⢀⣟⠁ ⢺⣻⢿⠏ ⠈⠉⠁ ⢀⣀ ⠈⠓⢳⣢⣂⡀ ",
|
" ⢀⣀⣤⠰⢤⣼⡯⢽⡟⣀⢶⣺⡛⠁ ⠈⢰⠃⠁ ⢖⣒⣾⡟⠂ ⠈⠛⠁ ⠺⢩⢖⡄ ",
|
||||||
" ⡞⣳⣿⣻⡧⣷⣿⣿⢿⢿⣧⡀⠉⠉⠙⢆ ⣰⠇ ⣠⠞⠃⢉⣄⣀⣠⠴⠊⠉⠁ ⠐⠾⠤⢤⠤⡄⠐⣻⠜⢓⠂ ",
|
" ⡬⢍⣿⣟⣿⣻⣿⣿⣿⡾⣯⡀⠈⠁⠁⢦ ⢀⡿ ⠈ ⢠⢶⠘⠋⡁⣀⢠⠤⠖⠘⠉⠁⠈⠼⡧⡄⣄⡀ ⢫⣗⠒⠆ ",
|
||||||
"⢍ ⢀⡴⠊⠙⠓⠒⠒⠤⠖⠺⠿⠽⣷⣬⢬⣾⣷⢻⣷⢲⢲⣍⠱⡀ ⠹⡗ ⢀⢐⠟ ⡔⠒⠉⠲⠤⢀⢄⡀⢩⣣⠦⢷⢼⡏⠈ ⠉⠉⠉ ⠈⠈⠉⠖⠤⠆⠒⠭",
|
"⣓ ⣠⠖⠓⠒⠢⠤⢄⠤⠶⠽⠽⣶⣃⣽⡮⣿⡷⣗⣤⡭⣍⢓⡄ ⠸⣷ ⢀⣀⠿⠇ ⢀⠔⠒⠲⠄⢄⢀⡀⢙⣑⡄⠴⡍⣟⠉ ⠑⠉⠉ ⠑⠐⠦⠤⣤⠤⢞",
|
||||||
"⠶⢽⡲⣽⡆ ⠈⣠⣽⣯⡼⢯⣘⡯⠃⠘⡆ ⢰⠒⠁ ⢾⣚⠟ ⢀⠆ ⣔⠆ ⢷⠾⠋⠁ ⠙⠁ ⠠⡤",
|
"⠶⢧⣗⢾⡆ ⠈⠈⠁⠈⠉⢀⣹⣶⣩⣽⣐⢮⠃ ⣇ ⢀⡔⠊ ⢰⣖⣲ ⢀⡐⠁⣰⠦ ⢲⣶⠛⠋ ⠐⠋ ⡤",
|
||||||
" ⠠⢧⣄⣀⡶⠦⠤⡀ ⢰⡁ ⠉⡻⠙⣎⡥ ⠘⠲⠇ ⢀⡀⠨⣁⡄⣸⢫⡤⠄ ⣀⢠⣤⠊⣼⠅⠖⠋⠁",
|
" ⠉⣮⣀⣀⣴⡤⣠⡀ ⡎ ⠛⢫⠙⢫⢫ ⠈⠦⠼ ⡃⡀⢸⠼⣤⡄ ⡀⣀⣀⡐⡶⣣⢤⠖⠉",
|
||||||
" ⣠⠾⠛⠁ ⠈⣱ ⠋⠦⢤⡼ ⠈⠈⠦⡀ ⢀⣿⣇ ⢹⣷⣂⡞⠃ ⢀⣂⡀ ⠏⣜ ",
|
" ⢀⡽⠟⠃ ⠈⠱⡀ ⠙⠢⣀⣨⠆⠈⠁⢧⡀ ⣸⣷ ⢹⣷⣼⣸⠃ ⢀⡐⢀ ⠁⡚⣨⠆ ",
|
||||||
" ⠙⣷⡄ ⠘⠆ ⢀⣀⡠⣗ ⠘⣻⣽⡟⠉⠈ ⢹⡇ ⠟⠁ ",
|
" ⠘⢳⡀ ⠈⠾ ⣀⣀⣽ ⠸⢼⣇⡧⠋⠉⠁ ⠉⣿ ⠢⠂ ",
|
||||||
" ⠈⡟ ⢎⣻⡿⠾⠇ ⠘⠇ ⣀⡀ ⣤⣤⡆ ⡠⡦ ⢀⠎⡏ ",
|
" ⠈⢻ ⠜⢹⣵⠻⠇ ⠈⢻ ⢀⡀ ⢠⣠⡤ ⢀⢤ ⢰⣯ ",
|
||||||
" ⡇ ⣀⠏⠋ ⢸⠒⢃⡖⢻⢟⣷⣄⣰⣡⠥⣱ ⢏⣧ ⣀ ⡴⠚⢰⠟ ",
|
" ⢼ ⢀⣾⠛⠉ ⠐⡖⠒⡰⢺⣞⣵⡄⢀⣏⡭⣙⡄⢕⢫⡀ ⢀ ⢠⠖⢱⡿⠃ ",
|
||||||
" ⢳ ⢸⠃ ⠸⣄⣼⣠⢼⡴⡟⢿⢿⣀⣄ ⠸⡹ ⠘⡯⢿⡇⡠⢼⠁ ",
|
" ⠸ ⠠⡎ ⠰⣅⣰⣃⣘⡣⡿⢻⡿⣁⣀ ⠸⣽ ⠐⣿⣽⣫ ⡸⡇ ",
|
||||||
" ⢳⣀ ⢀⠞⠁ ⢠⠋⠁ ⠐⠧⡄⣬⣉⣈⡽ ⢧⠘⢽⠟⠉ ",
|
" ⠳⣄ ⡰⠃ ⢀⠎⠉ ⢧⡀⣠⣛⠈⢻ ⢻⠘⢺⡿⠚⠁ ",
|
||||||
" ⣿⣄ ⡴⠚⠛⣿⣀ ⢠⠖ ⠈⠁ ⠹⣧ ⢾⣄⡀ ⡼ ⠈ ",
|
" ⢻⣇ ⣠⠲⠖⢲⡇ ⡸ ⠉⠃⠈⠉⣿ ⢰⣆ ⢸ ⠈⠁ ",
|
||||||
" ⣀ ⠘⣿⡄ ⡇ ⣘⣻ ⡏ ⢻⡄ ⠘⠿⢿⠒⠲⡀ ⢀⡀ ⢀⡰⣗ ",
|
" ⠈⢿⣆ ⡟ ⣘⣻ ⡸ ⢸⢇ ⠈⠯⢿⡒⠲⡀ ⢀⡀ ⣀⢾ ",
|
||||||
" ⠉⠷ ⢫⡀⢧⡼⡟⠉⣛⣳⣦⡀ ⠈⡇ ⠸⣱ ⢀⡼ ⢺ ⡸⠉⢇ ⣾⡏ ⣁ ",
|
" ⠈⢳ ⠸⡀⢳⣠⢾⠉⢹⣦⣤⣀ ⡇ ⡿⡄ ⢰⠃ ⠑⡂ ⢠⠏⢣ ⣼⡮⠁⢈⡀ ",
|
||||||
" ⠉⠒⢆⡓⡆ ⠠⡃ ⢳⣇⡠⠏ ⠐⡄⡞ ⠘⣇⡀⢱ ⣾⡀ ",
|
" ⠙⠲⢆⡿⢦⠈⠉⠁⠁ ⡇ ⠱⣇⣀⠼⠃ ⡃⢰⠃ ⠸⢶ ⠘⠄ ⢾⡁ ",
|
||||||
" ⢹⣇⣀⣾⡷⠤⡆ ⢣ ⠯⢺⠇ ⢣⣅ ⣽⢱⡔ ⢠⢿⣗ ",
|
" ⠙⣾⣀⡴⡶⢤⣤ ⢳ ⠻⠵⡆ ⠸⣸ ⢸⡳⡤⠃⢀⡾⣿ ",
|
||||||
" ⠙⢱ ⠘⠦⡄ ⠈⢦⡠⣠⢶⣀ ⡜ ⠈⠿ ⢠⣽⢆ ⢀⣼⡜⠿ ",
|
" ⠘⢻⠁ ⠈⠦⣄ ⢧⣀⣀⠤⣀ ⢐⠁ ⠈⠩⠆ ⣘⣧⠁ ⡸⡔⢿ ",
|
||||||
" ⢀⡞ ⢱⡀ ⢸ ⡔⠁ ⢻⢿⢰⠏⢸⣤⣴⣆ ",
|
" ⡸ ⢨ ⠁ ⠉⡇ ⢀⠎ ⢻⢿⠄⡴⢑⣧⡠⡄ ",
|
||||||
" ⢘⠆ ⠙⠢⢄ ⠸⡀ ⡸⠁ ⠈⣞⡎⠥⡟⣿⠠⠿⣷⠒⢤⢀⣆ ",
|
" ⡇ ⠈⠋⠦⡄ ⠈⡆ ⢠⠃ ⢏⡇⢧⣼⣾⣧⣽⣿⠶⢤⡀⣤ ",
|
||||||
" ⠘⠆ ⢈⠂ ⢳ ⡇ ⠈⠳⠶⣤⣭⣠ ⠋⢧⡬⣟⠉⠷⡄ ",
|
" ⣇ ⠈⡇ ⢸ ⢸ ⠈⠶⣦⣄⣋⣁⡀⠸⣵⢠⣻⠋⠷⣄ ",
|
||||||
" ⢨ ⡜ ⢸ ⠸ ⣠ ⠁⢁⣰⢶ ⡇⠉⠁ ⠛ ",
|
" ⠰⡀ ⣰⠁ ⢘⠆ ⢸ ⢠⡀ ⠙⠋⢠⠦⡄⣷⠙⠃ ⠙ ",
|
||||||
"⠆ ⠈⢱⡀ ⡆ ⡇ ⢀⡜⡴⢹ ⢰⠏⠁⠘⢶⠹⡀ ⠸ ⢠⡶",
|
"⠄ ⠣⡀ ⡃ ⢸ ⣸⢡⢾⠆ ⡞⠛⠘⢧⡏⡆ ⠸⠄ ⡤",
|
||||||
" ⠅ ⣸ ⢸ ⢫ ⡞⡊ ⢠⠔⠋ ⢳⡀ ⠐⣦ ",
|
" ⠱ ⢠⠃ ⠸⡀ ⢸⠁⢸⢨ ⡤⠚ ⠱⡀ ⢦ ⠁",
|
||||||
" ⡅ ⡏ ⠈⡆ ⢠⠎ ⠳⠃ ⢸ ⢳ ",
|
" ⠅ ⡖⠉ ⡇ ⡜ ⠸⠔ ⡇ ⢳ ",
|
||||||
" ⠨ ⡸⠁ ⢱ ⡸ ⠈⡇ ⢀⣀⡀ ⢸ ",
|
" ⡇ ⢀⠃ ⢱⡀ ⢰⠃ ⣇ ⢀⡀ ⢸ ",
|
||||||
" ⠸ ⠐⡶⠁ ⠘⠖⠚ ⠣⠒⠋ ⠱⣇ ⢀⠇ ⠰⡄ ",
|
" ⢀⠃ ⡦⠏ ⠈⠷⠖⠃ ⠾⠴⠊⠁⠹⣦ ⡞ ⣄ ",
|
||||||
" ⠽ ⣰⡖⠁ ⠘⢚⡊ ⢀⣿⠇",
|
" ⢸ ⡤⠃ ⠘⢲⠖⠃ ⣽⡆",
|
||||||
" ⡯⢀⡟ ⠘⠏ ⢠⢾⠃ ",
|
" ⢸ ⣸⠁ ⠈⠿ ⢀⢼⠏ ",
|
||||||
" ⠇⢨⠆ ⢠⡄ ⠈⠁ ",
|
" ⠞ ⡗ ⣄ ⠈⠋ ",
|
||||||
" ⢧⣷⡀⠚ ",
|
" ⢧⡼⡁⠲⠂ ",
|
||||||
" ⠉⠁ ",
|
" ⠙⠉ ",
|
||||||
" ⢀⡀ ",
|
" ⡀ ",
|
||||||
" ⢠⡾⠋ ⣀⡠⠖⢦⣀⣀ ⣀⠤⠦⢤⠤⠶⠤⠖⠦⠤⠤⠤⠴⠤⢤⣄ ",
|
" ⣴⠏⠁ ⣀⡤⢤⣀⣀ ⢀⣀⣤⣀⣀⡴⣄⡤⢤⣀⠤⠤⠴⣄⣀⡀ ",
|
||||||
" ⢀⣤⣀ ⡀ ⣼⣻⠙⡆ ⢀⡤⠤⠤⠴⠒⠖⠒⠒⠒⠚⠉⠋⠁ ⢰⡳⠊⠁ ⠈⠉⠉⠒⠤⣤ ",
|
" ⣀⣀ ⣠⣿⡍⣆ ⣠⣤⣤⠤⠴⠶⠖⠲⠤⠔⠛⠒⠉ ⠈⠨⣇⠖⠋ ⠈⠉⠓⠢⠤⢄ ",
|
||||||
" ⢀⣀⣀⡴⠖⠒⠒⠚⠛⠛⠛⠒⠚⠳⠉⠉⠉⠉⢉⣉⡥⠔⠃ ⢀⣠⠤⠴⠃ ⢠⠞⠁ ",
|
" ⡀ ⣠⠤⠴⠒⠚⠛⠛⠒⠢⠤⠿⠙⠉⠉⠑⢋⣚⣉⠥⠚ ⢀⣀⡠⠟⠁ ⡴⠋ ",
|
||||||
" ⠘⠛⣓⣒⠆ ⠸⠥⣀⣤⡦⠠⣞⣭⣇⣘⠿⠆ ⣖⠛ ",
|
" ⠐⠶⣛⣫⡤ ⠐⢏⣀⣤⣤ ⣴⣋⢇⢀⣮⡥ ⣴⠓ ",
|
||||||
"⠶⠔⠲⠤⠠⠜⢗⠤⠄ ⠘⠉ ⠁ ⠈⠉⠒⠔⠤",
|
"⠤⠤⠤⠤⡀⣈⢣⣠⡄ ⠉⠊⠉⠉⠉ ⠈⠓⠆⠤⠤",
|
||||||
" ",
|
" ",
|
||||||
]);
|
]);
|
||||||
assert_eq!(buffer, expected);
|
assert_eq!(buffer, expected);
|
||||||
|
|
|
@ -149,42 +149,43 @@ mod tests {
|
||||||
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
|
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
|
||||||
let canvas = Canvas::default()
|
let canvas = Canvas::default()
|
||||||
.marker(Marker::Braille)
|
.marker(Marker::Braille)
|
||||||
.x_bounds([0.0, 10.0])
|
.x_bounds([0.0, 20.0])
|
||||||
.y_bounds([0.0, 10.0])
|
.y_bounds([0.0, 20.0])
|
||||||
.paint(|context| {
|
.paint(|context| {
|
||||||
// a rectangle that will draw the outside part of the braille
|
// a rectangle that will draw the outside part of the braille
|
||||||
context.draw(&Rectangle {
|
context.draw(&Rectangle {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
width: 10.0,
|
width: 20.0,
|
||||||
height: 10.0,
|
height: 20.0,
|
||||||
color: Color::Red,
|
color: Color::Red,
|
||||||
});
|
});
|
||||||
// a rectangle that will draw the inside part of the braille
|
// a rectangle that will draw the inside part of the braille
|
||||||
context.draw(&Rectangle {
|
context.draw(&Rectangle {
|
||||||
x: 2.0,
|
x: 4.0,
|
||||||
y: 1.75,
|
y: 4.0,
|
||||||
width: 6.5,
|
width: 12.0,
|
||||||
height: 6.5,
|
height: 12.0,
|
||||||
color: Color::Green,
|
color: Color::Green,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
canvas.render(buffer.area, &mut buffer);
|
canvas.render(buffer.area, &mut buffer);
|
||||||
let mut expected = Buffer::with_lines([
|
let mut expected = Buffer::with_lines([
|
||||||
"⡏⠉⠉⠉⠉⠉⠉⠉⠉⢹",
|
"⡏⠉⠉⠉⠉⠉⠉⠉⠉⢹",
|
||||||
"⡇⢠⠤⠤⠤⠤⠤⠤⡄⢸",
|
"⡇ ⢸",
|
||||||
"⡇⢸ ⡇⢸",
|
"⡇ ⡏⠉⠉⠉⠉⢹ ⢸",
|
||||||
"⡇⢸ ⡇⢸",
|
"⡇ ⡇ ⢸ ⢸",
|
||||||
"⡇⢸ ⡇⢸",
|
"⡇ ⡇ ⢸ ⢸",
|
||||||
"⡇⢸ ⡇⢸",
|
"⡇ ⡇ ⢸ ⢸",
|
||||||
"⡇⢸ ⡇⢸",
|
"⡇ ⡇ ⢸ ⢸",
|
||||||
"⡇⢸ ⡇⢸",
|
"⡇ ⣇⣀⣀⣀⣀⣸ ⢸",
|
||||||
"⡇⠈⠉⠉⠉⠉⠉⠉⠁⢸",
|
"⡇ ⢸",
|
||||||
"⣇⣀⣀⣀⣀⣀⣀⣀⣀⣸",
|
"⣇⣀⣀⣀⣀⣀⣀⣀⣀⣸",
|
||||||
]);
|
]);
|
||||||
expected.set_style(buffer.area, Style::new().red());
|
expected.set_style(buffer.area, Style::new().red());
|
||||||
expected.set_style(buffer.area.inner(Margin::new(1, 1)), Style::new().green());
|
expected.set_style(buffer.area.inner(Margin::new(1, 1)), Style::reset());
|
||||||
expected.set_style(buffer.area.inner(Margin::new(2, 2)), Style::reset());
|
expected.set_style(buffer.area.inner(Margin::new(2, 2)), Style::new().green());
|
||||||
|
expected.set_style(buffer.area.inner(Margin::new(3, 3)), Style::reset());
|
||||||
assert_eq!(buffer, expected);
|
assert_eq!(buffer, expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue