Skip to content

Commit

Permalink
Add acces to other dim in helper
Browse files Browse the repository at this point in the history
Fix typo, rename index to value
  • Loading branch information
ivmartel committed Jan 10, 2025
1 parent 67897eb commit 3f4f909
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
67 changes: 49 additions & 18 deletions src/image/positionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ export class PositionHelper {
}

/**
* Get the maximum scroll index.
* Get the maximum dimension value.
*
* @returns {number} The maximum index.
* @param {number} dim The dimension.
* @returns {number} The maximum value.
*/
getMaximumScrollIndex() {
return this.#geometry.getSize().get(this.#scrollDimIndex) - 1;
getMaximumDimValue(dim) {
return this.#geometry.getSize().get(dim) - 1;
}

/**
* Get the maximum scroll value.
*
* @returns {number} The maximum value.
*/
getMaximumScrollValue() {
return this.getMaximumDimValue(this.#scrollDimIndex);
}

/**
Expand All @@ -109,27 +119,48 @@ export class PositionHelper {
}

/**
* Get the scroll index for the current position.
* Get the value at dimension index for the current position.
*
* @returns {number} The index.
* @param {number} dim The dimension.
* @returns {number} The value.
*/
getCurrentPositionScrollIndex() {
const values = this.getCurrentIndex().getValues();
return values[this.#scrollDimIndex];
getCurrentPositionDimValue(dim) {
return this.getCurrentIndex().get(dim);
}

/**
* Get the value at scroll index for the current position.
*
* @returns {number} The value.
*/
getCurrentPositionScrollValue() {
return this.getCurrentPositionDimValue(this.#scrollDimIndex);
}

/**
* Get the current position updated at the provided scroll index.
* Get the current position updated at the provided dimension index
* with the input value.
*
* @param {number} index The scroll index.
* @param {number} dim The dimension.
* @param {number} value The value to used at dimension index.
* @returns {Point} The position.
*/
getCurrentPositionAtScrollIndex(index) {
getCurrentPositionAtDimValue(dim, value) {
const values = this.getCurrentIndex().getValues();
values[this.#scrollDimIndex] = index;
values[dim] = value;
return this.#geometry.indexToWorld(new Index(values));
}

/**
* Get the current position updated at scroll index with the input value.
*
* @param {number} value The value to use at scroll index.
* @returns {Point} The position.
*/
getCurrentPositionAtScrollValue(value) {
return this.getCurrentPositionAtDimValue(this.#scrollDimIndex, value);
}

/**
* Get the current index.
*
Expand All @@ -146,7 +177,7 @@ export class PositionHelper {
* @param {boolean} [silent] Flag to fire event or not.
* @returns {boolean} True if possible and in bounds.
*/
setCurrentPositon(position, silent) {
setCurrentPosition(position, silent) {
let res = false;
if (typeof position !== 'undefined') {
res = this.#positionAccessor.setCurrentPosition(position, silent);
Expand All @@ -161,10 +192,10 @@ export class PositionHelper {
* @param {boolean} [silent] Flag to fire event or not.
* @returns {boolean} True if possible and in bounds.
*/
setCurrentPositonSafe(position, silent) {
setCurrentPositionSafe(position, silent) {
let res = false;
if (this.isPositionInBounds(position)) {
res = this.setCurrentPositon(position, silent);
res = this.setCurrentPosition(position, silent);
}
return res;
}
Expand Down Expand Up @@ -230,7 +261,7 @@ export class PositionHelper {
* @returns {boolean} True if possible and in bounds.
*/
incrementPosition(dim) {
return this.setCurrentPositonSafe(this.getIncrementPosition(dim));
return this.setCurrentPositionSafe(this.getIncrementPosition(dim));
}

/**
Expand All @@ -240,7 +271,7 @@ export class PositionHelper {
* @returns {boolean} True if possible and in bounds.
*/
decrementPosition(dim) {
return this.setCurrentPositonSafe(this.getDecrementPosition(dim));
return this.setCurrentPositionSafe(this.getDecrementPosition(dim));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions tests/pacs/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ function getSlider(layerGroupDivId) {
range.oninput = function () {
const lg = _app.getLayerGroupByDivId(layerGroupDivId);
const ph = lg.getPositionHelper();
const pos = ph.getCurrentPositionAtScrollIndex(this.value);
ph.setCurrentPositon(pos);
const pos = ph.getCurrentPositionAtScrollValue(this.value);
ph.setCurrentPosition(pos);
};
return range;
}
Expand All @@ -504,11 +504,11 @@ function initSliders() {
if (slider) {
const lg = _app.getLayerGroupByDivId(lgId);
const ph = lg.getPositionHelper();
const maxIndex = ph.getMaximumScrollIndex();
if (maxIndex !== 0) {
const max = ph.getMaximumScrollValue();
if (max !== 0) {
slider.disabled = false;
slider.max = maxIndex;
slider.value = ph.getCurrentPositionScrollIndex();
slider.max = max;
slider.value = ph.getCurrentPositionScrollValue();
}
}
}
Expand All @@ -525,7 +525,7 @@ function updateSliders() {
if (slider) {
const lg = _app.getLayerGroupByDivId(lgId);
const ph = lg.getPositionHelper();
slider.value = ph.getCurrentPositionScrollIndex();
slider.value = ph.getCurrentPositionScrollValue();
}
}
}
Expand Down

0 comments on commit 3f4f909

Please sign in to comment.