determinant.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  3. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_ARITHMETIC_DETERMINANT_HPP
  9. #define BOOST_GEOMETRY_ARITHMETIC_DETERMINANT_HPP
  10. #include <cstddef>
  11. #include <boost/geometry/core/access.hpp>
  12. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  13. #include <boost/geometry/util/select_coordinate_type.hpp>
  14. #include <boost/numeric/conversion/cast.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. #ifndef DOXYGEN_NO_DETAIL
  18. namespace detail
  19. {
  20. template <typename ReturnType, typename U, typename V>
  21. class calculate_determinant
  22. {
  23. template <typename T>
  24. static inline ReturnType rt(T const& v)
  25. {
  26. return boost::numeric_cast<ReturnType>(v);
  27. }
  28. public :
  29. static inline ReturnType apply(U const& ux, U const& uy
  30. , V const& vx, V const& vy)
  31. {
  32. return rt(ux) * rt(vy) - rt(uy) * rt(vx);
  33. }
  34. };
  35. template <typename ReturnType, typename U, typename V>
  36. inline ReturnType determinant(U const& ux, U const& uy
  37. , V const& vx, V const& vy)
  38. {
  39. return calculate_determinant
  40. <
  41. ReturnType, U, V
  42. >::apply(ux, uy, vx, vy);
  43. }
  44. template <typename ReturnType, typename U, typename V>
  45. inline ReturnType determinant(U const& u, V const& v)
  46. {
  47. BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<U>) );
  48. BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<V>) );
  49. return calculate_determinant
  50. <
  51. ReturnType,
  52. typename geometry::coordinate_type<U>::type,
  53. typename geometry::coordinate_type<V>::type
  54. >::apply(get<0>(u), get<1>(u), get<0>(v), get<1>(v));
  55. }
  56. } // namespace detail
  57. #endif // DOXYGEN_NO_DETAIL
  58. }} // namespace boost::geometry
  59. #endif // BOOST_GEOMETRY_ARITHMETIC_DETERMINANT_HPP