/**
* @author Wolfgang Kowarschick <kowa@hs-augsburg.de>
* @copyright 2017 - 2018
* @license CC-BY-NC-SA-4.0
*/
import {concretize} from '/wk/util/concretize';
/**
* @property {number} r - the radius of the circle
*
* @property {number} x - the x position of the circle
* @property {number} y - the y position of the circle
* @property {number} vx - the x velocity of the circle
* @property {number} vy - the y velocity of the circle
*
* @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 ModelCircle
{ /**
* @param {Object} [p_config]
* @param {number} [p_config.r = 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]
*/
constructor(p_config = {})
{ this.config = p_config;
this.reset();
}
reset()
{ const {r=0, x=0, y=0, vx=0, vy=0} = concretize({config: this.config});
this.r = r;
this.x = x; this.y = y;
this.vx = vx; this.vy = vy;
}
get left() { return this.x - this.r; }
get right() { return this.x + this.r; }
get top() { return this.y - this.r; }
get bottom() { return this.y + this.r; }
set left(p_x) { this.x = p_x + this.r; }
set right(p_x) { this.x = p_x - this.r; }
set top(p_y) { this.y = p_y + this.r; }
set bottom(p_y) { this.y = p_y - this.r; }
/**
* Moves the circle to a specific point. By default it's moved
* to the point stated in the config object that has been passed
* to the constructor.
* @param {Object} [p_config]
* @param {number} p_config.x
* @param {number} p_config.y
*/
moveTo({x=0, y=0} = concretize({config: this.config}))
{ this.x = x; this.y = y; }
/** Starts the circle moving around. */
start()
{ const {vx=0, vy=0} = concretize({config: this.config});
this.vx = vx; this.vy = vy;
}
/** Stops the circle moving around. */
stop()
{ this.vx = 0; this.vy = 0; }
/**
* @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;
}
}
export {ModelCircle};