Skip to content

Commit

Permalink
Code nit
Browse files Browse the repository at this point in the history
  • Loading branch information
chungmin99 committed Mar 22, 2024
1 parent 729e340 commit 78c90fc
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/viser/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 78c90fc

Please sign in to comment.