Skip to content

Commit

Permalink
delete ald comments, update ToolRect
Browse files Browse the repository at this point in the history
  • Loading branch information
VikaAbysova committed Oct 24, 2023
1 parent b6ffa3e commit bac099a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 103 deletions.
21 changes: 0 additions & 21 deletions src/engine/tools2d/ToolAngle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// Imports
// **********************************************

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

Expand Down Expand Up @@ -94,21 +93,6 @@ class ToolAngle {
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 Expand Up @@ -159,11 +143,9 @@ class ToolAngle {
const M_180 = 180.0;
const M_PI = 3.1415926535;
if (cosAlp > 1.0) {
// console.log('get Angle > 1');
return 0.0;
}
if (cosAlp < -1.0) {
// console.log('get Angle < -1');
return 180.0;
}
const ang = (Math.acos(cosAlp) * M_180) / M_PI;
Expand All @@ -180,10 +162,8 @@ class ToolAngle {
}

this.m_numClicks++;
// console.log('1st click: add 3 points');
} else if (this.m_numClicks === 1) {
this.m_numClicks++;
// console.log(`2st click: points are: ${this.m_points[0].x}, ${this.m_points[0].y} -> ${this.m_points[1].x}, ${this.m_points[1].y}`);
} else {
console.log('3rd click: finalize angle');
// this.m_numClicks === 2
Expand Down Expand Up @@ -220,7 +200,6 @@ class ToolAngle {
for (let idx = this.m_numClicks; idx < NUM_3; idx++) {
this.m_points[idx].x = vTex.x;
this.m_points[idx].y = vTex.y;
// console.log(`onMouseMove. modify point[${idx}]: now = ${vTex.x}, ${vTex.y}`);
}
// invoke redraw
this.m_objGraphics2d.forceUpdate();
Expand Down
19 changes: 0 additions & 19 deletions src/engine/tools2d/ToolArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ class ToolArea {
this.m_objEdit = objArea;
return objArea.m_points[j];
}
// const MIN_DIST = 4.0;
// if (this.getDistMm(vScr, vScrProj_S) <= MIN_DIST) {
// this.m_objEdit = objArea;
// return objArea.m_points[j];
// }
// if too close pick
} // for (j) all point in area
} // for (i) all areas
return null;
Expand All @@ -115,11 +109,8 @@ class ToolArea {
const y = vVolOld.y;
vVolOld.x = vVolNew.x;
vVolOld.y = vVolNew.y;
//const vObjSelfInters = ToolArea.getSelfIntersectPoint(this.m_objEdit.m_points);
//if (vObjSelfInters !== null) {
const hasInters = ToolArea.hasSelfIntersection(this.m_objEdit.m_points);
if (hasInters) {
// console.log('ToolArea. self inters found');
vVolOld.x = x;
vVolOld.y = y;
}
Expand Down Expand Up @@ -263,7 +254,6 @@ class ToolArea {
m_vIntersection: vInter,
m_lineIndex: 0,
};
// console.log('getSelfIntersection: detect with start');
return objInter;
}
return null;
Expand Down Expand Up @@ -465,7 +455,6 @@ class ToolArea {
const objArea = this.m_areas[a];
const isClosed = objArea.m_isClosed;
const numPoints = isClosed ? objArea.m_points.length + 1 : objArea.m_points.length;
// console.log(`ToolArea. render ${numPoints} points in poly`);

// calc area centroid in screen
let xScrCenter = 0.0;
Expand All @@ -475,7 +464,6 @@ class ToolArea {
for (let i = 0; i < numPoints; i++) {
const iPoly = i < objArea.m_points.length ? i : 0;
const vTex0 = objArea.m_points[iPoly];
// console.log(`ToolArea. render point ${vTex0.x}, ${vTex0.y} `);
const vScr = ToolDistance.textureToScreen(vTex0.x, vTex0.y, this.m_wScreen, this.m_hScreen, store);
if (i === 0) {
ctx.moveTo(vScr.x, vScr.y);
Expand All @@ -495,13 +483,6 @@ class ToolArea {
// draw area
if (isClosed) {
const strMsg = objArea.m_area.toFixed(2) + ' mm^2';
// const SHIFT_UP = 8;
//const vTex0 = objArea.m_points[0];
//const vs0 = ToolDistance.textureToScreen(vTex0.x, vTex0.y, this.m_wScreen, this.m_hScreen, store);
//const xText = vs0.x;
//const yText = vs0.y - SHIFT_UP;
// ctx.fillText(strMsg, xText, yText);

ctx.fillText(strMsg, xScrCenter, yScrCenter);
} // if this poly closed
} // for (a) all polys
Expand Down
19 changes: 0 additions & 19 deletions src/engine/tools2d/ToolDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// Imports
// **********************************************

// import ToolDistance from './ToolDistance';

// **********************************************
// Class
// **********************************************
Expand Down Expand Up @@ -90,7 +88,6 @@ class ToolDelete {
const objTool = tools[i];
const vDetect = objTool.getEditPoint(vScr, store);
if (vDetect !== null) {
// console.log(`ToolEdit. point tracked: ${vDetect.x}, ${vDetect.y}`);
this.m_pointTracked = vScr;
this.m_toolTracked = objTool;
break;
Expand All @@ -101,15 +98,6 @@ class ToolDelete {
// invoke forced 2d render
this.m_objGraphics2d.forceUpdate();
}
} else {
/*
if (this.m_pointTracked !== null) {
const vTexNew = ToolDistance.screenToTexture(xScr, yScr, this.m_wScreen, this.m_hScreen, store);
this.m_toolTracked.moveEditPoint(this.m_pointTracked, vTexNew);
// invoke forced 2d render
this.m_objGraphics2d.forceUpdate();
} // if we have tracked point
*/
}
}

Expand All @@ -126,13 +114,6 @@ class ToolDelete {
*/
render(ctx) {
if (this.m_pointTracked !== null) {
// const vScr = ToolDistance.textureToScreen(this.m_pointTracked.x, this.m_pointTracked.y, this.m_wScreen, this.m_hScreen, store);
// const RAD_CIRCLE_EDIT = 10;
// ctx.lineWidth = 2;
//ctx.strokeStyle = 'green';
// ctx.fillStyle = 'rgb(220, 94, 71)';
// ctx.arc(vScr.x, vScr.y, RAD_CIRCLE_EDIT, 0.0, 2 * 3.1415962, false);
// ctx.fill();
const vScr = this.m_pointTracked;
ctx.beginPath();

Expand Down
11 changes: 0 additions & 11 deletions src/engine/tools2d/ToolDistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ class ToolDistance {
this.m_objEdit = objLine;
return objLine.vs;
}
// const MIN_DIST = 4.0;
// if (this.getDistMm(vScr, vScrS) <= MIN_DIST) {
// this.m_objEdit = objLine;
// return objLine.vs;
// }
// if (this.getDistMm(vScr, vScrE) <= MIN_DIST) {
// this.m_objEdit = objLine;
// return objLine.ve;
// }
}
return null;
}
Expand Down Expand Up @@ -204,8 +195,6 @@ class ToolDistance {
};
this.m_lines.push(objLine);
this.m_mouseDown = true;
// this.m_pointStart = v;
// console.log(`onMouseDown: ${xScr}, ${yScr}`);
}

onMouseMove(xScr, yScr, store) {
Expand Down
22 changes: 16 additions & 6 deletions src/engine/tools2d/ToolRect.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,25 @@ class ToolRect {
const vScrMax = ToolDistance.textureToScreen(objRect.vMax.x, objRect.vMax.y, this.m_wScreen, this.m_hScreen, store);

// Check if the point is inside or on the border of the rectangle
if (vScrMin.x <= vScr.x && vScr.x <= vScrMax.x && vScrMin.y <= vScr.y && vScr.y <= vScrMax.y) {
if (
(vScrMin.x < vScrMax.x && vScrMin.x <= vScr.x && vScr.x <= vScrMax.x && vScrMin.y <= vScr.y && vScr.y <= vScrMax.y) ||
(vScrMin.x < vScrMax.x &&
vScrMin.y > vScrMax.y &&
vScrMin.x <= vScr.x &&
vScr.x <= vScrMax.x &&
vScrMin.y >= vScr.y &&
vScr.y >= vScrMax.y) ||
(vScrMin.x > vScrMax.x && vScrMin.x >= vScr.x && vScr.x >= vScrMax.x && vScrMin.y <= vScr.y && vScr.y <= vScrMax.y) ||
(vScrMin.x > vScrMax.x &&
vScrMin.y > vScrMax.y &&
vScrMin.x >= vScr.x &&
vScr.x >= vScrMax.x &&
vScrMin.y >= vScr.y &&
vScr.y >= vScrMax.y)
) {
this.m_objEdit = objRect;
return objRect.vMin;
}
// const MIN_DIST = 4.0;
// if (this.getDistMm(vScr, vScrMax) <= MIN_DIST) {
// this.m_objEdit = objRect;
// return objRect.vMax;
// }
}
return null;
}
Expand Down
27 changes: 0 additions & 27 deletions src/engine/tools2d/ToolText.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import ToolDistance from './ToolDistance';
import StoreActionType from '../../store/ActionTypes';
// import UiModalText from '../../ui/UiModalText';

// **********************************************
// Class
Expand Down Expand Up @@ -65,14 +64,11 @@ class ToolText {
for (let i = 0; i < numTexts; i++) {
const objText = this.m_texts[i];
const vScrProj = ToolDistance.textureToScreen(objText.point.x, objText.point.y, this.m_wScreen, this.m_hScreen, store);
// const MIN_DIST = 4.0;

// Define the distance by "x" coordinate from the center of the text
const MIN_DIST_X = objText.text.length * 4;
// Define the distance by "y" coordinate from the text
const MIN_DIST_Y = 16;
// if (this.getDistMm(vScr, vScrProj) <= MIN_DIST)

// Check if the point is on the text
if (
vScr.x >= vScrProj.x - MIN_DIST_X &&
Expand Down Expand Up @@ -191,29 +187,6 @@ class ToolText {
ctx.fillText(lines[j], vScr.x, vScr.y + j * LINE_HEIGHT - ((lines.length - 1) * LINE_HEIGHT) / 2);
}
} // for (i)

/*
const numRects = this.m_rects.length;
for (let i = 0; i < numRects; i++) {
const objRect = this.m_rects[i];
const vTexMin = objRect.vMin;
const vTexMax = objRect.vMax;
const vScrMin = ToolDistance.textureToScreen(vTexMin.x, vTexMin.y, this.m_wScreen, this.m_hScreen, store);
const vScrMax = ToolDistance.textureToScreen(vTexMax.x, vTexMax.y, this.m_wScreen, this.m_hScreen, store);
ctx.beginPath();
ctx.moveTo(vScrMin.x, vScrMin.y);
ctx.lineTo(vScrMax.x, vScrMin.y);
ctx.lineTo(vScrMax.x, vScrMax.y);
ctx.lineTo(vScrMin.x, vScrMax.y);
ctx.lineTo(vScrMin.x, vScrMin.y);
ctx.stroke();
// draw text
const xText = Math.floor((vScrMin.x + vScrMax.x) * 0.5);
const yText = Math.floor((vScrMin.y + vScrMax.y) * 0.5);
const strMsg = objRect.area.toFixed(2) + ' mm^2';
ctx.fillText(strMsg, xText, yText);
} // for (i) all rects
*/
} // end render
} // end class ToolText

Expand Down

0 comments on commit bac099a

Please sign in to comment.