Geometry.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. setCenter(center) {
  62. if (center) {
  63. this.center = {};
  64. this.center.x = center.x;
  65. this.center.y = center.y;
  66. }
  67. }
  68. setRadius(radius) {
  69. this.radius = radius;
  70. }
  71. setColor(value) {
  72. this.color = value;
  73. }
  74. getColor() {
  75. return this.color;
  76. }
  77. // ptSrc: 圆上某点(初始点);
  78. // ptRotationCenter: 圆心点;
  79. // angle: 旋转角度° -- [angle * M_PI / 180]:将角度换算为弧度
  80. // 【注意】angle 逆时针为正,顺时针为负
  81. rotatePoint(ptSrc, ptRotationCenter, angle) {
  82. angle = -1 * angle; //设计是逆时针为负,顺时针为正
  83. var a = ptRotationCenter.x;
  84. var b = ptRotationCenter.y;
  85. var x0 = ptSrc.x;
  86. var y0 = ptSrc.y;
  87. var rx =
  88. a +
  89. (x0 - a) * Math.cos((angle * Math.PI) / 180) -
  90. (y0 - b) * Math.sin((angle * Math.PI) / 180);
  91. var ry =
  92. b +
  93. (x0 - a) * Math.sin((angle * Math.PI) / 180) +
  94. (y0 - b) * Math.cos((angle * Math.PI) / 180);
  95. var json = { x: rx, y: ry };
  96. return json;
  97. }
  98. }