You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Rect.js 711B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import Vec2 from './Vec2';
  2. export default class Rect {
  3. constructor(pos = new Vec2(), size = new Vec2()) {
  4. this.pos = pos;
  5. this.size = size;
  6. }
  7. draw(ctx) {
  8. ctx.moveTo(this.left, this.top);
  9. ctx.lineTo(this.right, this.top);
  10. ctx.lineTo(this.right, this.bottom);
  11. ctx.lineTo(this.left, this.bottom);
  12. ctx.closePath();
  13. ctx.stroke();
  14. }
  15. get top() {
  16. return this.pos.y;
  17. }
  18. set top(n) {
  19. this.pos.y = n;
  20. }
  21. get bottom() {
  22. return this.pos.y + this.size.y;
  23. }
  24. set bottom(n) {
  25. this.pos.y = n - this.size.y;
  26. }
  27. get left() {
  28. return this.pos.x;
  29. }
  30. set left(n) {
  31. this.pos.x = n;
  32. }
  33. get right() {
  34. return this.pos.x + this.size.x;
  35. }
  36. set right(n) {
  37. this.pos.x = n - this.size.x;
  38. }
  39. }