-void DrawingView::UpdateGridBackground(void)
-{
- // Transform the origin to Qt coordinates
- Vector pixmapOrigin = Painter::CartesianToQtCoords(Vector());
- int x = (int)pixmapOrigin.x;
- int y = (int)pixmapOrigin.y;
- // Use mod arithmetic to grab the correct swatch of background
-/*
-Negative numbers still screw it up... Need to think about what we're
-trying to do here. The fact that it worked with 72 seems to have been pure luck.
-It seems the problem is negative numbers: We can't let that happen.
-When taking away the zero, it pops over 1 px at zero, then goes about 1/2 a
-grid at x<0.
-
-The bitmap looks like this:
-
-+---+---+---+---+---
-| | | | |
-| | | | |
-+---+---+---+---+---
-| | | | |
-| | | | |
-| | | | |
-
-@ x = 1, we want it to look like:
-
--+---+---+---+---+---
- | | | | |
- | | | | |
--+---+---+---+---+---
- | | | | |
- | | | | |
- | | | | |
-
-Which means we need to grab the sample from x = 3. @ x = -1:
-
----+---+---+---+---
- | | | |
- | | | |
----+---+---+---+---
- | | | |
- | | | |
- | | | |
-
-Which means we need to grab the sample from x = 1. Which means we have to take
-the mirror of the modulus of gridPixels.
-
-Doing a mod of a negative number is problematic: 1st, the compiler converts the
-negative number to an unsigned int, then it does the mod. Gets you wrong answers
-most of the time, unless you use a power of 2. :-P So what we do here is just
-take the modulus of the negation, which means we don't have to worry about
-mirroring it later.
-
-The positive case looks gruesome (and it is) but it boils down to this: We take
-the modulus of the X coordinate, then mirror it by subtraction from the
-maximum (in this case, gridPixels). This gives us a number in the range of 1 to
-gridPixels. But we need the case where the result equalling gridPixels to be
-zero; so we do another modulus operation on the result to achieve this.
-*/
- if (x < 0)
- x = -x % gridPixels;
- else
- x = (gridPixels - (x % gridPixels)) % gridPixels;