From 9f99a2c45319ac9d38ce6413f0c58ec5e7e86b01 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Fri, 1 Mar 2019 21:47:37 +0100
Subject: [PATCH] mol-math: fixed makeRotation edge case

---
 src/mol-math/linear-algebra/3d/vec3.ts | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts
index 0be0f033d..c0437fd57 100644
--- a/src/mol-math/linear-algebra/3d/vec3.ts
+++ b/src/mol-math/linear-algebra/3d/vec3.ts
@@ -452,9 +452,15 @@ namespace Vec3 {
     }
 
     const rotTemp = zero();
+    const flipMatrix = Mat4.fromScaling(Mat4.zero(), create(-1, -1, -1))
     export function makeRotation(mat: Mat4, a: Vec3, b: Vec3): Mat4 {
         const by = angle(a, b);
         if (Math.abs(by) < 0.0001) return Mat4.setIdentity(mat);
+        if (Math.abs(by - Math.PI) < EPSILON.Value) {
+            // here, axis can be [0,0,0] but the rotation is a simple flip
+            Mat4.copy(mat, flipMatrix);
+            return mat;
+        }
         const axis = cross(rotTemp, a, b);
         return Mat4.fromRotation(mat, by, axis);
     }
-- 
GitLab