insphere.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Qingan Zhou <qnzhou@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 "insphere.h"
  9. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
  10. #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
  11. template<typename Scalar>
  12. IGL_INLINE short igl::copyleft::cgal::insphere(
  13. const Scalar pa[3],
  14. const Scalar pb[3],
  15. const Scalar pc[3],
  16. const Scalar pd[3],
  17. const Scalar pe[3])
  18. {
  19. typedef CGAL::Exact_predicates_exact_constructions_kernel Epeck;
  20. typedef CGAL::Exact_predicates_inexact_constructions_kernel Epick;
  21. typedef typename std::conditional<std::is_same<Scalar, Epeck::FT>::value,
  22. Epeck, Epick>::type Kernel;
  23. switch(CGAL::side_of_oriented_sphere(
  24. typename Kernel::Point_3(pa[0], pa[1], pa[2]),
  25. typename Kernel::Point_3(pb[0], pb[1], pb[2]),
  26. typename Kernel::Point_3(pc[0], pc[1], pc[2]),
  27. typename Kernel::Point_3(pd[0], pd[1], pd[2]),
  28. typename Kernel::Point_3(pe[0], pe[1], pe[2]))) {
  29. case CGAL::ON_POSITIVE_SIDE:
  30. return 1;
  31. case CGAL::ON_NEGATIVE_SIDE:
  32. return -1;
  33. case CGAL::ON_ORIENTED_BOUNDARY:
  34. return 0;
  35. default:
  36. throw "Invalid incircle result";
  37. }
  38. }