Skip to content

Commit 23f7444

Browse files
rodrigobasilio2022finetjul
authored andcommitted
refactor(function): cropper center function calculation
1 parent e4d0d60 commit 23f7444

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

Sources/Widgets/Widgets3D/ImageCroppingWidget/behavior.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
transformVec3,
66
handleTypeFromName,
77
calculateDirection,
8+
calculateCropperCenter,
89
} from 'vtk.js/Sources/Widgets/Widgets3D/ImageCroppingWidget/helpers';
910

1011
export default function widgetBehavior(publicAPI, model) {
@@ -76,14 +77,8 @@ export default function widgetBehavior(publicAPI, model) {
7677

7778
if (type === 'faces') {
7879
// get center of current crop box
79-
const center = [
80-
(planes[0] + planes[1]) / 2,
81-
(planes[2] + planes[3]) / 2,
82-
(planes[4] + planes[5]) / 2,
83-
];
84-
85-
// manipulator should be a line manipulator
86-
const worldCenter = transformVec3(center, indexToWorldT);
80+
const worldCenter = calculateCropperCenter(planes, indexToWorldT);
81+
8782
manipulator.setHandleOrigin(worldCenter);
8883
manipulator.setHandleNormal(
8984
calculateDirection(model.activeState.getOrigin(), worldCenter)
@@ -100,14 +95,7 @@ export default function widgetBehavior(publicAPI, model) {
10095
const faceName = edgeAxis.map((i) => AXES[i + 1]).join('');
10196
const handle = model.widgetState.getStatesWithLabel(faceName)[0];
10297
// get center of current crop box
103-
const center = [
104-
(planes[0] + planes[1]) / 2,
105-
(planes[2] + planes[3]) / 2,
106-
(planes[4] + planes[5]) / 2,
107-
];
108-
109-
// manipulator should be a line manipulator
110-
const worldCenter = transformVec3(center, indexToWorldT);
98+
const worldCenter = calculateCropperCenter(planes, indexToWorldT);
11199

112100
manipulator.setHandleNormal(
113101
calculateDirection(handle.getOrigin(), worldCenter)

Sources/Widgets/Widgets3D/ImageCroppingWidget/helpers.js

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ export function handleTypeFromName(name) {
3535
return 'faces';
3636
}
3737

38+
export function calculateCropperCenter(planes, transform) {
39+
// get center of current crop box
40+
const center = [
41+
(planes[0] + planes[1]) / 2,
42+
(planes[2] + planes[3]) / 2,
43+
(planes[4] + planes[5]) / 2,
44+
];
45+
return transformVec3(center, transform);
46+
}
47+
3848
export function calculateDirection(v1, v2) {
3949
const direction = vec3.create();
4050
vec3.subtract(direction, v1, v2);

0 commit comments

Comments
 (0)