blob: 47c413ac7bb9dd91a0de09f0dd01c99b876d5975 [file] [log] [blame]
caryclark@google.coma5764232012-03-28 16:20:21 +00001#ifndef Intersections_DEFINE
2#define Intersections_DEFINE
3
caryclark@google.com639df892012-01-10 21:46:10 +00004class Intersections {
5public:
6 Intersections()
7 : fUsed(0)
8 , fSwap(0)
9 {
10 bzero(fT, sizeof(fT));
11 }
12
13 void add(double one, double two) {
14 if (fUsed > 0 && approximately_equal(fT[fSwap][fUsed - 1], one)
15 && approximately_equal(fT[fSwap ^ 1][fUsed - 1], two)) {
16 return;
17 }
18 fT[fSwap][fUsed] = one;
19 fT[fSwap ^ 1][fUsed] = two;
20 ++fUsed;
21 }
22
23 void offset(int base, double start, double end) {
24 for (int index = base; index < fUsed; ++index) {
25 double val = fT[fSwap][index];
26 val *= end - start;
27 val += start;
28 fT[fSwap][index] = val;
29 }
30 }
31
32 bool intersected() {
33 return fUsed > 0;
34 }
35
36 void swap() {
37 fSwap ^= 1;
38 }
39
40 bool swapped() {
41 return fSwap;
42 }
43
44 int used() {
45 return fUsed;
46 }
47
48 double fT[2][9];
caryclark@google.com639df892012-01-10 21:46:10 +000049 int fUsed;
caryclark@google.coma5764232012-03-28 16:20:21 +000050private:
caryclark@google.com639df892012-01-10 21:46:10 +000051 int fSwap;
52};
caryclark@google.coma5764232012-03-28 16:20:21 +000053
54#endif
55