From 78c90fc3e14dcc361c40bc7a2c870803f2d87f06 Mon Sep 17 00:00:00 2001 From: Chung Min Kim Date: Fri, 22 Mar 2024 16:45:01 -0700 Subject: [PATCH] Code nit --- src/viser/client/src/App.tsx | 46 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/viser/client/src/App.tsx b/src/viser/client/src/App.tsx index bc44b4d54..4cebe9047 100644 --- a/src/viser/client/src/App.tsx +++ b/src/viser/client/src/App.tsx @@ -344,28 +344,32 @@ function ViewerCanvas({ children }: { children: React.ReactNode }) { }); } - // If the ScenePointerEvent had mouse drag movement, we will send a "box" message: - // Use the first and last mouse positions to create a box. - const screenEventList = viewer.sceneClickInfo.current!.screenEventList; - const firstScreenEvent = screenEventList[0]; - const lastScreenEvent = screenEventList![screenEventList.length - 1]; - - // Again, click should be in openCV image coordinates (normalized). - const firstMouseVector = clickToOpenCV(viewer, firstScreenEvent); - const lastMouseVector = clickToOpenCV(viewer, lastScreenEvent); + else if ( + click_info.screenEventList!.length > 1 && + click_info.enabled_box + ) { + + // If the ScenePointerEvent had mouse drag movement, we will send a "box" message: + // Use the first and last mouse positions to create a box. + const screenEventList = viewer.sceneClickInfo.current!.screenEventList; + const firstScreenEvent = screenEventList[0]; + const lastScreenEvent = screenEventList![screenEventList.length - 1]; + + // Again, click should be in openCV image coordinates (normalized). + const firstMouseVector = clickToOpenCV(viewer, firstScreenEvent); + const lastMouseVector = clickToOpenCV(viewer, lastScreenEvent); + + const x_min = Math.min(firstMouseVector.x, lastMouseVector.x); + const x_max = Math.max(firstMouseVector.x, lastMouseVector.x); + const y_min = Math.min(firstMouseVector.y, lastMouseVector.y); + const y_max = Math.max(firstMouseVector.y, lastMouseVector.y); + + // Send the upper-left and lower-right corners of the box. + const screenBoxList: [number, number][] = [ + [x_min, y_min], + [x_max, y_max], + ]; - const x_min = Math.min(firstMouseVector.x, lastMouseVector.x); - const x_max = Math.max(firstMouseVector.x, lastMouseVector.x); - const y_min = Math.min(firstMouseVector.y, lastMouseVector.y); - const y_max = Math.max(firstMouseVector.y, lastMouseVector.y); - - // Send the upper-left and lower-right corners of the box. - const screenBoxList: [number, number][] = [ - [x_min, y_min], - [x_max, y_max], - ]; - - if (click_info.enabled_box) { sendClickThrottled({ type: "ScenePointerMessage", event_type: "rect-select",