Home Reference Source Repository

src/app/components/point-component/models/point-model.js

/*
 * iGeom by LInE
 * Geometric Object: Point
 * Model to Point
 * www.matematica.br/igeom
 * ./app/components/point-component/models/point-model.js
 * @version 2020/11/02: Implemented Line instersection
 */

import { GeometricObject } from "../../../core/models/objects/geometric-object";
import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";

export class PointModel extends GeometricObject {

  // @param {number  } posX X Position ex: (38.5) float precision
  // @param {number  } posY Y Position  ex: (-38.5) float precision
  // @param {string  } label  Label ex: (P)
  constructor(posX, posY, label, id) {
    super(id);
    this.posX = posX;
    this.posY = posY;
    this.setLabel(label);
    super.setClass(ELEMENTS_CLASS.POINT);
    this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
    this.color = -16711936;
  }

  // @param {konvaObject  } Object of Konva Library
  // @param {*  } event 
  update(konvaObject, event) {
    this.posX = konvaObject.attrs.startPosX + event.target._lastPos.x;
    this.posY = konvaObject.attrs.startPosY + event.target._lastPos.y;
    this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
  }

  bind(posX, posY, label) {
    this.posX = posX;
    this.posY = posY;
    this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
    if (label != undefined)
      this.setLabel(label);
  }

  // Create new Intersection By Line of Script .geo
  // @param {Map  } map JavaScript Map
  // @param {List  } list List of Generic Objects
  static do(map, list) {
    const id = map.get("id");
    const x = map.get("param")[0] - 5;
    const y = -map.get("param")[1] + 5;
    const label = map.get("label")[0];
    return new PointModel(x, y, label, id);
  }

}