assign_scalar.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 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 CGAL::Epeck::FT & _cgal,
  17. double & d)
  18. {
  19. // FORCE evaluation of the exact type otherwise interval might be huge.
  20. const 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 CGAL::Epeck::FT & _cgal,
  31. float& d)
  32. {
  33. // FORCE evaluation of the exact type otherwise interval might be huge.
  34. const 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, float(interval.second));
  39. if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
  40. d = next;
  41. } while (d < float(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. }
  61. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  62. const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
  63. CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & d)
  64. {
  65. d = cgal;
  66. }
  67. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  68. const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
  69. double & d)
  70. {
  71. const auto interval = CGAL::to_interval(cgal);
  72. d = interval.first;
  73. do {
  74. const double next = nextafter(d, interval.second);
  75. if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
  76. d = next;
  77. } while (d < interval.second);
  78. }
  79. IGL_INLINE void igl::copyleft::cgal::assign_scalar(
  80. const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
  81. float& d)
  82. {
  83. const auto interval = CGAL::to_interval(cgal);
  84. d = interval.first;
  85. do {
  86. const float next = nextafter(d, float(interval.second));
  87. if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
  88. d = next;
  89. } while (d < float(interval.second));
  90. }