@kitware/vtk.js 26.9.3 → 26.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import macro from '../../macros.js';
1
+ import macro, { vtkWarningMacro } from '../../macros.js';
2
2
  import vtkCompositeMouseManipulator from './CompositeMouseManipulator.js';
3
3
 
4
4
  // vtkMouseRangeManipulator methods
@@ -23,13 +23,16 @@ function vtkMouseRangeManipulator(publicAPI, model) {
23
23
  // the user's cursor is from the start of the interaction, the more
24
24
  // their movements will effect the value.
25
25
 
26
- var scalingFactor = listener.exponentialScroll ? Math.pow(listener.scale, Math.log2(Math.abs(model.interactionNetDelta) + 2)) : listener.scale;
27
- var newDelta = delta * scalingFactor + incrementalDelta.get(listener);
28
- var value = oldValue + newDelta; // Compute new value based on step
26
+ var scalingFactor = listener.exponentialScroll ? Math.pow(listener.scale, Math.log2(Math.abs(model.interactionNetDelta) + 2)) : listener.scale; // Preserve the sign of scale (which can be used to invert the scrolling direction)
27
+ // after the power operation above (in case of exponentialScroll).
29
28
 
30
- var difference = value - listener.min;
31
- var stepsToDifference = Math.round(difference / listener.step);
32
- value = listener.min + listener.step * stepsToDifference;
29
+ scalingFactor = Math.abs(scalingFactor) * Math.sign(listener.scale);
30
+ var newDelta = delta * scalingFactor + incrementalDelta.get(listener); // Compute new value based on step
31
+ // In the following line, Math.abs is required so that the floor function
32
+ // consistently rounds to the lowest absolute integer.
33
+
34
+ var stepsToDifference = Math.floor(Math.abs(newDelta / listener.step));
35
+ var value = oldValue + listener.step * stepsToDifference * Math.sign(newDelta);
33
36
  value = Math.max(value, listener.min);
34
37
  value = Math.min(value, listener.max);
35
38
 
@@ -97,13 +100,19 @@ function vtkMouseRangeManipulator(publicAPI, model) {
97
100
  publicAPI.setScrollListener = function (min, max, step, getValue, setValue) {
98
101
  var scale = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
99
102
  var exponentialScroll = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
103
+
104
+ if (step < 0) {
105
+ vtkWarningMacro('Value of step cannot be negative. If you want to invert the scrolling direction, use a negative scale value instead.');
106
+ }
107
+
108
+ var stepSize = Math.abs(step);
100
109
  var getFn = Number.isFinite(getValue) ? function () {
101
110
  return getValue;
102
111
  } : getValue;
103
112
  model.scrollListener = {
104
113
  min: min,
105
114
  max: max,
106
- step: step,
115
+ step: stepSize,
107
116
  getValue: getFn,
108
117
  setValue: setValue,
109
118
  scale: scale,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "26.9.3",
3
+ "version": "26.9.4",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",