1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import Constant from "../Constant";
- import { dataService } from "../Service/DataService";
- import { mathUtil } from "../Util/MathUtil";
- export default class MoveSVG {
- constructor() {}
- moveFullSVG(position, svgId) {
- let svg = dataService.getSVG(svgId);
- let dx = position.x - svg.center.x;
- let dy = position.y - svg.center.y;
- mathUtil.clonePoint(svg.center, position);
- //svg.setBoundingVertexs();
- svg.points[0].x += dx;
- svg.points[0].y += dy;
- svg.points[1].x += dx;
- svg.points[1].y += dy;
- svg.points[2].x += dx;
- svg.points[2].y += dy;
- svg.points[3].x += dx;
- svg.points[3].y += dy;
- }
- // movePoint(position, svgId, pointIndex) {
- // let svg = dataService.getSVG(svgId);
- // const rec = svg.getLengthWidth();
- // const scale = svg.getScale();
- // const side1 = Math.sqrt(
- // Math.pow((rec.width / 2) * scale, 2) +
- // Math.pow((rec.length / 2) * scale, 2)
- // );
- // svg.setBoundingVertexs2(position, pointIndex);
- // const side2 = mathUtil.getDistance(position, svg.center);
- // svg.scale = (side2 / side1) * scale;
- // }
- movePoint(newPos, svgId, pointIndex) {
- let svg = dataService.getSVG(svgId);
- const preIndex = svg.getPreIndex(pointIndex);
- const nextIndex = svg.getNextIndex(pointIndex);
- const nextIndex2 = svg.getNextIndex(nextIndex);
- const angle = mathUtil.Angle(
- svg.points[nextIndex],
- svg.points[pointIndex],
- newPos
- );
- const line1 = mathUtil.createLine1(
- svg.points[nextIndex2],
- svg.points[nextIndex]
- );
- const nextPoint = mathUtil.getJoinLinePoint(newPos, line1);
- const line2 = mathUtil.createLine1(
- svg.points[nextIndex2],
- svg.points[preIndex]
- );
- const prePoint = mathUtil.getJoinLinePoint(newPos, line2);
- if (
- nextPoint != null &&
- prePoint != null &&
- mathUtil.getDistance(newPos, nextPoint) > Constant.minAdsorbPix &&
- mathUtil.getDistance(newPos, prePoint) > Constant.minAdsorbPix &&
- mathUtil.getDistance(newPos, svg.points[nextIndex2]) >
- Constant.minAdsorbPix
- ) {
- svg.points[pointIndex] = newPos;
- if (!mathUtil.isClockwise(svg.points)) {
- svg.points[nextIndex] = nextPoint;
- svg.points[preIndex] = prePoint;
- } else {
- svg.points[nextIndex] = prePoint;
- svg.points[preIndex] = nextPoint;
- svg.resetPointsIndex();
- --pointIndex;
- if (pointIndex < 0) {
- pointIndex += 4;
- }
- return pointIndex;
- }
- }
- return pointIndex;
- }
- }
- const moveSVG = new MoveSVG();
- export { moveSVG };
|