Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in fillRectangle #69

Open
sbmrgd opened this issue Dec 11, 2018 · 2 comments
Open

bug in fillRectangle #69

sbmrgd opened this issue Dec 11, 2018 · 2 comments

Comments

@sbmrgd
Copy link

sbmrgd commented Dec 11, 2018

fillRectangle(x0,y0, s,s) does not draw a square it seems to me, because the x-range goes from x0 till x0+s-1, while the y-range goes from y0 till y0+s

@pokitto
Copy link
Owner

pokitto commented Dec 14, 2018

Possible. Let me check

@sbmrgd
Copy link
Author

sbmrgd commented Dec 15, 2018

I tried to highlight the 2 lines of code (with ** **) that show the issue:
in fill rectangle, x goes from x0 until x1-1 while in drawColumn, y goes from sy until ey.

void Display::fillRectangle(int16_t x0,int16_t y0, int16_t w, int16_t h){
    int16_t x,y,x1,y1;
    x1=x0+w;y1=y0+h;
    if ((x0<0 && x1<0) || (x0>=width && x1 >=width)) return; //completely out of bounds
    if ((y0<0 && y1<0) || (y0>=height && y1 >=height)) return; //completely out of bounds
    if (x0>x1) {x=x1;x1=x0;}
    else x=x0;
    if (y0>y1) {y=y1;y1=y0;}
    else y=y0;
    if (x<0) x=0;
    if (y<0) y=0;
    **for (;x<x1;x++) drawColumn(x,y,y1);**
}
void Display::drawColumn(int16_t x, int16_t sy, int16_t ey){
    if ((uint16_t)sy>=height && (uint16_t)ey>=height) return; //completely out of bounds
    if ((uint16_t)x>=width) return; //completely out of bounds
    if (sy>ey) {
            int y=sy;
            sy=ey;
            ey=y; // swap around so that x0 is less than x1
    }
    **for (int y=sy; y <= ey; y++)** {
        drawPixel(x,y);
    }
}

I think this is easily fixed, but as I am only a beginner I don't feel comfortable to do pull requests etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants