Refactoring for endless running
By now, you've properly noticed a pattern. Every time we add a new feature, we start by refactoring the old code to make it easier to add it. This is generally a good practice in most forms of software development, and we'll be following that same pattern now. We identified a couple of code smells while creating the infinite background, so let's clean those up now, starting with dealing with all those casts.
f32 versus i16
We had to cast values several times to go from i16
to f32
and back again. This isn't a safe operation; the maximum of f32
is orders of magnitude larger than the maximum of i16
, so there's the potential for our program to crash on a big f32
. HtmlImageElement
uses u32
types, so all the casting to make the compiler shut up isn't even correct. We have two choices here:
- Take our data types (such as
Rect
andPoint
) and make them matchHtmlImageElement
. - Set
Rect
and any other domain object to...