Source: base/2d/DrawRectObject.js

  1. import { DRAW_TYPE } from "../../constants.js";
  2. import { DrawShapeObject } from "./DrawShapeObject.js";
  3. /**
  4. * @extends DrawShapeObject
  5. * @see {@link DrawObjectFactory} should be created with factory method
  6. */
  7. export class DrawRectObject extends DrawShapeObject {
  8. /**
  9. * @type {number}
  10. */
  11. #w;
  12. /**
  13. * @type {number}
  14. */
  15. #h;
  16. /**
  17. * @type {Array<Array<number>>}
  18. */
  19. #vertices;
  20. /**
  21. * @hideconstructor
  22. */
  23. constructor(x, y, w, h, bgColor) {
  24. super(DRAW_TYPE.RECTANGLE, x, y, bgColor);
  25. this.#w = w;
  26. this.#h = h;
  27. this.#vertices = this._calculateRectVertices(w,h);
  28. }
  29. /**
  30. * @type {Array<Array<number>>}
  31. */
  32. get vertices () {
  33. return this.#vertices;
  34. }
  35. /**
  36. * @type {number}
  37. */
  38. get width() {
  39. return this.#w;
  40. }
  41. /**
  42. * @type {number}
  43. */
  44. get height() {
  45. return this.#h;
  46. }
  47. set width(w) {
  48. this.#w = w;
  49. }
  50. set height(h) {
  51. this.#h = h;
  52. }
  53. }