determinant.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. namespace boost { namespace geometry
  15. {
  16. #ifndef DOXYGEN_NO_DETAIL
  17. namespace detail
  18. {
  19. template <typename ReturnType, typename U, typename V>
  20. class calculate_determinant
  21. {
  22. template <typename T>
  23. static inline ReturnType rt(T const& v)
  24. {
  25. return boost::numeric_cast<ReturnType>(v);
  26. }
  27. public :
  28. static inline ReturnType apply(U const& ux, U const& uy
  29. , V const& vx, V const& vy)
  30. {
  31. return rt(ux) * rt(vy) - rt(uy) * rt(vx);
  32. }
  33. };
  34. template <typename ReturnType, typename U, typename V>
  35. inline ReturnType determinant(U const& ux, U const& uy
  36. , V const& vx, V const& vy)
  37. {
  38. return calculate_determinant
  39. <
  40. ReturnType, U, V
  41. >::apply(ux, uy, vx, vy);
  42. }
  43. template <typename ReturnType, typename U, typename V>
  44. inline ReturnType determinant(U const& u, V const& v)
  45. {
  46. BOOST_CONCEPT_ASSERT( (concept::ConstPoint<U>) );
  47. BOOST_CONCEPT_ASSERT( (concept::ConstPoint<V>) );
  48. return calculate_determinant
  49. <
  50. ReturnType,
  51. typename geometry::coordinate_type<U>::type,
  52. typename geometry::coordinate_type<V>::type
  53. >::apply(get<0>(u), get<1>(u), get<0>(v), get<1>(v));
  54. }
  55. } // namespace detail
  56. #endif // DOXYGEN_NO_DETAIL
  57. }} // namespace boost::geometry
  58. #endif // BOOST_GEOMETRY_ARITHMETIC_DETERMINANT_HPP