caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame^] | 1 | class Intersections { |
| 2 | public: |
| 3 | Intersections() |
| 4 | : fUsed(0) |
| 5 | , fSwap(0) |
| 6 | { |
| 7 | bzero(fT, sizeof(fT)); |
| 8 | } |
| 9 | |
| 10 | void add(double one, double two) { |
| 11 | if (fUsed > 0 && approximately_equal(fT[fSwap][fUsed - 1], one) |
| 12 | && approximately_equal(fT[fSwap ^ 1][fUsed - 1], two)) { |
| 13 | return; |
| 14 | } |
| 15 | fT[fSwap][fUsed] = one; |
| 16 | fT[fSwap ^ 1][fUsed] = two; |
| 17 | ++fUsed; |
| 18 | } |
| 19 | |
| 20 | void offset(int base, double start, double end) { |
| 21 | for (int index = base; index < fUsed; ++index) { |
| 22 | double val = fT[fSwap][index]; |
| 23 | val *= end - start; |
| 24 | val += start; |
| 25 | fT[fSwap][index] = val; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | bool intersected() { |
| 30 | return fUsed > 0; |
| 31 | } |
| 32 | |
| 33 | void swap() { |
| 34 | fSwap ^= 1; |
| 35 | } |
| 36 | |
| 37 | bool swapped() { |
| 38 | return fSwap; |
| 39 | } |
| 40 | |
| 41 | int used() { |
| 42 | return fUsed; |
| 43 | } |
| 44 | |
| 45 | double fT[2][9]; |
| 46 | private: |
| 47 | int fUsed; |
| 48 | int fSwap; |
| 49 | }; |