diff --git a/src/mol-geo/geometry/lines/lines.ts b/src/mol-geo/geometry/lines/lines.ts index 4ed81dd8582ae1b79225869f9c106b057c2a30fd..13dea32130f80e3d0c400373eca9feb74005d054 100644 --- a/src/mol-geo/geometry/lines/lines.ts +++ b/src/mol-geo/geometry/lines/lines.ts @@ -180,7 +180,7 @@ function getBoundingSphere(lineStart: Float32Array, lineEnd: Float32Array, lineC const start = calculateBoundingSphere(lineStart, lineCount * 4, transform, transformCount) const end = calculateBoundingSphere(lineEnd, lineCount * 4, transform, transformCount) return { - boundingSphere: Sphere3D.addSphere(start.boundingSphere, end.boundingSphere), - invariantBoundingSphere: Sphere3D.addSphere(start.invariantBoundingSphere, end.invariantBoundingSphere) + boundingSphere: Sphere3D.expandBySphere(start.boundingSphere, end.boundingSphere), + invariantBoundingSphere: Sphere3D.expandBySphere(start.invariantBoundingSphere, end.invariantBoundingSphere) } } \ No newline at end of file diff --git a/src/mol-math/geometry/primitives/sphere3d.ts b/src/mol-math/geometry/primitives/sphere3d.ts index c385ffad43297b3194e892d4c8c87de6d9ff6827..3bc41681d9375a53cf3725a212a9b29d8393fe33 100644 --- a/src/mol-math/geometry/primitives/sphere3d.ts +++ b/src/mol-math/geometry/primitives/sphere3d.ts @@ -83,12 +83,25 @@ namespace Sphere3D { return out } - export function addSphere(out: Sphere3D, sphere: Sphere3D) { + const tmpAddVec3 = Vec3.zero() + export function addVec3(out: Sphere3D, s: Sphere3D, v: Vec3) { + const d = Vec3.distance(s.center, v) + if (d < s.radius) return Sphere3D.copy(out, s) + Vec3.sub(tmpAddVec3, s.center, v) + Vec3.sub(tmpAddVec3, s.center, tmpAddVec3) + Vec3.setMagnitude(tmpAddVec3, tmpAddVec3, s.radius) + Vec3.scale(out.center, Vec3.add(tmpAddVec3, tmpAddVec3, v), 0.5) + out.radius = Vec3.distance(out.center, v) + return out + } + + /** Expand sphere radius by another sphere */ + export function expandBySphere(out: Sphere3D, sphere: Sphere3D) { out.radius = Math.max(out.radius, Vec3.distance(out.center, sphere.center) + sphere.radius) return out } - /** Expand sphere by delta */ + /** Expand sphere radius by delta */ export function expand(out: Sphere3D, sphere: Sphere3D, delta: number): Sphere3D { out.radius = sphere.radius + delta return out