Browse Source

static + capture by reference = bad idea

Alec Jacobson 5 years ago
parent
commit
6f5fadd154
1 changed files with 6 additions and 3 deletions
  1. 6 3
      include/igl/fit_cubic_bezier.cpp

+ 6 - 3
include/igl/fit_cubic_bezier.cpp

@@ -22,9 +22,12 @@ IGL_INLINE void igl::fit_cubic_bezier(
   // Don't attempt to fit curve to single point
   // Don't attempt to fit curve to single point
   if(nPts==1) { return; }
   if(nPts==1) { return; }
   // Avoid using zero tangent
   // Avoid using zero tangent
-  const static auto tangent = [&](const int i,const int dir)->Eigen::RowVectorXd
+  const static auto tangent = [](
+    const Eigen::MatrixXd & d,
+    const int i,const int dir)->Eigen::RowVectorXd
   {
   {
     int j = i;
     int j = i;
+    const int nPts = d.rows();
     Eigen::RowVectorXd t;
     Eigen::RowVectorXd t;
     while(true)
     while(true)
     {
     {
@@ -44,8 +47,8 @@ IGL_INLINE void igl::fit_cubic_bezier(
     }
     }
     return t.normalized();
     return t.normalized();
   };
   };
-  Eigen::RowVectorXd tHat1 = tangent(0,+1);
-  Eigen::RowVectorXd tHat2 = tangent(nPts-1,-1);
+  Eigen::RowVectorXd tHat1 = tangent(d,0,+1);
+  Eigen::RowVectorXd tHat2 = tangent(d,nPts-1,-1);
   // If first and last points are identically equal, then consider closed
   // If first and last points are identically equal, then consider closed
   const bool closed = (d.row(0) - d.row(d.rows()-1)).squaredNorm() == 0;
   const bool closed = (d.row(0) - d.row(d.rows()-1)).squaredNorm() == 0;
   // If closed loop make tangents match
   // If closed loop make tangents match