pub fn into_blocks(mut self, erase: bool) -> Vec<Block> {
        // Start a new drawing
        self.add_command(Command::StartDrawing);

        // First, erase the entire board.
        if erase {
            self.erase_all();
        } else {
            // If we used the eraser, we're already at `(0, 0)` coordinates.
            self.add_command(Command::PenLift);
            self.add_command(Command::Move(0, 0));
        }

        // Now add the drawing commands to the buffer
        for polyline in self.polylines {
            if polyline.len() < 2 {
                warn!("Skipping polyline with less than 2 coordinate pairs");
                continue;
            }

            let start = polyline[0];
            self.add_command(Command::Move(
                (fix_x(start.x) * 10.0) as u16,
                (fix_y(start.y) * 10.0) as u16,
            ));
            self.add_command(Command::PenDown);
            for point in polyline[1..].iter() {
                self.add_command(Command::Move(
                    (fix_x(point.x) * 10.0) as u16,
                    (fix_y(point.y) * 10.0) as u16,
                ));
            }
            self.add_command(Command::PenLift);
        }

        // Move back to start, done
        self.add_command(Command::Move(0, 0));
        self.add_command(Command::StopDrawing);

        // Then, divide up the buffer into blocks
        let mut blocks = vec![];
        for (i, chunk) in self.buf.chunks(self.block_size - 6).enumerate() {
            let mut block = vec![];
            block.extend_from_slice(&Command::BlockStart.to_bytes());
            block.extend_from_slice(&Command::BlockNumber((i+1) as u16).to_bytes());
            block.extend_from_slice(chunk);
            blocks.push(block);
        }
        blocks
    }
/// Convert the sketch into one or more byte vectors (blocks), ready to be
/// sent to the robot via serial.
Convert the sketch into one or more byte vectors (blocks), ready to be
sent to the robot via serial.
Convert the sketch into one or more byte vectors ( blocks ) ready to be sent to the robot via serial .
pub fn into_blocks(mut self, erase: bool) -> Vec<Block> {
        // Start a new drawing
        self.add_command(Command::StartDrawing);
        // First, erase the entire board.
        if erase {
            self.erase_all();
        } else {
            // If we used the eraser, we're already at `(0, 0)` coordinates.
            self.add_command(Command::PenLift);
            self.add_command(Command::Move(0, 0));
        }
        // Now add the drawing commands to the buffer
        for polyline in self.polylines {
            if polyline.len() < 2 {
                warn!("Skipping polyline with less than 2 coordinate pairs");
                continue;
            }
            let start = polyline[0];
            self.add_command(Command::Move(
                (fix_x(start.x) * 10.0) as u16,
                (fix_y(start.y) * 10.0) as u16,
            ));
            self.add_command(Command::PenDown);
            for point in polyline[1..].iter() {
                self.add_command(Command::Move(
                    (fix_x(point.x) * 10.0) as u16,
                    (fix_y(point.y) * 10.0) as u16,
                ));
            }
            self.add_command(Command::PenLift);
        }
        // Move back to start, done
        self.add_command(Command::Move(0, 0));
        self.add_command(Command::StopDrawing);
        // Then, divide up the buffer into blocks
        let mut blocks = vec![];
        for (i, chunk) in self.buf.chunks(self.block_size - 6).enumerate() {
            let mut block = vec![];
            block.extend_from_slice(&Command::BlockStart.to_bytes());
            block.extend_from_slice(&Command::BlockNumber((i+1) as u16).to_bytes());
            block.extend_from_slice(chunk);
            blocks.push(block);
        }
        blocks
    }
pub fn into_blocks ( mut self , erase : bool ) -> Vec < Block > { // Start a new drawing self . add_command ( Command :: StartDrawing ) ; // First, erase the entire board. if erase { self . erase_all ( ) ; } else { // If we used the eraser, we're already at `(0, 0)` coordinates. self . add_command ( Command :: PenLift ) ; self . add_command ( Command :: Move ( 0 , 0 ) ) ; } // Now add the drawing commands to the buffer for polyline in self . polylines { if polyline . len ( ) < 2 { warn ! ( " " ) ; continue ; } let start = polyline [ 0 ] ; self . add_command ( Command :: Move ( ( fix_x ( start . x ) * 10.0 ) as u16 , ( fix_y ( start . y ) * 10.0 ) as u16 , ) ) ; self . add_command ( Command :: PenDown ) ; for point in polyline [ 1 .. ] . iter ( ) { self . add_command ( Command :: Move ( ( fix_x ( point . x ) * 10.0 ) as u16 , ( fix_y ( point . y ) * 10.0 ) as u16 , ) ) ; } self . add_command ( Command :: PenLift ) ; } // Move back to start, done self . add_command ( Command :: Move ( 0 , 0 ) ) ; self . add_command ( Command :: StopDrawing ) ; // Then, divide up the buffer into blocks let mut blocks = vec ! [ ] ; for ( i , chunk ) in self . buf . chunks ( self . block_size - 6 ) . enumerate ( ) { let mut block = vec ! [ ] ; block . extend_from_slice ( & Command :: BlockStart . to_bytes ( ) ) ; block . extend_from_slice ( & Command :: BlockNumber ( ( i + 1 ) as u16 ) . to_bytes ( ) ) ; block . extend_from_slice ( chunk ) ; blocks . push ( block ) ; } blocks }
Convert the sketch into one or more byte vectors (blocks), ready to be
sent to the robot via serial.
Convert the sketch into one or more byte vectors ( blocks ) ready to be sent to the robot via serial .
mut self
erase
bool
mut self
erase
bool