From 88dc9b9976ce3b6637b0651e27af92b656875173 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Thu, 4 Apr 2019 11:03:13 -0700 Subject: [PATCH] Sphere3D.addVec3 --- src/mol-geo/geometry/lines/lines.ts | 4 ++-- src/mol-math/geometry/primitives/sphere3d.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/mol-geo/geometry/lines/lines.ts b/src/mol-geo/geometry/lines/lines.ts index 4ed81dd85..13dea3213 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 c385ffad4..3bc41681d 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 -- GitLab