добавил макросы для генерации функций типа прямо_поворот, поворот_прямо

main
serr 2025-06-25 20:59:31 +03:00
parent cd7249e272
commit ee3b0f36b0
1 changed files with 6 additions and 6 deletions

View File

@ -8,7 +8,7 @@ type ImgBufU8 = ImageBuffer<Rgb<u8>, Vec<u8>>;
type Colour = Rgb<u8>; type Colour = Rgb<u8>;
type Coord = (i32, i32); type Coord = (i32, i32);
macro_rules! rotation_move_combo { macro_rules! rotation_move {
($name:ident $rot:ident) => { ($name:ident $rot:ident) => {
pub fn $name(&mut self, degrees: f64, steps: u32) { pub fn $name(&mut self, degrees: f64, steps: u32) {
self.$rot(degrees); self.$rot(degrees);
@ -17,7 +17,7 @@ macro_rules! rotation_move_combo {
}; };
} }
macro_rules! move_rotation_combo { macro_rules! move_rotation {
($name:ident $rot:ident) => { ($name:ident $rot:ident) => {
pub fn $name(&mut self, steps: u32, degrees: f64) { pub fn $name(&mut self, steps: u32, degrees: f64) {
self.forward(steps); self.forward(steps);
@ -92,10 +92,10 @@ impl Turtle {
self.angle = self.angle.rem_euclid(2.0 * std::f64::consts::PI); self.angle = self.angle.rem_euclid(2.0 * std::f64::consts::PI);
} }
rotation_move_combo!(right_forward right); rotation_move!(right_forward right);
rotation_move_combo!(left_forward left); rotation_move!(left_forward left);
move_rotation_combo!(forward_right right); move_rotation!(forward_right right);
move_rotation_combo!(forward_left left); move_rotation!(forward_left left);
pub fn forward(&mut self, steps_count: u32) { pub fn forward(&mut self, steps_count: u32) {
let start_pos = self.pos; let start_pos = self.pos;