MaxNorm.h
Go to the documentation of this file.
1#ifndef GfxTL__MAXNORM_HEADER__
2#define GfxTL__MAXNORM_HEADER__
3#include <GfxTL/MathHelper.h>
6
7namespace GfxTL
8{
9 template <class VectorKernelT>
10 struct MaxNorm : public VectorKernelT
11 {
12 template <class ScalarAT, class ScalarBT>
17
18 template <class PointAT, class PointBT>
21 Distance(const PointAT& p, const PointBT& v) const
22 {
25 DistType;
26 DistType di, max = Math<DistType>::Abs(p[0] - v[0]);
27 for (size_t i = 1; i < m_dim; ++i)
28 {
29 di = Math<DistType>::Abs(p[i] - v[i]);
30 if (di > max)
31 {
32 max = di;
33 }
34 }
35 return max;
36 }
37
38 template <class PointAT, class PointBT>
39 typename DistanceType<typename ScalarTypeDeferer<PointAT>::ScalarType,
41 SqrDistance(const PointAT& p, const PointBT& v) const
42 {
45 DistType;
46 DistType di, max = Math<DistType>::Abs(p[0] - v[0]);
47 for (size_t i = 1; i < m_dim; ++i)
48 {
49 di = Math<DistType>::Abs(p[i] - v[i]);
50 if (di > max)
51 {
52 max = di;
53 }
54 }
55 return max;
56 }
57
58 template <class ScalarT>
59 ScalarT
60 RootOfDistance(ScalarT sqrDistance) const
61 {
62 return sqrDistance;
63 }
64
65 template <class DistScalarT, class DiffScalarT>
66 DistScalarT
67 IncrementalBoxSqrDistance(DistScalarT boxDist,
68 DiffScalarT boxDiff,
69 DiffScalarT cutDiff) const
70 {
71 return std::max(boxDist, (DistScalarT)Math<DiffScalarT>::Abs(cutDiff));
72 }
73
74 template <class PointAT, class PointBT>
75 typename DistanceType<typename ScalarTypeDeferer<PointAT>::ScalarType,
77 BoxSqrDistance(const PointAT& a, const PointBT& min, const PointBT& max) const
78 {
80 typename ScalarTypeDeferer<PointBT>::ScalarType>::Type sqrDist =
81 0,
82 t;
83 for (unsigned int i = 0; i < m_dim; ++i)
84 {
85 if (a[i] < min[i])
86 {
87 t = min[i] - a[i];
88 if (t > sqrDist)
89 {
90 sqrDist = t;
91 }
92 }
93 else if (a[i] > max[i])
94 {
95 t = a[i] - max[i];
96 if (t > sqrDist)
97 {
98 sqrDist = t;
99 }
100 }
101 }
102 return sqrDist;
103 }
104 };
105}; // namespace GfxTL
106
107#endif
static ScalarT Abs(ScalarT s)
Definition MathHelper.h:15
Definition AABox.h:10
MatrixXX< C, R, T > min(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition MatrixXX.h:616
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition MatrixXX.h:630
ScalarTypeConversion< ScalarAT, ScalarBT >::DifferenceType Type
Definition MaxNorm.h:15
DistScalarT IncrementalBoxSqrDistance(DistScalarT boxDist, DiffScalarT boxDiff, DiffScalarT cutDiff) const
Definition MaxNorm.h:67
DistanceType< typenameScalarTypeDeferer< PointAT >::ScalarType, typenameScalarTypeDeferer< PointBT >::ScalarType >::Type Distance(const PointAT &p, const PointBT &v) const
Definition MaxNorm.h:21
ScalarT RootOfDistance(ScalarT sqrDistance) const
Definition MaxNorm.h:60
DistanceType< typenameScalarTypeDeferer< PointAT >::ScalarType, typenameScalarTypeDeferer< PointBT >::ScalarType >::Type SqrDistance(const PointAT &p, const PointBT &v) const
Definition MaxNorm.h:41
DistanceType< typenameScalarTypeDeferer< PointAT >::ScalarType, typenameScalarTypeDeferer< PointBT >::ScalarType >::Type BoxSqrDistance(const PointAT &a, const PointBT &min, const PointBT &max) const
Definition MaxNorm.h:77
PointT::value_type ScalarType