box_surface_area.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include "box_surface_area.h"
  2. template <typename DerivedCorner>
  3. IGL_INLINE typename DerivedCorner::Scalar igl::box_surface_area(
  4. const Eigen::MatrixBase<DerivedCorner> & min_corner,
  5. const Eigen::MatrixBase<DerivedCorner> & max_corner)
  6. {
  7. using Scalar = typename DerivedCorner::Scalar;
  8. const auto dimensions = (max_corner - min_corner).eval();
  9. const auto num_dimensions = dimensions.size();
  10. Scalar surface_area = 0;
  11. for (int i = 0; i < num_dimensions; ++i) {
  12. for (int j = i + 1; j < num_dimensions; ++j) {
  13. surface_area += 2 * dimensions[i] * dimensions[j];
  14. }
  15. }
  16. return surface_area;
  17. }
  18. template <typename Scalar, int AmbientDim>
  19. IGL_INLINE Scalar igl::box_surface_area(
  20. const Eigen::AlignedBox<Scalar,AmbientDim> & box)
  21. {
  22. return igl::box_surface_area(box.min(),box.max());
  23. }
  24. #ifdef IGL_STATIC_LIBRARY
  25. // Explicit template instantiation
  26. // generated by autoexplicit.sh
  27. template double igl::box_surface_area<double, 2>(Eigen::AlignedBox<double, 2> const&);
  28. template double igl::box_surface_area<double, 3>(Eigen::AlignedBox<double, 3> const&);
  29. #endif