Point.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Point = /** @class */ (function () {
  4. function Point(x, y) {
  5. this._x = x;
  6. this._y = y;
  7. }
  8. Object.defineProperty(Point.prototype, "x", {
  9. get: function () { return this._x; },
  10. enumerable: true,
  11. configurable: true
  12. });
  13. Object.defineProperty(Point.prototype, "y", {
  14. get: function () { return this._y; },
  15. enumerable: true,
  16. configurable: true
  17. });
  18. Point.prototype.add = function (pt) {
  19. return new Point(this.x + pt.x, this.y + pt.y);
  20. };
  21. Point.prototype.sub = function (pt) {
  22. return new Point(this.x - pt.x, this.y - pt.y);
  23. };
  24. Point.prototype.mul = function (pt) {
  25. return new Point(this.x * pt.x, this.y * pt.y);
  26. };
  27. Point.prototype.div = function (pt) {
  28. return new Point(this.x / pt.x, this.y / pt.y);
  29. };
  30. Point.prototype.abs = function () {
  31. return new Point(Math.abs(this.x), Math.abs(this.y));
  32. };
  33. Point.prototype.magnitude = function () {
  34. return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
  35. };
  36. Point.prototype.floor = function () {
  37. return new Point(Math.floor(this.x), Math.floor(this.y));
  38. };
  39. return Point;
  40. }());
  41. exports.Point = Point;
  42. //# sourceMappingURL=Point.js.map