aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/Intersection/Intersections.h
blob: 879b54e1f5ac51a67f9fbf03f03599b772e545c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef Intersections_DEFINE
#define Intersections_DEFINE

class Intersections {
public:
    Intersections()
        : fUsed(0)
        , fSwap(0)
    {
        bzero(fT, sizeof(fT));
    }

    void add(double one, double two) {
        if (fUsed > 0 && approximately_equal(fT[fSwap][fUsed - 1], one)
                && approximately_equal(fT[fSwap ^ 1][fUsed - 1], two)) {
            return;
        }
        fT[fSwap][fUsed] = one;
        fT[fSwap ^ 1][fUsed] = two;
        ++fUsed;
    }

    void offset(int base, double start, double end) {
        for (int index = base; index < fUsed; ++index) {
            double val = fT[fSwap][index];
            val *= end - start;
            val += start;
            fT[fSwap][index] = val;
        }
    }

    bool intersected() {
        return fUsed > 0;
    }

    void swap() {
        fSwap ^= 1;
    }

    bool swapped() {
        return fSwap;
    }

    int used() {
        return fUsed;
    }

    double fT[2][9];
    int fUsed;
private:
    int fSwap;
};

#endif