Refactor drawWall function for improved readability and maintainability

This commit is contained in:
2025-06-25 17:39:28 +05:30
parent d8a793c421
commit 9696bc0f1e

View File

@@ -38,7 +38,7 @@ async function drawWall(
projectId?: string, projectId?: string,
versionId?: string, versionId?: string,
): Promise<void> { ): Promise<void> {
const { userId, organization, email } = getUserData(); const { userId, organization } = getUserData();
////////// Creating lines Based on the positions clicked ////////// ////////// Creating lines Based on the positions clicked //////////
////////// Allows the user lines that represents walls and roof, floor if forms a polygon ////////// ////////// Allows the user lines that represents walls and roof, floor if forms a polygon //////////
@@ -46,18 +46,10 @@ async function drawWall(
if (!plane.current) return; if (!plane.current) return;
let intersects = raycaster.intersectObject(plane.current, true); let intersects = raycaster.intersectObject(plane.current, true);
let intersectsLines = raycaster.intersectObjects( let intersectsLines = raycaster.intersectObjects(floorPlanGroupLine.current.children, true);
floorPlanGroupLine.current.children, let intersectsPoint = raycaster.intersectObjects(floorPlanGroupPoint.current.children, true);
true
);
let intersectsPoint = raycaster.intersectObjects(
floorPlanGroupPoint.current.children,
true
);
const VisibleintersectsPoint = intersectsPoint.find( const VisibleintersectsPoint = intersectsPoint.find((intersect) => intersect.object.visible);
(intersect) => intersect.object.visible
);
const visibleIntersect = intersectsLines.find( const visibleIntersect = intersectsLines.find(
(intersect) => (intersect) =>
intersect.object.visible && intersect.object.visible &&
@@ -66,33 +58,18 @@ async function drawWall(
CONSTANTS.lineConfig.wallName CONSTANTS.lineConfig.wallName
); );
if ( if ((intersectsPoint.length === 0 || VisibleintersectsPoint === undefined) && intersectsLines.length > 0 && !isSnapped.current && !ispreSnapped.current) {
(intersectsPoint.length === 0 || VisibleintersectsPoint === undefined) &&
intersectsLines.length > 0 &&
!isSnapped.current &&
!ispreSnapped.current
) {
////////// Clicked on a preexisting Line ////////// ////////// Clicked on a preexisting Line //////////
if (visibleIntersect && intersects) { if (visibleIntersect && intersects) {
let IntersectsPoint = new THREE.Vector3( let IntersectsPoint = new THREE.Vector3(intersects[0].point.x, 0.01, intersects[0].point.z);
intersects[0].point.x,
0.01,
intersects[0].point.z
);
if (isAngleSnapped.current && anglesnappedPoint.current) { if (isAngleSnapped.current && anglesnappedPoint.current) {
IntersectsPoint = anglesnappedPoint.current; IntersectsPoint = anglesnappedPoint.current;
} }
if (visibleIntersect.object instanceof THREE.Mesh) { if (visibleIntersect.object instanceof THREE.Mesh) {
const ThroughPoint = const ThroughPoint = visibleIntersect.object.geometry.parameters.path.getPoints(CONSTANTS.lineConfig.lineIntersectionPoints);
visibleIntersect.object.geometry.parameters.path.getPoints( let intersectionPoint = getClosestIntersection(ThroughPoint, IntersectsPoint);
CONSTANTS.lineConfig.lineIntersectionPoints
);
let intersectionPoint = getClosestIntersection(
ThroughPoint,
IntersectsPoint
);
if (intersectionPoint) { if (intersectionPoint) {
const newLines = splitLine( const newLines = splitLine(
@@ -141,7 +118,6 @@ async function drawWall(
userId, userId,
}; };
console.log('input: ', input);
socket.emit("v1:Line:create", input); socket.emit("v1:Line:create", input);
setNewLines([newLines[0], newLines[1], line.current]); setNewLines([newLines[0], newLines[1], line.current]);
@@ -167,11 +143,7 @@ async function drawWall(
let intersectionPoint = intersects[0].point; let intersectionPoint = intersects[0].point;
if ( if (isAngleSnapped.current && line.current.length > 0 && anglesnappedPoint.current) {
isAngleSnapped.current &&
line.current.length > 0 &&
anglesnappedPoint.current
) {
intersectionPoint = anglesnappedPoint.current; intersectionPoint = anglesnappedPoint.current;
} }
if (isSnapped.current && line.current.length > 0 && snappedPoint.current) { if (isSnapped.current && line.current.length > 0 && snappedPoint.current) {
@@ -223,7 +195,6 @@ async function drawWall(
userId, userId,
}; };
console.log('input: ', input);
socket.emit("v1:Line:create", input); socket.emit("v1:Line:create", input);
setNewLines([line.current]); setNewLines([line.current]);