assign_scalar.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 typename CGAL::Epeck::FT & _cgal,
  31. float& d)
  32. {
  33. // FORCE evaluation of the exact type otherwise interval might be huge.
  34. const typename CGAL::Epeck::FT cgal = _cgal.exact();
  35. const auto interval = CGAL::to_interval(cgal);
  36. d = interval.first;
  37. do {
  38. const float next = nextafter(d, interval.second);
  39. if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
  40. d = next;
  41. } while (d < interval.second);
  42. }
  43. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  44. const double & c,
  45. double & d)
  46. {
  47. d = c;
  48. }
  49. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  50. const float& c,
  51. float& d)
  52. {
  53. d = c;
  54. }
  55. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  56. const float& c,
  57. double& d)
  58. {
  59. d = c;
  60. }