SDoorItem.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SDoorItem = void 0;
  4. const lib_1 = require("@persagy-web/draw/lib");
  5. const SMathUtil_1 = require("../../utils/SMathUtil");
  6. const __1 = require("../..");
  7. const __2 = require("../..");
  8. const lib_2 = require("@persagy-web/graph/lib");
  9. class SDoorItem extends lib_2.SGraphItem {
  10. constructor(parent, data) {
  11. super(parent);
  12. this.pointArr = [];
  13. this.r = 0;
  14. this.ang = 0;
  15. this.p = new lib_1.SPoint(0, 0);
  16. this.startAng = -Math.PI / 2;
  17. this.minX = Number.MAX_SAFE_INTEGER;
  18. this.maxX = Number.MIN_SAFE_INTEGER;
  19. this.minY = Number.MAX_SAFE_INTEGER;
  20. this.maxY = Number.MIN_SAFE_INTEGER;
  21. this.data = data;
  22. this.zOrder = __1.ItemOrder.doorOrder;
  23. if (this.data.OutLine.length) {
  24. this.pointArr = this.data.OutLine[0].map((t) => {
  25. let x = t.X, y = -t.Y;
  26. if (x < this.minX) {
  27. this.minX = x;
  28. }
  29. if (y < this.minY) {
  30. this.minY = y;
  31. }
  32. if (x > this.maxX) {
  33. this.maxX = x;
  34. }
  35. if (y > this.maxY) {
  36. this.maxY = y;
  37. }
  38. return new lib_1.SPoint(t.X, -t.Y);
  39. });
  40. let p1 = this.pointArr[0], p2 = this.pointArr[1];
  41. this.p = p1;
  42. const HX = (this.data.HandDirection.X = Number(this.data.HandDirection.X.toFixed()));
  43. const HY = (this.data.HandDirection.Y = Number(this.data.HandDirection.Y.toFixed()));
  44. const FX = (this.data.FaceDirection.X = Number(this.data.FaceDirection.X.toFixed()));
  45. const FY = (this.data.FaceDirection.Y = Number(this.data.FaceDirection.Y.toFixed()));
  46. let dotProduct = (p2.x - p1.x) * HX + (p2.y - p1.y) * -HY;
  47. if (dotProduct > 0) {
  48. this.p = p2;
  49. p2 = p1;
  50. p1 = this.p;
  51. }
  52. this.r = SMathUtil_1.SMathUtil.pointDistance(p1.x, p1.y, p2.x, p2.y);
  53. let fo = Math.atan(-FY / FX);
  54. this.ang = FX > 0 ? fo : fo + Math.PI;
  55. let direction = (p2.x - p1.x) * -FY - (p2.y - p1.y) * FX;
  56. if (direction > 0) {
  57. this.startAng = 0;
  58. }
  59. }
  60. }
  61. boundingRect() {
  62. return new lib_1.SRect(this.minX, this.minY, this.maxX - this.minX, this.maxY - this.minY);
  63. }
  64. onDraw(painter) {
  65. painter.translate(this.p.x, this.p.y);
  66. painter.rotate(this.ang);
  67. painter.pen.lineWidth = 100;
  68. painter.pen.color = __2.ItemColor.doorColor;
  69. painter.drawLine(0, 0, this.r, 0);
  70. painter.pen.lineDash = [50, 100];
  71. painter.pen.lineWidth = painter.toPx(1);
  72. }
  73. }
  74. exports.SDoorItem = SDoorItem;