FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
maximum_norm.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #ifndef MATHTOOLS_MAXIMUM_NORM_H
17 #define MATHTOOLS_MAXIMUM_NORM_H
18 
19 #include "norm.h"
20 #include <algorithm>
21 
22 namespace math {
23 namespace internal {
24 
25 template<typename COORD_ITERATOR>
26 auto MaximumFunc_value(COORD_ITERATOR begin, COORD_ITERATOR end) -> decltype(typeHelper(*begin))
27 {
28  return *std::max_element(begin, end);
29 }
30 
31 template<std::size_t N, typename COORD_TYPE>
32 struct MaximumFuncArity
33 {
34  static typename NumTraits<COORD_TYPE>::Real value(const COORD_TYPE* coordPtr)
35  {
36  return std::max(*(coordPtr + N - 1), MaximumFuncArity<N - 1, COORD_TYPE>::value(coordPtr));
37  }
38 };
39 
40 template<typename COORD_TYPE>
41 struct MaximumFuncArity<1, COORD_TYPE>
42 {
43  static typename NumTraits<COORD_TYPE>::Real value(const COORD_TYPE* coordPtr)
44  { return *coordPtr; }
45 };
46 
47 struct MaximumFunc
48 {
49  template<typename COORD_ITERATOR>
50  static auto fromRange(COORD_ITERATOR begin, COORD_ITERATOR end) -> decltype(typeHelper(*begin))
51  { return MaximumFunc_value(begin, end); }
52 
53  template<std::size_t N, typename COORD_TYPE>
54  static typename NumTraits<COORD_TYPE>::Real fromPtr(const COORD_TYPE* coordPtr)
55  { return MaximumFuncArity<N, COORD_TYPE>::value(coordPtr); }
56 };
57 
58 template<> struct NormTraits<internal::MaximumFunc>
59 {
60  typedef ArityNormSpecializationTag NormCategory;
61 };
62 
63 } // namespace internal
64 
73 
74 } // namespace math
75 
76 #endif // MATHTOOLS_MAXIMUM_NORM_H
Computation of norms in K-vector space.
Definition: norm.h:60
Norm< internal::MaximumFunc > MaximumNorm
Provides computation of the maximum norm
Definition: maximum_norm.h:72
Definition: consts.h:18