Эх сурвалжийг харах

assign routines for mpqclass exact type

Former-commit-id: 1950ee9c09b3213ba78cc8d6f052937b1989ebd3
Alec Jacobson 7 жил өмнө
parent
commit
af2780924c

+ 35 - 0
include/igl/copyleft/cgal/assign_scalar.cpp

@@ -97,3 +97,38 @@ IGL_INLINE void igl::copyleft::cgal::assign_scalar(
       d = next;
   } while (d < float(interval.second));
 }
+
+
+IGL_INLINE void igl::copyleft::cgal::assign_scalar(
+  const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
+  CGAL::Simple_cartesian<mpq_class>::FT & d)
+{
+  d = cgal;
+}
+
+IGL_INLINE void igl::copyleft::cgal::assign_scalar(
+  const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
+  double & d)
+{
+  const auto interval = CGAL::to_interval(cgal);
+  d = interval.first;
+  do {
+      const double next = nextafter(d, interval.second);
+      if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
+      d = next;
+  } while (d < interval.second);
+}
+
+IGL_INLINE void igl::copyleft::cgal::assign_scalar(
+  const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
+  float& d)
+{
+  const auto interval = CGAL::to_interval(cgal);
+  d = interval.first;
+  do {
+      const float next = nextafter(d, float(interval.second));
+      if (CGAL::abs(cgal-d) < CGAL::abs(cgal-next)) break;
+      d = next;
+  } while (d < float(interval.second));
+}
+

+ 14 - 0
include/igl/copyleft/cgal/assign_scalar.h

@@ -10,6 +10,8 @@
 #include "../../igl_inline.h"
 #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
 #include <CGAL/Exact_predicates_exact_constructions_kernel_with_sqrt.h>
+#include <CGAL/gmpxx.h>
+
 namespace igl
 {
   namespace copyleft
@@ -38,6 +40,7 @@ namespace igl
       IGL_INLINE void assign_scalar(
         const float& c,
         double& d);
+
       IGL_INLINE void assign_scalar(
         const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
         CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & d);
@@ -47,6 +50,17 @@ namespace igl
       IGL_INLINE void assign_scalar(
         const CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt::FT & cgal,
         float& d);
+
+      IGL_INLINE void assign_scalar(
+        const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
+        CGAL::Simple_cartesian<mpq_class>::FT & d);
+      IGL_INLINE void assign_scalar(
+        const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
+        double & d);
+      IGL_INLINE void assign_scalar(
+        const CGAL::Simple_cartesian<mpq_class>::FT & cgal,
+        float& d);
+
     }
   }
 }