Code-Eli  0.3.6
trapezoid.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_mutil_quad_trapezoid_hpp
14 #define eli_mutil_quad_trapezoid_hpp
15 
16 #include "eli/code_eli.hpp"
17 
18 namespace eli
19 {
20  namespace mutil
21  {
22  namespace quad
23  {
24  template<typename data__>
25  class trapezoid
26  {
27  public:
28  trapezoid() {};
30  ~trapezoid() {};
31 
32  trapezoid<data__> & operator=(const trapezoid<data__> &) {return *this;};
33 
44  template<typename yit__>
45  data__ operator()(const data__ &dx, yit__ yb, yit__ ye) const
46  {
47  data__ rtnval(-(*yb)/2);
48  yit__ y(yb);
49 
50  for (; y!=ye; ++y)
51  rtnval+=(*y);
52 
53  --y;
54  rtnval-=(*y)/2;
55  rtnval*=dx;
56 
57  return rtnval;
58  }
59 
71  template<typename xit__, typename yit__>
72  data__ operator()(xit__ x, yit__ yb, yit__ ye) const
73  {
74  xit__ xp(x);
75  yit__ y(yb), yp(yb);
76  data__ rtnval(0);
77 
78  for (++x, ++y; y!=ye; ++x, ++xp, ++y, ++yp)
79  rtnval+=((*x)-(*xp))*((*y)+(*yp))/2;
80 
81  return rtnval;
82  }
83  };
84  }
85  }
86 }
87 #endif
Definition: math.hpp:20
trapezoid< data__ > & operator=(const trapezoid< data__ > &)
Definition: trapezoid.hpp:32
trapezoid()
Definition: trapezoid.hpp:28
Definition: trapezoid.hpp:25
data__ operator()(const data__ &dx, yit__ yb, yit__ ye) const
Definition: trapezoid.hpp:45
data__ operator()(xit__ x, yit__ yb, yit__ ye) const
Definition: trapezoid.hpp:72
trapezoid(const trapezoid< data__ > &)
Definition: trapezoid.hpp:29
~trapezoid()
Definition: trapezoid.hpp:30