gamercade-io / gamercade_console

A Neo-Retro Fantasy Console. Make WASM-powered, networked multiplayer games.
https://gamercade.io
Apache License 2.0
166 stars 10 forks source link

fix(draw_context): Draw circle out of bounds #44

Closed Cardosaum closed 1 year ago

Cardosaum commented 1 year ago

Fix #4, drawing both circle and circle_filled correctly even when the circle would fall out of bounds (outside of screen).


There might be room for optimizations.

Functions set_pixel_safe and x_y_cord_to_pixel_buffer_index are admittedly ugly, I think it would be a good idea to create helper methods like try_add(self, rhs) -> Result<Self, Error> and variants in order to make the code cleaner. Probably adding a trait like CoordinateMath with such methods or something like that. If it's of interest, I can work on that later.

Cardosaum commented 1 year ago

@RobDavenport , could you please take a look in this new changes?

I made quite a few this time, trying to address your previous comments. I think now it's impossible for us to have invalid XCord and YCord when creating them from validate_x and validate_y. It's also impossible to instantiate XCord and YCord manually, but it is technically possible to create invalid coordinates when multiplying or adding already existing ones. (I just figured out that it's actually the case. I may submit a new commit fixing it, and then it'll probably be possible to remove the checks in the draw_circle_points)