colon.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef IGL_COLON_H
  2. #define IGL_COLON_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Dense>
  5. namespace igl
  6. {
  7. // Note:
  8. // This should be potentially replaced with eigen's LinSpaced() function
  9. // Colon operator like matlab's colon operator. Enumerats values between low
  10. // and hi with step step.
  11. // Templates:
  12. // L should be a eigen matrix primitive type like int or double
  13. // S should be a eigen matrix primitive type like int or double
  14. // H should be a eigen matrix primitive type like int or double
  15. // T should be a eigen matrix primitive type like int or double
  16. // Inputs:
  17. // low starting value if step is valid then this is *always* the first
  18. // element of I
  19. // step step difference between sequential elements returned in I,
  20. // remember this will be cast to template T at compile time. If low<hi
  21. // then step must be positive. If low>hi then step must be negative.
  22. // Otherwise I will be set to empty.
  23. // hi ending value, if (hi-low)%step is zero then this will be the last
  24. // element in I. If step is positive there will be no elements greater
  25. // than hi, vice versa if hi<low
  26. // Output:
  27. // I list of values from low to hi with step size step
  28. template <typename L,typename S,typename H,typename T>
  29. IGL_INLINE void colon(
  30. const L low,
  31. const S step,
  32. const H hi,
  33. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  34. // Same as above but step == (T)1
  35. template <typename L,typename H,typename T>
  36. IGL_INLINE void colon(
  37. const L low,
  38. const H hi,
  39. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  40. // Return output rather than set in reference
  41. template <typename T,typename L,typename H>
  42. IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> colon(
  43. const L low,
  44. const H hi);
  45. }
  46. #ifdef IGL_HEADER_ONLY
  47. # include "colon.cpp"
  48. #endif
  49. #endif