Skip to content

Commit

Permalink
remove safeMultiply
Browse files Browse the repository at this point in the history
  • Loading branch information
knollengewaechs committed Nov 28, 2024
1 parent 19961f6 commit 3feaa7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
5 changes: 4 additions & 1 deletion frontend/javascripts/libs/format_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,12 @@ export function formatBytes(nbytes: number) {
}

export function formatVoxels(voxelCount: number) {
if (voxelCount == null || !Number.isFinite(voxelCount)) {
if (voxelCount == null) {
return "";
}
if (!Number.isFinite(voxelCount)) {
return "Infinity";
}
if (voxelCount > 2 ** 50) {
return `${(voxelCount / 2 ** 50).toPrecision(4)} PVx`;
}
Expand Down
21 changes: 3 additions & 18 deletions frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,13 @@ function getDatasetExtentAsProduct(extent: {
height: number;
depth: number;
}) {
const safeMultiply = (a: number, b: number) => {
const result = a * b;
if (!Number.isFinite(result)) {
throw new Error("Dataset extent product exceeds maximum safe number");
}
return result;
};
return safeMultiply(safeMultiply(extent.width, extent.height), extent.depth);
return extent.width * extent.height * extent.depth;
}
export function getDatasetExtentInVoxelAsProduct(dataset: APIDataset) {
try {
return getDatasetExtentAsProduct(getDatasetExtentInVoxel(dataset));
} catch (e) {
console.error(e);
}
return getDatasetExtentAsProduct(getDatasetExtentInVoxel(dataset));
}
export function getDatasetExtentInUnitAsProduct(dataset: APIDataset) {
try {
return getDatasetExtentAsProduct(getDatasetExtentInUnit(dataset));
} catch (e) {
console.error(e);
}
return getDatasetExtentAsProduct(getDatasetExtentInUnit(dataset));
}
export function determineAllowedModes(settings?: Settings): {
preferredMode: APIAllowedMode | null | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,17 @@ export function DatasetExtentRow({ dataset }: { dataset: APIDataset }) {
const extentInLength = getDatasetExtentAsString(dataset, false);
const extentProductInVx = getDatasetExtentInVoxelAsProduct(dataset);
const extentProductInUnit = getDatasetExtentInUnitAsProduct(dataset);
const formattedExtentinUnit =
extentProductInUnit != null
? formatNumberToVolume(
extentProductInUnit,
LongUnitToShortUnitMap[dataset.dataSource.scale.unit],
)
: "Unable to calculate";
const formattedExtentinUnit = formatNumberToVolume(
extentProductInUnit,
LongUnitToShortUnitMap[dataset.dataSource.scale.unit],
);

const renderDSExtentTooltip = () => {
return (
<div>
Dataset extent:
<br />
{extentProductInVx != null ? formatVoxels(extentProductInVx) : "Unable to calculate"}
{formatVoxels(extentProductInVx)}
<br />
{formattedExtentinUnit}
</div>
Expand Down

0 comments on commit 3feaa7f

Please sign in to comment.