UNPKG

algomin

Version:

Algomin - Viszualizing Distributed Algorithms

118 lines (96 loc) 2.28 kB
import {Model} from "../Model"; /** * Abstract class */ export class BaseModel { /** * BaseModel constructor * @param id Identifier * @param x x Position * @param y y Position * @param w Width * @param h Height * @param label Label * @param creation_time Creation Time * @param death_time Death Time * @param type Type of the object */ constructor(id, x, y, w, h, label, creation_time, death_time, type) { this._id = id; this._x = x; this._y = y; this._w = w; this._h = h; this._creation_time = creation_time; this._death_time = death_time; this._label = label; this._type = type; } /** * Check if object is visible in the animation by checking if * the current runtime is within the objects' creation- and death time * @returns {boolean} */ isVisible() { return (this.creationTime < Model.time && Model.time < this.deathTime); } /** * Returns the x coordinate of the center horizontal of the object * @returns Integer */ get middleX() { return this._x + (this._w / 2); } /** * Returns the y coordinate of the center vertical of the object * @returns Integer */ get middleY() { return this._y + (this._h / 2); } get creationTime() { return this._creation_time; } get deathTime() { return this._death_time; } set deathTime(value) { this._death_time = value; } get id() { return this._id; } get x() { return this._x; } set x(value) { this._x = value; } get y() { return this._y; } set y(value) { this._y = value; } get w() { return this._w; } set w(value) { this._w = value; } get h() { return this._h; } set h(value) { this._h = value; } get label() { return this._label; } set label(value) { this._label = value; } get type(){ return this._type; } }