diff --git a/src/algorithm/geometry.hpp b/src/algorithm/geometry.hpp
index 1bc72c3004eed5ba7d3bd9dde82ed313fedc8527..f7303a1451a6350b17880e6942e9404eb847f47c 100644
--- a/src/algorithm/geometry.hpp
+++ b/src/algorithm/geometry.hpp
@@ -70,8 +70,18 @@ namespace se3
                                 const bool stopAtFirstCollision = false
                                 );
 
+  /// Compute the distances of all collision pairs
+  ///
+  /// \param ComputeShortest default to true.
+  /// \param data_geom
+  /// \return When ComputeShortest is true, the index of the collision pair which has the shortest distance.
+  ///         When ComputeShortest is false, the number of collision pairs.
+  template <bool ComputeShortest>
   inline std::size_t computeDistances(GeometryData & data_geom);
 
+  /// Compute the forward kinematics, update the goemetry placements and
+  /// calls computeDistances(GeometryData&).
+  template <bool ComputeShortest>
   inline std::size_t computeDistances(const Model & model,
                                       Data & data,
                                       const GeometryModel & model_geom,
diff --git a/src/algorithm/geometry.hxx b/src/algorithm/geometry.hxx
index 9c3ecf595e67fa4cce24a8011219fe116ca87ca5..e32f9864844283240c78d84880ba80db2ba3aa47 100644
--- a/src/algorithm/geometry.hxx
+++ b/src/algorithm/geometry.hxx
@@ -78,7 +78,14 @@ namespace se3
     
     return computeCollisions(data_geom, stopAtFirstCollision);
   }
+
+  // Required to have a default template argument on templated free function
+  inline std::size_t computeDistances(GeometryData & data_geom)
+  {
+    return computeDistances<true>(data_geom);
+  }
   
+  template <bool ComputeShortest>
   inline std::size_t computeDistances(GeometryData & data_geom)
   {
     double min_dist = std::numeric_limits<double>::infinity();
@@ -87,7 +94,7 @@ namespace se3
     {
       data_geom.distance_results[cpt] = data_geom.computeDistance(data_geom.collision_pairs[cpt].first,
                                                                   data_geom.collision_pairs[cpt].second);
-      if (data_geom.distance_results[cpt].distance() < min_dist) {
+      if (ComputeShortest && data_geom.distance_results[cpt].distance() < min_dist) {
         min_index = cpt;
         min_dist = data_geom.distance_results[cpt].distance();
       }
@@ -95,6 +102,18 @@ namespace se3
     return min_index;
   }
   
+  // Required to have a default template argument on templated free function
+  inline std::size_t computeDistances(const Model & model,
+                               Data & data,
+                               const GeometryModel & model_geom,
+                               GeometryData & data_geom,
+                               const Eigen::VectorXd & q
+                               )
+  {
+    return computeDistances<true>(model, data, model_geom, data_geom, q);
+  }
+
+  template <bool ComputeShortest>
   inline std::size_t computeDistances(const Model & model,
                                Data & data,
                                const GeometryModel & model_geom,
@@ -103,7 +122,7 @@ namespace se3
                                )
   {
     updateGeometryPlacements (model, data, model_geom, data_geom, q);
-    return computeDistances(data_geom);
+    return computeDistances<ComputeShortest>(data_geom);
   }
 
   /// Given p1..3 being either "min" or "max", return one of the corners of the