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