SLine.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SLine = void 0;
  4. var SPoint_1 = require("./SPoint");
  5. var SLine = (function () {
  6. function SLine(x1, y1, x2, y2) {
  7. if (x1 == undefined) {
  8. this.p1 = new SPoint_1.SPoint(0, 0);
  9. this.p2 = new SPoint_1.SPoint(0, 0);
  10. }
  11. else if (x1 instanceof SLine) {
  12. this.p1 = new SPoint_1.SPoint(x1.p1.x, x1.p1.y);
  13. this.p2 = new SPoint_1.SPoint(x1.p2.x, x1.p2.y);
  14. }
  15. else if (x1 instanceof SPoint_1.SPoint && y1 instanceof SPoint_1.SPoint) {
  16. this.p1 = new SPoint_1.SPoint(x1.x, x1.y);
  17. this.p2 = new SPoint_1.SPoint(y1.x, y1.y);
  18. }
  19. else {
  20. this.p1 = new SPoint_1.SPoint(x1, y1);
  21. this.p2 = new SPoint_1.SPoint(x2, y2);
  22. }
  23. }
  24. Object.defineProperty(SLine.prototype, "x1", {
  25. get: function () {
  26. return this.p1.x;
  27. },
  28. set: function (value) {
  29. this.p1.x = value;
  30. },
  31. enumerable: false,
  32. configurable: true
  33. });
  34. Object.defineProperty(SLine.prototype, "y1", {
  35. get: function () {
  36. return this.p1.y;
  37. },
  38. set: function (value) {
  39. this.p1.y = value;
  40. },
  41. enumerable: false,
  42. configurable: true
  43. });
  44. Object.defineProperty(SLine.prototype, "x2", {
  45. get: function () {
  46. return this.p2.x;
  47. },
  48. set: function (v) {
  49. this.p2.x = v;
  50. },
  51. enumerable: false,
  52. configurable: true
  53. });
  54. Object.defineProperty(SLine.prototype, "y2", {
  55. get: function () {
  56. return this.p2.y;
  57. },
  58. set: function (value) {
  59. this.p2.y = value;
  60. },
  61. enumerable: false,
  62. configurable: true
  63. });
  64. Object.defineProperty(SLine.prototype, "dx", {
  65. get: function () {
  66. return this.p2.x - this.p1.x;
  67. },
  68. enumerable: false,
  69. configurable: true
  70. });
  71. Object.defineProperty(SLine.prototype, "dy", {
  72. get: function () {
  73. return this.p2.y - this.p1.y;
  74. },
  75. enumerable: false,
  76. configurable: true
  77. });
  78. SLine.prototype.isNull = function () {
  79. return (Math.abs(this.p1.x - this.p2.x) + Math.abs(this.p1.y - this.p2.y) <
  80. 0.000001);
  81. };
  82. SLine.prototype.center = function () {
  83. return new SPoint_1.SPoint((this.p1.x + this.p2.x) / 2, (this.p1.y + this.p2.y) / 2);
  84. };
  85. SLine.prototype.translate = function (dx, dy) {
  86. this.p1.x += dx;
  87. this.p2.x += dx;
  88. this.p1.y += dy;
  89. this.p2.y += dy;
  90. };
  91. SLine.prototype.translated = function (dx, dy) {
  92. return new SLine(this.p1.x + dx, this.p1.y + dy, this.p2.x + dx, this.p2.y + dy);
  93. };
  94. return SLine;
  95. }());
  96. exports.SLine = SLine;