Hey all! Lately I’ve been a little confused about something that really should be simple, something that should probably send me back to like a basic geometry class or something. I’m simply trying to draw and do math with a rectangle, defined by an X, Y, width and height. When I draw a rectangle at any point with a width/height of 16, the drawn rectangle ends up being 17x17.
To combat this in drawing, I just subtracted 1 from the end coordinates. For example, this is how my code would’ve changed:
GBOX X, Y, X + W, Y + H
GBOX X, Y, X + W - 1, Y + H - 1I did this because the old version seems to count the starting pixel as part of the rectangle, but not as part of the size of the rectangle. This worked to solve the graphics side of things, however when I started adding math the problem was no longer completely solved because it seems like in any arithmetic operation I’d need to subtract 1 from the size again. Otherwise, whatever I’m doing with the rectangle in terms of physics would not match up exactly with what the rectangle looks like on screen. There seems to be a simple solution: in my function to define a rectangle I would just push on the input size minus 1, rather than the input size unchanged. In that way, I would never have to subtract 1 from the size to get my desired results. However, I don’t think this would account for the whole picture. I also want to do math that will inevitably use half of the rectangle’s size, because for example I will want to find the center point of this rectangle. My intended size for this particular rectangle is 16x16, and subtracting 1 from the input of 16 causes the system to actually draw a 16x16 rectangle. But half of 15, the newly stored size, is different from half of 16, so if I were to preemptively subtract 1 for the sake of drawing functions and addition/subtraction, I would have to add 1 back in for multiplication/division. Maybe this is something to do with how SmileBASIC works, or perhaps more likely this is a subtlety with math that I don’t fully understand yet. In either case, I’m looking for more insight. What way does the math actually work? What would be the correct action to take in order to make a realistic physics system while also keeping a safe distance from any spaghetti code? Right now I’m thinking I’ll just subtract 1 from the size any time I’m using purely addition or subtraction, so multiplication and division don’t get muddy. Is that a smart way to go, and does that properly capture the bigger picture of what’s going on?