draw_rectangle

Function draw_rectangle 

Source
pub fn draw_rectangle(
    grid: &mut BrailleGrid,
    x: i32,
    y: i32,
    width: u32,
    height: u32,
) -> Result<(), DotmaxError>
Expand description

Draw a rectangle outline on the braille grid.

Draws a rectangle by rendering four lines (top, right, bottom, left edges) using the Bresenham line algorithm. The rectangle is defined by its top-left corner position and dimensions.

§Arguments

  • grid - Mutable reference to BrailleGrid to draw on
  • x, y - Top-left corner in dot coordinates (signed for clipping)
  • width, height - Rectangle dimensions in dots (must be > 0)

§Returns

  • Ok(()) on success
  • Err(DotmaxError::InvalidDimensions) if width or height is 0

§Examples

use dotmax::{BrailleGrid, primitives::shapes::draw_rectangle};

let mut grid = BrailleGrid::new(80, 24)?; // 160×96 dots

// Small rectangle
draw_rectangle(&mut grid, 10, 10, 50, 30)?;

// Large rectangle
draw_rectangle(&mut grid, 0, 0, 160, 96)?;

// Rectangle partially off-grid (clipped automatically)
draw_rectangle(&mut grid, -10, -10, 50, 50)?;

§Performance

O(perimeter) where perimeter = 2×(width + height). Typically <1ms for 100×50 rectangle.

§Errors

Returns InvalidDimensions if width == 0 or height == 0.