Updraft  1.0
Open source glider flight visualisation tool.
linearfunc.h
Go to the documentation of this file.
00001 #ifndef UPDRAFT_SRC_LIBRARIES_UTIL_LINEARFUNC_H_
00002 #define UPDRAFT_SRC_LIBRARIES_UTIL_LINEARFUNC_H_
00003 
00004 #include <QColor>
00005 
00006 #include "util.h"
00007 
00008 namespace Updraft {
00009 namespace Util {
00010 
00013 class UTIL_EXPORT LinearFunc {
00014  public:
00015   LinearFunc()
00016     : a(0), b(0) {}
00017 
00018   LinearFunc(qreal slope, qreal yIntercept)
00019     : a(slope), b(yIntercept) {}
00020 
00023   LinearFunc(qreal x0, qreal y0, qreal x1, qreal y1) {
00024     set(x0, y0, x1, y1);
00025   }
00026 
00027   void set(qreal slope, qreal yIntercept) {
00028     this->a = slope;
00029     this->b = yIntercept;
00030   }
00031 
00034   void set(qreal x0, qreal y0, qreal x1, qreal y1) {
00035     a = (y1 - y0) / (x1 - x0);
00036     b = y0 - a * x0;
00037   }
00038 
00041   LinearFunc compose(const LinearFunc& other) const {
00042     return LinearFunc(a * other.a, a * other.b + b);
00043   }
00044 
00046   qreal get(qreal x) const {
00047     return a * x + b;
00048   }
00049 
00051   qreal inverse(qreal y) const {
00052     return (y - b) / a;
00053   }
00054 
00055  protected:
00056   qreal a, b;
00057 };
00058 
00059 }  // End namespace Util
00060 }  // End namespace Updraft
00061 
00062 #endif  // UPDRAFT_SRC_LIBRARIES_UTIL_LINEARFUNC_H_
00063 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines