From 85103f7027eda6d183203f834b8d4c59959db8e5 Mon Sep 17 00:00:00 2001
From: Daniel Chappuis <chappuis.daniel@gmail.com>
Date: Fri, 2 Oct 2020 21:26:14 +0200
Subject: [PATCH] Small optimizations

---
 .../collision/shapes/BoxShape.h               | 18 +++++++--------
 .../collision/shapes/ConvexPolyhedronShape.h  | 23 +++++++++++++++++++
 .../shapes/ConvexPolyhedronShape.cpp          | 23 -------------------
 3 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/include/reactphysics3d/collision/shapes/BoxShape.h b/include/reactphysics3d/collision/shapes/BoxShape.h
index c54def68..bbf08d0e 100644
--- a/include/reactphysics3d/collision/shapes/BoxShape.h
+++ b/include/reactphysics3d/collision/shapes/BoxShape.h
@@ -217,17 +217,15 @@ RP3D_FORCE_INLINE HalfEdgeStructure::Vertex BoxShape::getVertex(uint vertexIndex
 RP3D_FORCE_INLINE Vector3 BoxShape::getVertexPosition(uint vertexIndex) const {
     assert(vertexIndex < getNbVertices());
 
-    Vector3 extent = getHalfExtents();
-
     switch(vertexIndex) {
-        case 0: return Vector3(-extent.x, -extent.y, extent.z);
-        case 1: return Vector3(extent.x, -extent.y, extent.z);
-        case 2: return Vector3(extent.x, extent.y, extent.z);
-        case 3: return Vector3(-extent.x, extent.y, extent.z);
-        case 4: return Vector3(-extent.x, -extent.y, -extent.z);
-        case 5: return Vector3(extent.x, -extent.y, -extent.z);
-        case 6: return Vector3(extent.x, extent.y, -extent.z);
-        case 7: return Vector3(-extent.x, extent.y, -extent.z);
+        case 0: return Vector3(-mHalfExtents.x, -mHalfExtents.y, mHalfExtents.z);
+        case 1: return Vector3(mHalfExtents.x, -mHalfExtents.y, mHalfExtents.z);
+        case 2: return Vector3(mHalfExtents.x, mHalfExtents.y, mHalfExtents.z);
+        case 3: return Vector3(-mHalfExtents.x, mHalfExtents.y, mHalfExtents.z);
+        case 4: return Vector3(-mHalfExtents.x, -mHalfExtents.y, -mHalfExtents.z);
+        case 5: return Vector3(mHalfExtents.x, -mHalfExtents.y, -mHalfExtents.z);
+        case 6: return Vector3(mHalfExtents.x, mHalfExtents.y, -mHalfExtents.z);
+        case 7: return Vector3(-mHalfExtents.x, mHalfExtents.y, -mHalfExtents.z);
     }
 
     assert(false);
diff --git a/include/reactphysics3d/collision/shapes/ConvexPolyhedronShape.h b/include/reactphysics3d/collision/shapes/ConvexPolyhedronShape.h
index d723d28a..68dce6be 100644
--- a/include/reactphysics3d/collision/shapes/ConvexPolyhedronShape.h
+++ b/include/reactphysics3d/collision/shapes/ConvexPolyhedronShape.h
@@ -99,6 +99,29 @@ RP3D_FORCE_INLINE bool ConvexPolyhedronShape::isPolyhedron() const {
 }
 
 
+// Find and return the index of the polyhedron face with the most anti-parallel face
+// normal given a direction vector. This is used to find the incident face on
+// a polyhedron of a given reference face of another polyhedron
+RP3D_FORCE_INLINE uint ConvexPolyhedronShape::findMostAntiParallelFace(const Vector3& direction) const {
+
+    decimal minDotProduct = DECIMAL_LARGEST;
+    uint mostAntiParallelFace = 0;
+
+    // For each face of the polyhedron
+    const uint32 nbFaces = getNbFaces();
+    for (uint32 i=0; i < nbFaces; i++) {
+
+        // Get the face normal
+        const decimal dotProduct = getFaceNormal(i).dot(direction);
+        if (dotProduct < minDotProduct) {
+            minDotProduct = dotProduct;
+            mostAntiParallelFace = i;
+        }
+    }
+
+    return mostAntiParallelFace;
+}
+
 }
 
 #endif
diff --git a/src/collision/shapes/ConvexPolyhedronShape.cpp b/src/collision/shapes/ConvexPolyhedronShape.cpp
index 9ec5f1a8..28c81c20 100644
--- a/src/collision/shapes/ConvexPolyhedronShape.cpp
+++ b/src/collision/shapes/ConvexPolyhedronShape.cpp
@@ -35,26 +35,3 @@ ConvexPolyhedronShape::ConvexPolyhedronShape(CollisionShapeName name, MemoryAllo
             : ConvexShape(name, CollisionShapeType::CONVEX_POLYHEDRON, allocator) {
 
 }
-
-// Find and return the index of the polyhedron face with the most anti-parallel face
-// normal given a direction vector. This is used to find the incident face on
-// a polyhedron of a given reference face of another polyhedron
-uint ConvexPolyhedronShape::findMostAntiParallelFace(const Vector3& direction) const {
-
-    decimal minDotProduct = DECIMAL_LARGEST;
-    uint mostAntiParallelFace = 0;
-
-    // For each face of the polyhedron
-    uint32 nbFaces = getNbFaces();
-    for (uint32 i=0; i < nbFaces; i++) {
-
-        // Get the face normal
-        const decimal dotProduct = getFaceNormal(i).dot(direction);
-        if (dotProduct < minDotProduct) {
-            minDotProduct = dotProduct;
-            mostAntiParallelFace = i;
-        }
-    }
-
-    return mostAntiParallelFace;
-}