PROBI
1.0
Main Page
Classes
Files
File List
All
Classes
Functions
CenterOfGravity.hpp
1
#ifndef CENTERGRAVITY_H
2
#define CENTERGRAVITY_H
3
4
#include <functional>
5
#include <algorithm>
6
#include <limits>
7
8
#include "Point.hpp"
9
#include "Metric.hpp"
10
14
class
CenterOfGravity
15
{
16
public
:
17
CenterOfGravity
(std::function<
Metric<Point>
*() > createMetric);
18
25
template
<
typename
ForwardIterator>
26
Point
cog
(ForwardIterator begin, ForwardIterator end);
27
28
private
:
29
Metric<Point>
* metric;
30
};
31
32
template
<
typename
ForwardIterator>
33
Point
CenterOfGravity::cog
(ForwardIterator begin, ForwardIterator end)
34
{
35
Point
cog
= *begin;
36
++begin;
37
double
n = 1;
38
for
(; begin != end; ++begin)
39
{
40
cog += *begin;
41
++n;
42
;
43
}
44
cog = (1.0 / n) * cog;
45
return
cog
;
46
}
47
48
#endif
probi-source
CenterOfGravity.hpp
Generated on Wed Aug 28 2013 20:04:15 for PROBI by
1.8.4