SVGService.js 907 B

12345678910111213141516171819202122232425262728293031
  1. import SVG from "../Geometry/SVG.js";
  2. import { dataService } from "./DataService.js";
  3. import { mathUtil } from "../Util/MathUtil.js";
  4. import { uiService } from "./UIService.js";
  5. export default class SVGService {
  6. constructor() {}
  7. create(position, type, svgId) {
  8. let svg = new SVG(position, type, svgId);
  9. dataService.addSVG(svg);
  10. return svg;
  11. }
  12. copy(vectorId) {
  13. let SVG = dataService.getSVG(vectorId);
  14. let newCenter = uiService.getNewPositionForPop(SVG.center);
  15. let newSVG = this.create(newCenter, SVG.type);
  16. newSVG.setScale(SVG.scale);
  17. for (let i = 0; i < SVG.points.length; ++i) {
  18. let dx = SVG.points[i].x - SVG.center.x;
  19. let dy = SVG.points[i].y - SVG.center.y;
  20. newSVG.points[i].x = newSVG.center.x + dx;
  21. newSVG.points[i].y = newSVG.center.y + dy;
  22. }
  23. return newSVG;
  24. }
  25. }
  26. const svgService = new SVGService();
  27. export { svgService };