| 40 | |
| 41 | template<class A> |
| 42 | inline |
| 43 | Slice<A>::Slice(const Matrix<A>& a, int fc, int tc, int fr, int tr) |
| 44 | : _r(0), _fc(fc), _tc(tc), _fr(fr), _tr(tr) { |
| 45 | if (tc > a.width() || tr > a.height()) |
| 46 | throw MiniModel::ArgumentOutOfRange("Slice::Slice"); |
| 47 | if (fc >= tc || fr >= tr) { |
| 48 | _fc=0; _tc=0; _fr=0; _tr=0; |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | _r = ArgsType((tc-fc)*(tr-fr)); |
| 53 | |
| 54 | int i = 0; |
| 55 | for (int h = fr; h < tr; h++) |
| 56 | for (int w = fc; w < tc; w++) |
| 57 | _r[i++] = a(w, h); |
| 58 | } |
| 59 | |
| 60 | template<class A> |
| 61 | Slice<A>& |