Geometry.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { dataService } from "../Service/DataService";
  2. // import { mathUtil } from "../Util/MathUtil.js/index.js";
  3. import SymbolEvents from "../enum/SymbolEvents.js";
  4. export default class Geometry {
  5. constructor() {
  6. this.len = null;
  7. }
  8. setId(vectorId) {
  9. if (vectorId == null || typeof vectorId === "undefined") {
  10. vectorId = dataService.getCurrentId();
  11. dataService.updateCurrentId();
  12. this.vectorId = this.geoType + vectorId;
  13. } else {
  14. this.vectorId = vectorId;
  15. }
  16. }
  17. setPointParent(parentId, dir) {
  18. if (this.parent == null) {
  19. this.parent = {};
  20. }
  21. this.parent[parentId] = dir;
  22. }
  23. setLeftEdge(edgeId) {
  24. this.leftEdgeId = edgeId;
  25. }
  26. setRightEdge(edgeId) {
  27. this.rightEdgeId = edgeId;
  28. }
  29. getParent() {
  30. return this.parent;
  31. }
  32. // ptSrc: 圆上某点(初始点);
  33. // ptRotationCenter: 圆心点;
  34. // angle: 旋转角度° -- [angle * M_PI / 180]:将角度换算为弧度
  35. // 【注意】angle 逆时针为正,顺时针为负
  36. rotatePoint(ptSrc, ptRotationCenter, angle) {
  37. angle = -1 * angle; //设计是逆时针为负,顺时针为正
  38. var a = ptRotationCenter.x;
  39. var b = ptRotationCenter.y;
  40. var x0 = ptSrc.x;
  41. var y0 = ptSrc.y;
  42. var rx =
  43. a +
  44. (x0 - a) * Math.cos((angle * Math.PI) / 180) -
  45. (y0 - b) * Math.sin((angle * Math.PI) / 180);
  46. var ry =
  47. b +
  48. (x0 - a) * Math.sin((angle * Math.PI) / 180) +
  49. (y0 - b) * Math.cos((angle * Math.PI) / 180);
  50. var json = { x: rx, y: ry };
  51. return json;
  52. }
  53. }