Skip to content

Commit

Permalink
fix(ruler): avoid error when manipulator returns no worldCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Oct 27, 2023
1 parent d879675 commit 1a34f8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/vtk/PolygonWidget/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ export default function widgetBehavior(publicAPI: any, model: any) {
return false;
}

function getWorldCoords(callData: any) {
const getWorldCoords = (event: any) => {
const manipulator =
model.activeState?.getManipulator?.() ?? model.manipulator;
if (!manipulator) {
return undefined;
}

return manipulator.handleEvent(callData, model._apiSpecificRenderWindow)
return manipulator.handleEvent(event, model._apiSpecificRenderWindow)
.worldCoords;
}
};

function updateActiveStateHandle(callData: any) {
const worldCoords = getWorldCoords(callData);
Expand Down
31 changes: 16 additions & 15 deletions src/vtk/RulerWidget/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ export default function widgetBehavior(publicAPI: any, model: any) {
return overSegment;
};

const getWorldCoords = (event: any) => {
const manipulator =
model.activeState?.getManipulator?.() ?? model.manipulator;
if (!manipulator) {
return undefined;
}
return manipulator.handleEvent(event, model._apiSpecificRenderWindow)
.worldCoords;
};

/**
* Places or drags a point.
*/
Expand All @@ -86,11 +96,8 @@ export default function widgetBehavior(publicAPI: any, model: any) {
return macro.VOID;
}

const { worldCoords } = model.manipulator.handleEvent(
eventData,
model._apiSpecificRenderWindow
)?.worldCoords;
if (!worldCoords.length) {
const worldCoords = getWorldCoords(eventData);
if (!worldCoords?.length) {
return macro.VOID;
}

Expand Down Expand Up @@ -141,11 +148,8 @@ export default function widgetBehavior(publicAPI: any, model: any) {
* Moves a point around.
*/
publicAPI.handleMouseMove = (eventData: any) => {
const { worldCoords } = model.manipulator.handleEvent(
eventData,
model._apiSpecificRenderWindow
)?.worldCoords;
if (!worldCoords.length) {
const worldCoords = getWorldCoords(eventData);
if (!worldCoords?.length) {
return macro.VOID;
}

Expand Down Expand Up @@ -181,11 +185,8 @@ export default function widgetBehavior(publicAPI: any, model: any) {
*/
publicAPI.handleLeftButtonRelease = (eventData: any) => {
if (draggingState) {
const { worldCoords } = model.manipulator.handleEvent(
eventData,
model._apiSpecificRenderWindow
)?.worldCoords;
if (worldCoords.length) {
const worldCoords = getWorldCoords(eventData);
if (worldCoords?.length) {
draggingState.setOrigin(worldCoords);
}

Expand Down

0 comments on commit 1a34f8b

Please sign in to comment.