From ef07f272b88b34ae7628da5ebd18bcdc0c2debc6 Mon Sep 17 00:00:00 2001 From: rodrigobasilio2022 Date: Tue, 30 Jan 2024 10:53:10 -0300 Subject: [PATCH] refactor: early return --- .../Manipulators/LineManipulator/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Widgets/Manipulators/LineManipulator/index.js b/Sources/Widgets/Manipulators/LineManipulator/index.js index 197c45e0353..fe43c2de70f 100644 --- a/Sources/Widgets/Manipulators/LineManipulator/index.js +++ b/Sources/Widgets/Manipulators/LineManipulator/index.js @@ -12,14 +12,6 @@ export function projectDisplayToLine( renderer, glRenderWindow ) { - const near = glRenderWindow.displayToWorld(x, y, 0, renderer); - const far = glRenderWindow.displayToWorld(x, y, 1, renderer); - const viewDir = [0, 0, 0]; - vtkMath.subtract(far, near, viewDir); - - const normal = [0, 0, 0]; - vtkMath.cross(lineDirection, viewDir, normal); - vtkMath.cross(normal, viewDir, normal); // if the active camera viewPlaneNormal and line direction are parallel, no change is allowed const dotProduct = Math.abs( vtkMath.dot(renderer.getActiveCamera().getViewPlaneNormal(), lineDirection) @@ -28,6 +20,14 @@ export function projectDisplayToLine( if (1 - dotProduct < EPSILON) { return []; } + const near = glRenderWindow.displayToWorld(x, y, 0, renderer); + const far = glRenderWindow.displayToWorld(x, y, 1, renderer); + const viewDir = [0, 0, 0]; + vtkMath.subtract(far, near, viewDir); + + const normal = [0, 0, 0]; + vtkMath.cross(lineDirection, viewDir, normal); + vtkMath.cross(normal, viewDir, normal); const numerator = vtkMath.dot( [near[0] - lineOrigin[0], near[1] - lineOrigin[1], near[2] - lineOrigin[2]],