Grab Bag Release: Math

As you might have noticed, I have slightly changed the order of the development roadmap of my Grab Bag of Useful Stuff: 2D Packing heavily relies on rectangles, and that’s why I decided to implement to the Math classes first. These will come in handy for the second version of the ByChance Framework later, as well.

Math

The Npruehs.GrabBag.Math namespace contains utility classes for many math operations.

Math2 is a useful extension of the .NET System.Math class, providing constants like PiOverTwo, or methods like DegreesToRadians for converting angles and passing them to the .NET trigonometric functions.

John Carmack himself advises to use vector structs instead of fields for x- and y-coordinates, for example. Thus, other parts of the Grab Bag follow that advice, and you can do so as well. The vector structs are immutable and feature a lot of convenient operator overloads.

John Carmack @ID_AA_Carmack 9:15 PM – 5 Mar 13

I advocate the use of an idVec2i type for all two integer element tasks over discrete x/y, width/height, etc. A lot of code is improved.

Additionally, there are geometry classes for rectangles and boxes for the same reason.