Skip to content

Commit

Permalink
[Editor] Allow Float32Array for quadpoints in annotations (bug 1907958)
Browse files Browse the repository at this point in the history
Added annotations could have some quadpoints (highlight, ink).
The isNumberArray check was returning false and consequently the annotation wasn't
printable.
The tests didn't catch this issue because the quadpoints were passed as Array.
So driver.js has been updated in order to pass them as Float32Array in order
to be in a situation similar to the real life one.
  • Loading branch information
calixteman committed Jul 31, 2024
1 parent f6b356e commit 1bdc9f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,15 @@ function isBooleanArray(arr, len) {
* @returns {boolean}
*/
function isNumberArray(arr, len) {
// ArrayBuffer.isView... check allows us to have typed arrays but not the
// BigInt64Array/BigUint64Array types (their elements aren't "number").
return (
Array.isArray(arr) &&
(len === null || arr.length === len) &&
arr.every(x => typeof x === "number")
(ArrayBuffer.isView(arr) &&
(arr.length === 0 || typeof arr[0] === "number") &&
(len === null || arr.length === len)) ||
(Array.isArray(arr) &&
(len === null || arr.length === len) &&
arr.every(x => typeof x === "number"))
);
}

Expand Down
7 changes: 6 additions & 1 deletion test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ class Driver {

if (task.annotationStorage) {
for (const annotation of Object.values(task.annotationStorage)) {
const { bitmapName } = annotation;
const { bitmapName, quadPoints } = annotation;
if (bitmapName) {
promise = promise.then(async doc => {
const response = await fetch(
Expand Down Expand Up @@ -643,6 +643,11 @@ class Driver {
return doc;
});
}
if (quadPoints) {
// Just to ensure that the quadPoints are always a Float32Array
// like IRL (in order to avoid bugs like bug 1907958).
annotation.quadPoints = new Float32Array(quadPoints);
}
}
}

Expand Down

0 comments on commit 1bdc9f6

Please sign in to comment.