<commit_before>const {normalize, between, scale, add} = require('../vector')

module.exports = {step}

/**
 * @typedef Entity
 * @type {Object}
 * @property {Vector} position
 * @property {Vector} velocity
 * @property {number} thrust
 * @property {number} mass
 */

/**
 * @typedef Vector
 * @type {Object}
 * @property {number} x
 * @property {number} y
 */

/**
 * @returns {Entity} entity with position and velocity forwarded in time by one turn
 * @param {Entity} entity entity for which to simulate the movement
 * @param {Entity} target entity that the entity is moving towards
 */
function step (entity, target) {
  const velocityDelta = scale(scale(normalize(between(entity, target)), entity.thrust), 1 / entity.mass)
  const movementVelocity = add(entity.velocity, velocityDelta)
  const newPosition = add(entity.position, movementVelocity)
  const newVelocity = scale(movementVelocity, entity.friction)
  return Object.assign({}, entity, {position: newPosition, velocity: newVelocity})
}<commit_msg>feat(fantastic-bits): low level movement functions<commit_after>const {normalize, between, scale, add} = require('../vector')

module.exports = {
  step,
  nextVelocity,
  nextPosition,
  nextMoveVelocity,
  nextMove
}

/**
 * @typedef Entity
 * @type {Object}
 * @property {Vector} position
 * @property {Vector} velocity
 * @property {number} thrust
 * @property {number} mass
 */

/**
 * @typedef Vector
 * @type {Object}
 * @property {number} x
 * @property {number} y
 */

/**
 * @returns {Entity} entity with position and velocity forwarded in time by one turn
 * @param {Entity} entity entity for which to simulate the movement
 * @param {Entity} target entity that the entity is moving towards
 */
function step (entity, target) {
  return Object.assign({}, entity, {
    position: nextPosition(entity, target),
    velocity: nextVelocity(entity, target)
  })
}

/**
 * @returns {Vector}
 * @param {Entity} entity entity for which to simulate the movement
 * @param {Entity} target entity that the entity is moving towards
 */
function nextVelocity (entity, target) {
  return scale(nextMoveVelocity(entity, target), entity.friction)
}

/**
 * @returns {Vector}
 * @param {Entity} entity entity for which to simulate the movement
 * @param {Entity} target entity that the entity is moving towards
 */
function nextPosition (entity, target) {
  return add(entity.position, nextMoveVelocity(entity, target))
}

/**
 * @returns {Vector}
 * @param {Entity} entity entity for which to simulate the movement
 * @param {Entity} target entity that the entity is moving towards
 */
function nextMoveVelocity (entity, target) {
  return add(entity.velocity, nextMove(entity, target))
}

/**
 * @returns {Vector}
 * @param {Entity} entity entity for which to simulate the movement
 * @param {Entity} target entity that the entity is moving towards
 */
function nextMove (entity, target) {
  return scale(scale(normalize(between(entity, target)), entity.thrust), 1 / entity.mass)
}
{'fraction_non_alphanumeric': 0.12286575159022431, 'fraction_numerical': 0.0006695681285570807, 'mean_word_length': 4.606003752345216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3476962', 'n_tokens_mistral': 857, 'n_tokens_neox': 834, 'n_words': 307}