How to add padding to hit test override?

if i want the range to be 8 pixels or so within the range

just run a for loop?

edit I think we are suppose to add triangle the line method works but not very good then draw the real path elsewhere

    bool hitTest(int x, int y) override {
        
        auto val =  path.contains(x, y);
        
        return val;
    }
    bool hitTest(int x, int y) override {
        bool val = false;
        
        for(int i = 0; i < 8; i++){
            for(int j = 0; j < 8; j++) {
                val = path.contains(x-4+i,y-4+j);
            }
        }
        
        return val;
    }

The code you wrote there won’t do what you want because it’s only going to tell you whether the last pixel in the loop intersects. If you wanted to fix it, you’d have to add a check inside the inner loop and return early if path.contains() is true.

But this doesn’t seem like a great solution to begin with because you have to do 8 * 8 = 64 separate checks. Imagine if you want to increase the padding size: the time it takes to check will increase parabolically.

See if you can come up with something simpler, that only involves a couple of checks regardless of the size. If the Path you are dealing with is a rectangle, then you can do something like Rectangle(8, 8).withCentre({x, y}).intersects(pathRectangle);

Thank you for the reply I figured it out I drew two fake paths above and below and checked in between if it mathches either above or below then hit test returns true only painting the real path