Skip to content

Commit

Permalink
improve delete functionality fot text, rect, distance, area, angle tools
Browse files Browse the repository at this point in the history
  • Loading branch information
VikaAbysova committed Oct 23, 2023
1 parent e30e250 commit b9b398a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/engine/tools2d/ToolAngle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// **********************************************

// import Modes2d from '../../store/Modes2d';
import PointerChecker from '../utils/PointerChecker';
import ToolDistance from './ToolDistance';

// **********************************************
Expand Down Expand Up @@ -78,20 +79,36 @@ class ToolAngle {
const vScr0 = ToolDistance.textureToScreen(objAngle.points[0].x, objAngle.points[0].y, this.m_wScreen, this.m_hScreen, store);
const vScr1 = ToolDistance.textureToScreen(objAngle.points[1].x, objAngle.points[1].y, this.m_wScreen, this.m_hScreen, store);
const vScr2 = ToolDistance.textureToScreen(objAngle.points[2].x, objAngle.points[2].y, this.m_wScreen, this.m_hScreen, store);
const MIN_DIST = 4.0;
if (this.getDistMm(vScr, vScr0) <= MIN_DIST) {
this.m_objEdit = objAngle;
return objAngle.points[0];
}
if (this.getDistMm(vScr, vScr1) <= MIN_DIST) {

const vScrLine1_S = vScr0;
const vScrLine1_E = vScr1;
const vScrLine2_S = vScr0;
const vScrLine2_E = vScr2;

if (PointerChecker.isPointerOnLine(vScrLine1_S, vScrLine1_E, vScr)) {
this.m_objEdit = objAngle;
return objAngle.points[1];
return objAngle.points;
}
if (this.getDistMm(vScr, vScr2) <= MIN_DIST) {
if (PointerChecker.isPointerOnLine(vScrLine2_S, vScrLine2_E, vScr)) {
this.m_objEdit = objAngle;
return objAngle.points[2];
return objAngle.points;
}
}

// const MIN_DIST = 4.0;
// if (this.getDistMm(vScr, vScr0) <= MIN_DIST) {
// this.m_objEdit = objAngle;
// return objAngle.points[0];
// }
// if (this.getDistMm(vScr, vScr1) <= MIN_DIST) {
// this.m_objEdit = objAngle;
// return objAngle.points[1];
// }
// if (this.getDistMm(vScr, vScr2) <= MIN_DIST) {
// this.m_objEdit = objAngle;
// return objAngle.points[2];
// }

return null;
}

Expand Down
48 changes: 48 additions & 0 deletions src/engine/utils/PointerChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2021 EPAM Systems, Inc. (https://www.epam.com/)
* SPDX-License-Identifier: Apache-2.0
*/
/**
* This is a tool for checking whether a pointer is on the line
* @module demo/engine/utils/tool
*/
// absolute imports
/**
* Class PointerChecker to check if the point is on the line
* @class PointerChecker
*/
class PointerChecker {
static isPointerOnLine(vs, ve, vScr) {
// Define the center point of the line by "y" coordinate
const centerLineY = (vs.y + ve.y) / 2;
// Define the angle slope of the line
const m = (ve.y - vs.y) / (ve.x - vs.x);
// Define the intercept of the line
const b = vs.y - m * vs.x;
// Define the length of the line by "y"
const widthY = Math.abs(ve.y - vs.y);
// Define the distance to the line by "y"
const MIN_DIST_Y = 10;
// Check if the point is on the border of the line
if (
vs.x != ve.x &&
(vs.x < ve.x ? vScr.x >= vs.x && vScr.x <= ve.x : vScr.x <= vs.x && vScr.x >= ve.x) &&
Math.floor(vScr.y) >= Math.floor(m * vScr.x + b) - MIN_DIST_Y &&
Math.floor(vScr.y) <= Math.floor(m * vScr.x + b) + MIN_DIST_Y
) {
return true;
}
// Check if the point is on the border of the vertical line
if (
vs.x === ve.x &&
vScr.x <= vs.x + 10 &&
vScr.x >= vs.x - 10 &&
vScr.y >= centerLineY - widthY / 2 &&
vScr.y <= centerLineY + widthY / 2
) {
return true;
}
}
}

export default PointerChecker;

0 comments on commit b9b398a

Please sign in to comment.