incircle.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2019 Qingnan Zhou <[email protected]>
  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 "incircle.h"
  9. #include <predicates.h>
  10. namespace igl {
  11. namespace predicates {
  12. using REAL = IGL_PREDICATES_REAL;
  13. #include "IGL_PREDICATES_ASSERT_SCALAR.h"
  14. template<typename Vector2D>
  15. IGL_INLINE Orientation incircle(
  16. const Eigen::MatrixBase<Vector2D>& pa,
  17. const Eigen::MatrixBase<Vector2D>& pb,
  18. const Eigen::MatrixBase<Vector2D>& pc,
  19. const Eigen::MatrixBase<Vector2D>& pd)
  20. {
  21. EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector2D, 2);
  22. IGL_PREDICATES_ASSERT_SCALAR(Vector2D);
  23. using Point = Eigen::Matrix<REAL, 2, 1>;
  24. Point a{pa[0], pa[1]};
  25. Point b{pb[0], pb[1]};
  26. Point c{pc[0], pc[1]};
  27. Point d{pd[0], pd[1]};
  28. const auto r = ::incircle(a.data(), b.data(), c.data(), d.data());
  29. if (r > 0) return Orientation::INSIDE;
  30. else if (r < 0) return Orientation::OUTSIDE;
  31. else return Orientation::COCIRCULAR;
  32. }
  33. }
  34. }
  35. #ifdef IGL_STATIC_LIBRARY
  36. #define IGL_INCIRCLE(Vector) template igl::predicates::Orientation igl::predicates::incircle<Vector>(const Eigen::MatrixBase<Vector>&, const Eigen::MatrixBase<Vector>&, const Eigen::MatrixBase<Vector>&, const Eigen::MatrixBase<Vector>&)
  37. #define IGL_MATRIX(T, R, C) Eigen::Matrix<T, R, C>
  38. IGL_INCIRCLE(IGL_MATRIX(float, 1, 2));
  39. IGL_INCIRCLE(IGL_MATRIX(float, 2, 1));
  40. #ifndef LIBIGL_PREDICATES_USE_FLOAT
  41. IGL_INCIRCLE(IGL_MATRIX(double, 1, 2));
  42. IGL_INCIRCLE(IGL_MATRIX(double, 2, 1));
  43. #endif
  44. #undef IGL_MATRIX
  45. #undef IGL_INCIRCLE
  46. #endif