1 #ifndef SEEN_SBASIS_2D_H
2 #define SEEN_SBASIS_2D_H
21 for(
unsigned i = 0 ; i < 4; i ++)
24 Linear2d(
double a00,
double a01,
double a10,
double a11)
32 double operator[](
const int i)
const {
37 double& operator[](
const int i) {
42 double apply(
double u,
double v) {
43 return (a[0]*(1-u)*(1-v) +
56 inline Linear extract_v(Linear2d
const &a,
double v) {
57 return Linear(a[0]*(1-v) +
62 inline Linear2d operator-(Linear2d
const &a) {
63 return Linear2d(-a.a[0], -a.a[1],
66 inline Linear2d operator+(Linear2d
const & a, Linear2d
const & b) {
67 return Linear2d(a[0] + b[0],
72 inline Linear2d operator-(Linear2d
const & a, Linear2d
const & b) {
73 return Linear2d(a[0] - b[0],
78 inline Linear2d& operator+=(Linear2d & a, Linear2d
const & b) {
79 for(
unsigned i = 0; i < 4; i++)
83 inline Linear2d& operator-=(Linear2d & a, Linear2d
const & b) {
84 for(
unsigned i = 0; i < 4; i++)
88 inline Linear2d& operator*=(Linear2d & a,
double b) {
89 for(
unsigned i = 0; i < 4; i++)
94 inline bool operator==(Linear2d
const & a, Linear2d
const & b) {
95 for(
unsigned i = 0; i < 4; i++)
100 inline bool operator!=(Linear2d
const & a, Linear2d
const & b) {
101 for(
unsigned i = 0; i < 4; i++)
106 inline Linear2d operator*(
double const a, Linear2d
const & b) {
107 return Linear2d(a*b[0], a*b[1],
121 : std::vector<Linear2d>(a), us(a.us), vs(a.vs) {}
123 Linear2d& index(
unsigned ui,
unsigned vi) {
126 return (*
this)[ui + vi*us];
129 Linear2d index(
unsigned ui,
unsigned vi)
const {
134 return (*
this)[ui + vi*us];
137 double apply(
double u,
double v)
const {
143 for(
unsigned vi = 0; vi < vs; vi++) {
145 for(
unsigned ui = 0; ui < us; ui++) {
146 p += (sk*tk)*index(ui, vi);
160 double tail_error(
unsigned tail)
const;
162 void truncate(
unsigned k);
167 result.reserve(p.size());
169 for(
unsigned i = 0; i < p.size(); i++) {
170 result.push_back(-p[i]);
175 inline SBasis2d operator+(
const SBasis2d& a,
const SBasis2d& b) {
177 result.us = std::max(a.us, b.us);
178 result.vs = std::max(a.vs, b.vs);
179 const unsigned out_size = result.us*result.vs;
180 result.resize(out_size);
182 for(
unsigned vi = 0; vi < result.vs; vi++) {
183 for(
unsigned ui = 0; ui < result.us; ui++) {
185 if(ui < a.us && vi < a.vs)
186 bo += a.index(ui, vi);
187 if(ui < b.us && vi < b.vs)
188 bo += b.index(ui, vi);
189 result.index(ui, vi) = bo;
195 inline SBasis2d operator-(
const SBasis2d& a,
const SBasis2d& b) {
197 result.us = std::max(a.us, b.us);
198 result.vs = std::max(a.vs, b.vs);
199 const unsigned out_size = result.us*result.vs;
200 result.resize(out_size);
202 for(
unsigned vi = 0; vi < result.vs; vi++) {
203 for(
unsigned ui = 0; ui < result.us; ui++) {
205 if(ui < a.us && vi < a.vs)
206 bo += a.index(ui, vi);
207 if(ui < b.us && vi < b.vs)
208 bo -= b.index(ui, vi);
209 result.index(ui, vi) = bo;
216 inline SBasis2d& operator+=(SBasis2d& a,
const Linear2d& b) {
224 inline SBasis2d& operator-=(SBasis2d& a,
const Linear2d& b) {
232 inline SBasis2d& operator+=(SBasis2d& a,
double b) {
234 a.push_back(Linear2d(b));
236 for(
unsigned i = 0; i < 4; i++)
242 inline SBasis2d& operator-=(SBasis2d& a,
double b) {
244 a.push_back(Linear2d(-b));
251 inline SBasis2d& operator*=(SBasis2d& a,
double b) {
252 for(
unsigned i = 0; i < a.size(); i++)
257 inline SBasis2d& operator/=(SBasis2d& a,
double b) {
258 for(
unsigned i = 0; i < a.size(); i++)
263 SBasis2d operator*(
double k, SBasis2d
const &a);
264 SBasis2d operator*(SBasis2d
const &a, SBasis2d
const &b);
266 SBasis2d shift(SBasis2d
const &a,
int sh);
268 SBasis2d shift(Linear2d
const &a,
int sh);
270 SBasis2d truncate(SBasis2d
const &a,
unsigned terms);
272 SBasis2d multiply(SBasis2d
const &a, SBasis2d
const &b);
274 SBasis2d integral(SBasis2d
const &c);
276 SBasis2d derivative(SBasis2d
const &a);
278 SBasis2d sqrt(SBasis2d
const &a,
int k);
281 SBasis2d reciprocal(Linear2d
const &a,
int k);
283 SBasis2d divide(SBasis2d
const &a, SBasis2d
const &b,
int k);
286 SBasis2d compose(SBasis2d
const &a, SBasis2d
const &b);
287 SBasis2d compose(SBasis2d
const &a, SBasis2d
const &b,
unsigned k);
288 SBasis2d inverse(SBasis2d
const &a,
int k);
291 SBasis extract_u(SBasis2d
const &a,
double u);
292 SBasis extract_v(SBasis2d
const &a,
double v);
294 SBasis compose(Linear2d
const &a, D2<SBasis>
const &p);
296 SBasis compose(SBasis2d
const &fg, D2<SBasis>
const &p);
298 D2<SBasis> compose_each(D2<SBasis2d>
const &fg, D2<SBasis>
const &p);
300 inline std::ostream &operator<< (std::ostream &out_file,
const Linear2d &bo) {
301 out_file <<
"{" << bo[0] <<
", " << bo[1] <<
"}, ";
302 out_file <<
"{" << bo[2] <<
", " << bo[3] <<
"}";
306 inline std::ostream &operator<< (std::ostream &out_file,
const SBasis2d & p) {
307 for(
unsigned i = 0; i < p.size(); i++) {
308 out_file << p[i] <<
"s^" << i <<
" + ";
Definition: sbasis-2d.h:111
Definition: sbasis-2d.h:12