Point.js 1.2 KB

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