Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Editor] Allow Float32Array for quadpoints in annotations (bug 1907958) #18526

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,19 @@ function isBooleanArray(arr, len) {
* @returns {boolean}
*/
function isNumberArray(arr, len) {
if (Array.isArray(arr)) {
return (
(len === null || arr.length === len) &&
arr.every(x => typeof x === "number")
);
}

// This 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)
);
}

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