Source: model/ModelRectangle.js

/**
 * @author    Wolfgang Kowarschick <kowa@hs-augsburg.de>
 * @copyright 2017 - 2018
 * @license   CC-BY-NC-SA-4.0
 */

/**
 * @property {number} width  - the width of the rectangle
 * @property {number} height - the height of the rectangle
 *
 * @property {number} x      - the x position of the rectangle
 * @property {number} y      - the y position of the rectangle
 * @property {number} vx     - the x velocity of the rectangle
 * @property {number} vy     - the y velocity of the rectangle
 * @property {number} ax     - the x acceleration of the rectangle
 * @property {number} ay     - the y acceleration of the rectangle
 *
 * @property {number} left   - the x position of the left border (AABB)
 * @property {number} right  - the x position of the right border (AABB)
 * @property {number} top    - the y position of the top border (AABB)
 * @property {number} bottom - the y position of the bottom border (AABB)
 */
class ModelRectangle
{ /**
   * @param {Object} [p_config]
   * @param {number} [p_config.width  = 0]
   * @param {number} [p_config.height = 0]
   * @param {number} [p_config.x = 0]
   * @param {number} [p_config.y = 0]
   * @param {number} [p_config.vx = 0]
   * @param {number} [p_config.vy = 0]
   * @param {number} [p_config.ax = 0]
   * @param {number} [p_config.ay = 0]
   */
   constructor(p_config = {})
   { this.config = p_config;
     this.reset();
   }
  
  reset()
  { const {width=0, height=0, x=0, y=0, vx=0, vy=0, ax=0, ay=0} = this.config;
    this.width = width; this.height = height;
    this.x     = x;     this.y      = y;
    this.vx    = vx;    this.vy     = vy;
    this.ax    = ax;    this.ay     = ay;
  }
  
  get left()   { return this.x; }
  get right()  { return this.x + this.width; }
  get top()    { return this.y; }
  get bottom() { return this.y + this.height; }
  
  set left(p_x)   { this.x = p_x; }
  set right(p_x)  { this.x = p_x - this.width; }
  set top(p_y)    { this.y = p_y; }
  set bottom(p_y) { this.y = p_y - this.height; }
  
  /**
   * @param {number} p_delta_s - time in seconds since last call (max 1/60)
   */
  update(p_delta_s)
  { this.x  += this.vx * p_delta_s;
    this.y  += this.vy * p_delta_s;
  
    this.vx += this.ax * p_delta_s;
    this.vy += this.ay * p_delta_s;
  }
}

export {ModelRectangle};