41 inline double lerp(
double t,
double a,
double b) {
return a*(1-t) + b*t; }
48 Hat(
double d) :d(d) {}
49 operator double()
const {
return d; }
56 Tri(
double d) :d(d) {}
57 operator double()
const {
return d; }
65 Linear(
double aa,
double b) {a[0] = aa; a[1] = b;}
67 a[0] = double(h) - double(t)/2;
68 a[1] = double(h) + double(t)/2;
76 double operator[](
const int i)
const {
81 double& operator[](
const int i) {
88 typedef double output_type;
89 inline bool isZero()
const {
return a[0] == 0 && a[1] == 0; }
90 inline bool isConstant()
const {
return a[0] == a[1]; }
91 inline bool isFinite()
const {
return is_finite(a[0]) && is_finite(a[1]); }
93 inline double at0()
const {
return a[0]; }
94 inline double at1()
const {
return a[1]; }
96 inline double valueAt(
double t)
const {
return lerp(t, a[0], a[1]); }
97 inline double operator()(
double t)
const {
return valueAt(t); }
100 inline SBasis toSBasis()
const;
103 inline Interval bounds_fast()
const {
return bounds_exact(); }
104 inline Interval bounds_local(
double u,
double v)
const {
return Interval(valueAt(u), valueAt(v)); }
106 operator Tri()
const {
109 operator Hat()
const {
110 return (a[1] + a[0])/2;
117 inline Linear operator+(Linear
const & a, Linear
const & b) {
118 return Linear(a[0] + b[0], a[1] + b[1]);
120 inline Linear operator-(Linear
const & a, Linear
const & b) {
121 return Linear(a[0] - b[0], a[1] - b[1]);
123 inline Linear& operator+=(Linear & a, Linear
const & b) {
124 a[0] += b[0]; a[1] += b[1];
127 inline Linear& operator-=(Linear & a, Linear
const & b) {
128 a[0] -= b[0]; a[1] -= b[1];
132 inline Linear operator+(Linear
const & a,
double b) {
133 return Linear(a[0] + b, a[1] + b);
135 inline Linear operator-(Linear
const & a,
double b) {
136 return Linear(a[0] - b, a[1] - b);
138 inline Linear& operator+=(Linear & a,
double b) {
139 a[0] += b; a[1] += b;
142 inline Linear& operator-=(Linear & a,
double b) {
143 a[0] -= b; a[1] -= b;
147 inline bool operator==(Linear
const & a, Linear
const & b) {
148 return a[0] == b[0] && a[1] == b[1];
150 inline bool operator!=(Linear
const & a, Linear
const & b) {
151 return a[0] != b[0] || a[1] != b[1];
154 inline Linear operator-(Linear
const &a) {
155 return Linear(-a[0], -a[1]);
157 inline Linear operator*(Linear
const & a,
double b) {
158 return Linear(a[0]*b, a[1]*b);
160 inline Linear operator/(Linear
const & a,
double b) {
161 return Linear(a[0]/b, a[1]/b);
163 inline Linear operator*=(Linear & a,
double b) {
164 a[0] *= b; a[1] *= b;
167 inline Linear operator/=(Linear & a,
double b) {
168 a[0] /= b; a[1] /= b;
173 #endif //SEEN_LINEAR_H
Definition: interval.h:56