skia2/experimental/Intersection/Intersections.h
rmistry@google.com d6176b0dca Result of running tools/sanitize_source_files.py (which was added in https://codereview.appspot.com/6465078/)
This CL is part II of IV (I broke down the 1280 files into 4 CLs).
Review URL: https://codereview.appspot.com/6474054

git-svn-id: http://skia.googlecode.com/svn/trunk@5263 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-08-23 18:14:13 +00:00

56 lines
1.0 KiB
C++

#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