Skip to content

Commit

Permalink
fix(BoundingRectangle): fit handle circles within rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Sep 15, 2023
1 parent 0f8e55f commit e6a552a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/components/tools/BoundingRectangle.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script setup lang="ts">
import { computed, ref, watch, toRefs } from 'vue';
import { ANNOTATION_TOOL_HANDLE_RADIUS } from '@/src/constants';
import { useViewStore } from '@/src/store/views';
import { worldToSVG } from '@/src/utils/vtk-helpers';
import { nonNullable } from '@/src/utils/index';
import vtkLPSView2DProxy from '@/src/vtk/LPSView2DProxy';
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox';
import { Bounds, Vector3 } from '@kitware/vtk.js/types';
import { computed, ref, watch, toRefs } from 'vue';
import { onVTKEvent } from '@/src/composables/onVTKEvent';
const props = defineProps<{
Expand Down Expand Up @@ -44,11 +45,13 @@ const updateRectangle = () => {
});
const [x, y] = vtkBoundingBox.getMinPoint(screenBounds);
const [maxX, maxY] = vtkBoundingBox.getMaxPoint(screenBounds);
const handleRadius = ANNOTATION_TOOL_HANDLE_RADIUS / devicePixelRatio;
const handleDiameter = 2 * handleRadius;
rectangle.value = {
x,
y,
width: maxX - x,
height: maxY - y,
x: x - handleRadius,
y: y - handleRadius,
width: maxX - x + handleDiameter,
height: maxY - y + handleDiameter,
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/tools/polygon/PolygonSVG2D.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<g>
<!-- radius is related to the vtkRectangleWidget scale, specified in state -->
<!-- radius should match constants.ANNOTATION_TOOL_HANDLE_RADIUS and should be related to vtkHandleWidget scale. -->
<circle
v-for="({ point: [x, y], radius }, index) in handlePoints"
:key="index"
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ export const Messages = {
'Lost the WebGL context! Please reload the webpage. If the problem persists, you may need to restart your web browser.',
},
} as const;

export const ANNOTATION_TOOL_HANDLE_RADIUS = 10; // pixels

0 comments on commit e6a552a

Please sign in to comment.