// tag::apply[]
/// apply a single step to the ship with or without waypoint (for part 1 and part 2
/// respectively)
///
/// # Examples
/// ```
/// let mut ship = mr_kaffee_2020_12::Ship::new();
///
/// // ship starts at (0, 0)
/// assert_eq!(ship.distance(), 0);
///
/// ship.apply(&mr_kaffee_2020_12::Step::North(20), false);
/// // ship will be at (0, 10)
/// assert_eq!(ship.distance(), 20);
///
/// ship.apply(&mr_kaffee_2020_12::Step::Fwd(1), false);
/// // waypoint is at (10, 1) -> ship will be at (10, 11)
/// assert_eq!(ship.distance(), 21);
/// ```
:apply[]
apply a single step to the ship with or without waypoint (for part 1 and part 2
respectively)
: apply [] apply a single step to the ship with or without waypoint ( for part 1 and part 2 respectively )
pub fn apply(&mut self, instr: &Step, use_wp: bool) {
        if use_wp {
            match instr {
                Step::North(v) => self.wp.1 += v,
                Step::South(v) => self.wp.1 -= v,
                Step::East(v) => self.wp.0 += v,
                Step::West(v) => self.wp.0 -= v,
                Step::Left => self.wp = (-self.wp.1, self.wp.0),
                Step::Reverse => self.wp = (-self.wp.0, -self.wp.1),
                Step::Right => self.wp = (self.wp.1, -self.wp.0),
                Step::Fwd(v) => self.pos =
                    (self.pos.0 + v * self.wp.0, self.pos.1 + v * self.wp.1),
            };
        } else {
            match instr {
                Step::North(v) => self.pos.1 += v,
                Step::South(v) => self.pos.1 -= v,
                Step::East(v) => self.pos.0 += v,
                Step::West(v) => self.pos.0 -= v,
                Step::Left => self.heading = self.heading.left(),
                Step::Reverse => self.heading = self.heading.reverse(),
                Step::Right => self.heading = self.heading.right(),
                Step::Fwd(v) => self.pos = match self.heading {
                    Heading::East => (self.pos.0 + v, self.pos.1),
                    Heading::South => (self.pos.0, self.pos.1 - v),
                    Heading::West => (self.pos.0 - v, self.pos.1),
                    Heading::North => (self.pos.0, self.pos.1 + v),
                }
            }
        };
    }
pub fn apply ( & mut self , instr : & Step , use_wp : bool ) { if use_wp { match instr { Step :: North ( v ) => self . wp . 1 += v , Step :: South ( v ) => self . wp . 1 -= v , Step :: East ( v ) => self . wp . 0 += v , Step :: West ( v ) => self . wp . 0 -= v , Step :: Left => self . wp = ( - self . wp . 1 , self . wp . 0 ) , Step :: Reverse => self . wp = ( - self . wp . 0 , - self . wp . 1 ) , Step :: Right => self . wp = ( self . wp . 1 , - self . wp . 0 ) , Step :: Fwd ( v ) => self . pos = ( self . pos . 0 + v * self . wp . 0 , self . pos . 1 + v * self . wp . 1 ) , } ; } else { match instr { Step :: North ( v ) => self . pos . 1 += v , Step :: South ( v ) => self . pos . 1 -= v , Step :: East ( v ) => self . pos . 0 += v , Step :: West ( v ) => self . pos . 0 -= v , Step :: Left => self . heading = self . heading . left ( ) , Step :: Reverse => self . heading = self . heading . reverse ( ) , Step :: Right => self . heading = self . heading . right ( ) , Step :: Fwd ( v ) => self . pos = match self . heading { Heading :: East => ( self . pos . 0 + v , self . pos . 1 ) , Heading :: South => ( self . pos . 0 , self . pos . 1 - v ) , Heading :: West => ( self . pos . 0 - v , self . pos . 1 ) , Heading :: North => ( self . pos . 0 , self . pos . 1 + v ) , } } } ; }
tag::apply[]
apply a single step to the ship with or without waypoint (for part 1 and part 2
respectively)
tag :: apply [] apply a single step to the ship with or without waypoint ( for part 1 and part 2 respectively )
&mut self
instr
&Step
use_wp
bool
examples
None