colon.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_COLON_H
  9. #define IGL_COLON_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl
  13. {
  14. // Note:
  15. // This should be potentially replaced with eigen's LinSpaced() function
  16. // Colon operator like matlab's colon operator. Enumerats values between low
  17. // and hi with step step.
  18. // Templates:
  19. // L should be a eigen matrix primitive type like int or double
  20. // S should be a eigen matrix primitive type like int or double
  21. // H should be a eigen matrix primitive type like int or double
  22. // T should be a eigen matrix primitive type like int or double
  23. // Inputs:
  24. // low starting value if step is valid then this is *always* the first
  25. // element of I
  26. // step step difference between sequential elements returned in I,
  27. // remember this will be cast to template T at compile time. If low<hi
  28. // then step must be positive. If low>hi then step must be negative.
  29. // Otherwise I will be set to empty.
  30. // hi ending value, if (hi-low)%step is zero then this will be the last
  31. // element in I. If step is positive there will be no elements greater
  32. // than hi, vice versa if hi<low
  33. // Output:
  34. // I list of values from low to hi with step size step
  35. template <typename L,typename S,typename H,typename T>
  36. IGL_INLINE void colon(
  37. const L low,
  38. const S step,
  39. const H hi,
  40. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  41. // Same as above but step == (T)1
  42. template <typename L,typename H,typename T>
  43. IGL_INLINE void colon(
  44. const L low,
  45. const H hi,
  46. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  47. // Return output rather than set in reference
  48. template <typename T,typename L,typename H>
  49. IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> colon(
  50. const L low,
  51. const H hi);
  52. }
  53. #ifndef IGL_STATIC_LIBRARY
  54. # include "colon.cpp"
  55. #endif
  56. #endif