linear.h revision 981b809bc6ed10a21e89444d9447e5475801874f
/*
* linear.h - Linear fragment function class
*
* Authors:
* Nathan Hurst <njh@mail.csse.monash.edu.au>
* Michael Sloan <mgsloan@gmail.com>
*
* Copyright (C) 2006-2007 authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*/
#ifndef SEEN_LINEAR_H
#define SEEN_LINEAR_H
#include "isnan.h"
#include "interval.h"
inline double lerp(double t, double a, double b) { return a*(1-t) + b*t; }
Hat () {}
Hat(double d) :d(d) {}
operator double() const { return d; }
double d;
};
Tri () {}
Tri(double d) :d(d) {}
operator double() const { return d; }
double d;
};
double a[2];
Linear() {}
a[0] = double(h) - double(t)/2;
a[1] = double(h) + double(t)/2;
}
a[0] = double(h);
a[1] = double(h);
}
double operator[](const int i) const {
assert(i >= 0);
assert(i < 2);
return a[i];
}
double& operator[](const int i) {
assert(i >= 0);
assert(i < 2);
return a[i];
}
//IMPL: FragmentConcept
typedef double output_type;
inline bool isZero() const { return a[0] == 0 && a[1] == 0; }
inline double at0() const { return a[0]; }
inline double at1() const { return a[1]; }
//defined in sbasis.h
return a[1] - a[0];
}
return (a[1] + a[0])/2;
}
};
//IMPL: AddableConcept
}
}
a[0] += b[0]; a[1] += b[1];
return a;
}
a[0] -= b[0]; a[1] -= b[1];
return a;
}
//IMPL: OffsetableConcept
return Linear(a[0] + b, a[1] + b);
}
return Linear(a[0] - b, a[1] - b);
}
a[0] += b; a[1] += b;
return a;
}
a[0] -= b; a[1] -= b;
return a;
}
//IMPL: boost::EqualityComparableConcept
return a[0] == b[0] && a[1] == b[1];
}
return a[0] != b[0] || a[1] != b[1];
}
//IMPL: ScalableConcept
return Linear(-a[0], -a[1]);
}
return Linear(a[0]*b, a[1]*b);
}
return Linear(a[0]/b, a[1]/b);
}
a[0] *= b; a[1] *= b;
return a;
}
a[0] /= b; a[1] /= b;
return a;
}
};
#endif //SEEN_LINEAR_H