Geometry.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { dataService } from "../Service/DataService";
  2. import { mathUtil } from "../Util/MathUtil";
  3. export default class Geometry {
  4. constructor() {
  5. this.display = true;
  6. }
  7. setId(vectorId) {
  8. if (vectorId == null || typeof vectorId === "undefined") {
  9. vectorId = dataService.getCurrentId();
  10. dataService.updateCurrentId();
  11. this.vectorId = this.geoType + vectorId;
  12. } else {
  13. this.vectorId = vectorId;
  14. }
  15. }
  16. getIndex() {
  17. return this.index;
  18. }
  19. setIndex(index) {
  20. this.index = index;
  21. }
  22. getPoints() {
  23. return this.points;
  24. }
  25. setPoints(points) {
  26. this.points = JSON.parse(JSON.stringify(points));
  27. }
  28. setPointParent(parentId, dir) {
  29. if (this.parent == null) {
  30. this.parent = {};
  31. }
  32. this.parent[parentId] = dir;
  33. }
  34. setEdgeParent(parentId) {
  35. if (this.parent == null) {
  36. this.parent = {};
  37. }
  38. this.parent = parentId;
  39. }
  40. setLeftEdge(edgeId) {
  41. this.leftEdgeId = edgeId;
  42. }
  43. setRightEdge(edgeId) {
  44. this.rightEdgeId = edgeId;
  45. }
  46. setDisplay(value) {
  47. this.display = value;
  48. }
  49. setParent(value) {
  50. this.parent = value;
  51. }
  52. getParent() {
  53. return this.parent;
  54. }
  55. setValue(value) {
  56. this.value = value;
  57. }
  58. getValue() {
  59. return this.value;
  60. }
  61. getCenter() {
  62. return this.center;
  63. }
  64. setCenter(center) {
  65. if (center) {
  66. this.center = {};
  67. this.center.x = center.x;
  68. this.center.y = center.y;
  69. }
  70. }
  71. setColor(value) {
  72. this.color = value;
  73. }
  74. getColor() {
  75. return this.color;
  76. }
  77. getStyle() {
  78. return this.style;
  79. }
  80. setStyle(style) {
  81. this.style = style;
  82. }
  83. getStyle() {
  84. return this.weight;
  85. }
  86. setWeight(weight) {
  87. this.weight = weight;
  88. }
  89. getType() {
  90. return this.type;
  91. }
  92. setType(type) {
  93. this.type = type;
  94. }
  95. getCategory() {
  96. return this.category;
  97. }
  98. setLocationMode(value) {
  99. this.locationMode = value;
  100. }
  101. setLinkedBasePointId(id){
  102. this.linkedBasePointId = id;
  103. }
  104. setLinkedTestPointId(id){
  105. this.linkedTestPointId = id;
  106. }
  107. getLocationMode() {
  108. return this.locationMode;
  109. }
  110. // ptSrc: 圆上某点(初始点);
  111. // ptRotationCenter: 圆心点;
  112. // angle: 旋转角度° -- [angle * M_PI / 180]:将角度换算为弧度
  113. // 【注意】angle 逆时针为正,顺时针为负
  114. rotatePoint(ptSrc, ptRotationCenter, angle) {
  115. angle = -1 * angle; //设计是逆时针为负,顺时针为正
  116. var a = ptRotationCenter.x;
  117. var b = ptRotationCenter.y;
  118. var x0 = ptSrc.x;
  119. var y0 = ptSrc.y;
  120. var rx =
  121. a +
  122. (x0 - a) * Math.cos((angle * Math.PI) / 180) -
  123. (y0 - b) * Math.sin((angle * Math.PI) / 180);
  124. var ry =
  125. b +
  126. (x0 - a) * Math.sin((angle * Math.PI) / 180) +
  127. (y0 - b) * Math.cos((angle * Math.PI) / 180);
  128. var json = { x: rx, y: ry };
  129. return json;
  130. }
  131. }