UNPKG

algomin

Version:

Algomin - Viszualizing Distributed Algorithms

69 lines (58 loc) 1.63 kB
import {BaseModel} from "./BaseModel"; export class Shape extends BaseModel{ /** * Static list of all existing Shapes * @type {[]} */ static shapes = []; /** * Initially the death_time is set to the max integer since the kill command * has not yet been passed. Then adds itself to the static list of all Shapes. * * @param id Variable name * @param x x Position in percent * @param y y Position in percent * @param w Width * @param h Height * @param label Label * @param creation_time Creation Time */ constructor(id, x, y, w, h, label, creation_time) { super(id, x, y, w, h, label, creation_time, Number.MAX_SAFE_INTEGER, "shape"); this._percentage_x = x; this._percentage_y = y; this._percentage_w = w; this._percentage_h = h; Shape.shapes.push(this); } get percentageX(){ return this._percentage_x; } get percentageY(){ return this._percentage_y; } get percentageW(){ return this._percentage_w; } get percentageH(){ return this._percentage_h; } /** * Finds a Shape object by given id and returns it * @param id * @returns {*} */ static get(id){ for(let i = 0; i < Shape.shapes.length; i++){ if(Shape.shapes[i].id === id){ return Shape.shapes[i]; } } } /** * Clears all Shapes */ static clearShapes(){ Shape.shapes = []; } }