move in the tree in given direction and return the last position.

        :param starting_pos: position to start at
        :param direction: callable that transforms a position into a position.
486528
def _last_in_direction(starting_pos, direction):
        
        cur_pos = None
        next_pos = starting_pos
        while next_pos is not None:
            cur_pos = next_pos
            next_pos = direction(cur_pos)
        return cur_pos
922246
function calcDirection(start, end) {
  var direction = new Vec2(end);
  direction.subtract(start);
  direction.normalize();
  return direction;
}
771430
function Position(start) {
    this.start = start;
    this.end = { line: lineno, column: column };
    this.source = options.source;
  }
401325
def add_one_en_passant_move(self, direction, position):
        
        try:
            if self._is_en_passant_valid(direction(self.location), position):
                yield self.create_move(
                    end_loc=self.square_in_front(direction(self.location)),
                    status=notation_const.EN_PASSANT
                )
        except IndexError:
            pass
1129012
def push_pos(self, *args):
        
        self.proxy['_x'] = self.x / self.board.width
        self.proxy['_y'] = self.y / self.board.height
358306
async def seek(self, position: int):
        
        if self.current.seekable:
            position = max(min(position, self.current.length), 0)
            await self.node.seek(self.channel.guild.id, position)
238214
def seek(self, pos=0):
        
        if pos - self.pos >= 0:
            blocks, remainder = divmod(pos - self.pos, self.bufsize)
            for i in range(blocks):
                self.read(self.bufsize)
            self.read(remainder)
        else:
            raise StreamError("seeking backwards is not allowed")
        return self.pos
927737
def enter_position(self):
        ''''''
        state = self.state
        dlg = wx.TextEntryDialog(self, 'Enter new position', 'Position')
        dlg.SetValue("%f %f" % (state.lat, state.lon))
        if dlg.ShowModal() == wx.ID_OK:
            latlon = dlg.GetValue().split()
            dlg.Destroy()
            state.lat = float(latlon[0])
            state.lon = float(latlon[1])
            self.re_center(state.width/2,state.height/2, state.lat, state.lon)
            self.redraw_map()
786346
def set_pos(self, pos):
        
        self.pos = pos
        if pos is not None and self.typ is not None:
            self.typ._v_pos = pos
        return self
992930
def _get_pos(self):
        
        if self._canvas.height >= self._max_height:
            return 0
        else:
            return self._canvas.start_line / (self._max_height - self._canvas.height + 1)
1199390
private void moveTo(int position) {
    while (position >= currentPosition) {
      try {
        currentPosition = ignoreSpans.nextStartPosition();
        if (currentPosition != Spans.NO_MORE_POSITIONS
            && currentPosition >= minimumPosition) {
          if (!baseEndPositionList.containsKey(currentPosition)) {
            baseEndPositionList.put(currentPosition, new HashSet<Integer>());
            maxBaseEndPosition.put(currentPosition, currentPosition);
          } else {
            maxBaseEndPosition.put(currentPosition,
                Math.max(maxBaseEndPosition.get(currentPosition),
                    ignoreSpans.endPosition()));
          }
          if (!baseStartPositionList.containsKey(ignoreSpans.endPosition())) {
            baseStartPositionList.put(ignoreSpans.endPosition(),
                new HashSet<Integer>());
            minBaseStartPosition.put(ignoreSpans.endPosition(),
                ignoreSpans.endPosition());
          } else {
            minBaseStartPosition.put(ignoreSpans.endPosition(),
                Math.min(minBaseStartPosition.get(ignoreSpans.endPosition()),
                    currentPosition));
          }
          baseStartPositionList.get(ignoreSpans.endPosition())
              .add(currentPosition);
          baseEndPositionList.get(currentPosition)
              .add(ignoreSpans.endPosition());
        }
      } catch (IOException e) {
        log.debug(e);
        currentPosition = Spans.NO_MORE_POSITIONS;
        break;
      }
    }
  }
1203798
def _move_to_top(self, pos):
        """"""
        if pos > 0:
            self.queue.rotate(-pos)
            item = self.queue.popleft()
            self.queue.rotate(pos)
            self.queue.appendleft(item)
472088
def pos(self):
        """"""
        for i, task in enumerate(self.work):
            if self == task:
                return self.work.pos, i
        raise ValueError("Cannot find the position of %s in flow %s" % (self, self.flow))
952973
def possible_moves(self, position):
        
        # Chain used to combine multiple generators
        for move in itertools.chain(*[self.add(fn, position) for fn in self.cardinal_directions]):
            yield move

        for move in self.add_castle(position):
            yield move
786598
def move(self, target, pos=None):
        '''
        
        '''
        if self.outline != target.outline:
            raise IntegrityError('Elements must be from the same outline!')
        tree_manipulation.send(
            sender=self.__class__,
            instance=self,
            action='move',
            target_node_type=None,
            target_node=target,
            pos=pos
        )
        return super().move(target, pos)
951822
def prev_position(self, pos):
        """"""
        candidate = None
        if pos is not None:
            prevsib = self.prev_sibling_position(pos)  # is None if first
            if prevsib is not None:
                candidate = self.last_decendant(prevsib)
            else:
                parent = self.parent_position(pos)
                if parent is not None:
                    candidate = parent
        return candidate
1247844
def begin_pos
      node_begin_pos = @node.loc.expression.begin_pos
      while @node.loc.expression.source_buffer.source[node_begin_pos -= 1] == ' '
      end
      node_begin_pos - Engine::ERUBY_STMT_SPLITTER.length + 1
    end