Skip to content
Snippets Groups Projects
Commit 524d38c4 authored by David Sehnal's avatar David Sehnal
Browse files

fix bounding box bug

parent 68a2e523
No related branches found
No related tags found
No related merge requests found
......@@ -168,7 +168,7 @@ function _build(state: BuildState): Grid3D {
function build(data: PositionData, boundary: Boundary, cellSizeOrCount?: Vec3 | number) {
// need to expand the grid bounds to avoid rounding errors
const expandedBox = Box3D.expand(Box3D.empty(), boundary.box, Vec3.create(0.5, 0.5, 0.5));
const expandedBox = Box3D.expand(Box3D(), boundary.box, Vec3.create(0.5, 0.5, 0.5));
const { indices } = data;
const S = Box3D.size(Vec3.zero(), expandedBox);
......
......@@ -13,12 +13,12 @@ import { Sphere3D } from './sphere3d';
interface Box3D { min: Vec3, max: Vec3 }
function Box3D() {
return Box3D.empty();
return Box3D.zero();
}
namespace Box3D {
export function create(min: Vec3, max: Vec3): Box3D { return { min, max }; }
export function empty(): Box3D { return { min: Vec3(), max: Vec3() }; }
export function zero(): Box3D { return { min: Vec3(), max: Vec3() }; }
export function copy(out: Box3D, a: Box3D): Box3D {
Vec3.copy(out.min, a.min);
......@@ -27,7 +27,7 @@ namespace Box3D {
}
export function clone(a: Box3D): Box3D {
return copy(empty(), a);
return copy(zero(), a);
}
/** Get box from sphere, uses extrema if available */
......@@ -77,6 +77,7 @@ namespace Box3D {
return tmpSizeV[0] * tmpSizeV[1] * tmpSizeV[2];
}
/** Sets min to Number.MAX_VALUE and max to -Number.MAX_VALUE */
export function setEmpty(box: Box3D): Box3D {
Vec3.set(box.min, Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
Vec3.set(box.max, -Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
......
......@@ -71,7 +71,7 @@ export namespace VolumeStreaming {
// fake the info
const info = entryData || { kind: 'em', header: { sampling: [fakeSampling], availablePrecisions: [{ precision: 0, maxVoxels: 0 }] }, emDefaultContourLevel: Volume.IsoValue.relative(0) };
const box = (structure && structure.boundary.box) || Box3D.empty();
const box = (structure && structure.boundary.box) || Box3D();
return {
view: PD.MappedStatic(defaultView || (info.kind === 'em' ? 'cell' : 'selection-box'), {
......@@ -304,13 +304,13 @@ export namespace VolumeStreaming {
private getBoxFromLoci(loci: StructureElement.Loci | EmptyLoci): Box3D {
if (Loci.isEmpty(loci)) {
return Box3D.empty();
return Box3D();
}
const parent = this.plugin.helpers.substructureParent.get(loci.structure, true);
if (!parent) return Box3D.empty();
if (!parent) return Box3D();
const root = this.getStructureRoot();
if (!root || root.obj?.data !== parent.obj?.data) return Box3D.empty();
if (!root || root.obj?.data !== parent.obj?.data) return Box3D();
const extendedLoci = StructureElement.Loci.extendToWholeResidues(loci);
const box = StructureElement.Loci.getBoundary(extendedLoci).box;
......@@ -341,14 +341,14 @@ export namespace VolumeStreaming {
private updateSelectionBox(loci: StructureElement.Loci | EmptyLoci) {
if (Loci.areEqual(this.lastLoci, loci)) {
this.lastLoci = EmptyLoci;
this.updateSelectionBoxParams(Box3D.empty());
this.updateSelectionBoxParams(Box3D());
return;
}
this.lastLoci = loci;
if (isEmptyLoci(loci)) {
this.updateSelectionBoxParams(Box3D.empty());
this.updateSelectionBoxParams(Box3D());
return;
}
......@@ -373,7 +373,7 @@ export namespace VolumeStreaming {
break;
case 'selection-box': {
if (switchedToSelection) {
box = this.getBoxFromLoci(this.lastLoci) || Box3D.empty();
box = this.getBoxFromLoci(this.lastLoci) || Box3D();
} else {
box = Box3D.create(Vec3.clone(params.entry.params.view.params.bottomLeft), Vec3.clone(params.entry.params.view.params.topRight));
}
......
......@@ -25,7 +25,7 @@ import { eachVolumeLoci } from './util';
import { encodeFloatRGBtoArray } from '../../mol-util/float-packing';
function getBoundingBox(gridDimension: Vec3, transform: Mat4) {
const bbox = Box3D.empty();
const bbox = Box3D.setEmpty(Box3D());
Box3D.add(bbox, gridDimension);
Box3D.transform(bbox, bbox, transform);
return bbox;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment