assign_scalar.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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. #include "assign_scalar.h"
  9. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  10. const typename CGAL::Epeck::FT & cgal,
  11. CGAL::Epeck::FT & d)
  12. {
  13. d = cgal;
  14. }
  15. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  16. const typename CGAL::Epeck::FT & _cgal,
  17. double & d)
  18. {
  19. // FORCE evaluation of the exact type otherwise interval might be huge.
  20. const typename CGAL::Epeck::FT cgal = _cgal.exact();
  21. const auto interval = CGAL::to_interval(cgal);
  22. d = interval.first;
  23. do {
  24. const double next = nextafter(d, interval.second);
  25. if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
  26. d = next;
  27. } while (d < interval.second);
  28. }
  29. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  30. const double & c,
  31. double & d)
  32. {
  33. d = c;
  34. }