orient2D.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 "orient2D.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::orient2D(
  13. const Scalar pa[2],
  14. const Scalar pb[2],
  15. const Scalar pc[2])
  16. {
  17. typedef CGAL::Exact_predicates_exact_constructions_kernel Epeck;
  18. typedef CGAL::Exact_predicates_inexact_constructions_kernel Epick;
  19. typedef typename std::conditional<std::is_same<Scalar, Epeck::FT>::value,
  20. Epeck, Epick>::type Kernel;
  21. switch(CGAL::orientation(
  22. typename Kernel::Point_2(pa[0], pa[1]),
  23. typename Kernel::Point_2(pb[0], pb[1]),
  24. typename Kernel::Point_2(pc[0], pc[1]))) {
  25. case CGAL::LEFT_TURN:
  26. return 1;
  27. case CGAL::RIGHT_TURN:
  28. return -1;
  29. case CGAL::COLLINEAR:
  30. return 0;
  31. default:
  32. throw "Invalid orientation";
  33. }
  34. }