ProteoWizard
Parabola.hpp
Go to the documentation of this file.
1 //
2 // $Id: Parabola.hpp 1195 2009-08-14 22:12:04Z chambm $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2006 Louis Warschaw Prostate Cancer Center
8 // Cedars Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
24 #ifndef _PARABOLA_HPP_
25 #define _PARABOLA_HPP_
26 
27 
29 #include <vector>
30 #include <iosfwd>
31 
32 
33 namespace pwiz {
34 namespace math {
35 
36 
38 {
39  public:
40 
41  // construct by giving 3 coefficients
42  Parabola(double a=0, double b=0, double c=0);
43  Parabola(std::vector<double> a);
44 
45  // construct by giving 3 or more sample points
46  Parabola(const std::vector< std::pair<double,double> >& samples);
47 
48  // construct by weighted least squares
49  Parabola(const std::vector< std::pair<double,double> >& samples,
50  const std::vector<double>& weights);
51 
52  std::vector<double>& coefficients() {return a_;}
53  const std::vector<double>& coefficients() const {return a_;}
54 
55  double operator()(double x) const {return a_[0]*x*x + a_[1]*x + a_[2];}
56  double center() const {return -a_[1]/(2*a_[0]);}
57 
58  private:
59  std::vector<double> a_;
60 };
61 
62 
63 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const Parabola& p);
64 
65 
66 } // namespace math
67 } // namespace pwiz
68 
69 
70 #endif // _PARABOLA_HPP_
71