Mathematics


This short article is about mathematical module added in 4.0.0 version of the Nitisa framework.


Mathematical module is a completely independent module implemented as a set of template functions and objects. It can be used as part of the framework and standalone as well. To include mathematical module into your source file you have to add #include "Nitisa/Modules/Math.h". But, if you already included other files from the framework, it could not be necessary because it is already included in most of the header files available in the framework. All the objects are located inside nitisa::math namespace.

Main purpose of the module is to provide usefull functions and objects for working with GUI elements and graphics. You can find complete list of available entities in Mathematical module reference. The most usefull objects are TPoint which is mainly used to represent point coordinates in 2D space; TRect which is used to describe such entities like rectangles, borders, corner radiuses, border colors; and the TTensor which represents multidimentional arrays, vectors, matrices. In case of TTensor we want you pay attention on using ^ operator. If you want vector multiplication of 2 vectors, transformation of vector by a matrix, multiplication of two matrices in proper way, use this operator. There is also * operator but it provides element wise multiplication. See difference below.

* operator

math::TTensor<int, 3> v1{ 1, 0, 0 };
math::TTensor<int, 3> v2{ 0, 1, 0 };
math::TTensor<int, 3> r{ v1 * v2 };
// r is { 0, 0, 0 }
r[0] = v1[0] * v2[0]
r[1] = v1[1] * v2[1]
r[2] = v1[2] * v2[2]
(element wise multiplication)

^ operator

math::TTensor<int, 3> v1{ 1, 0, 0 };
math::TTensor<int, 3> v2{ 0, 1, 0 };
math::TTensor<int, 3> r{ v1 ^ v2 };
// r is { 0, 0, 1 }
r[0] = v1[1] * v2[2] - v1[2] * v2[1]
r[1] = v1[2] * v2[0] - v1[0] * v2[2]
r[2] = v1[0] * v2[1] - v1[1] * v2[0]
(accordingly to vector multiplication rules for 3D vectors)

The TTensor is a very powerful template class but it is not always the best choise. The most common project type where better objects could be used is 3D graphics and games. They do not usually require power of higher dimentions which the TTensor provides. Instead such projects require more specific functionality and better performance. That is why we also added several template classes specially for such purposes. They are TVec2, TVec3, and TVec4 templates represending 2D, 3D, and 4D vectors; the TMat2, TMat3, and TMat4 templates for representing 2x2, 3x3, and 4x4 matrices.

Basically you may do with these objects all the things you can do with coresponding dimention tensors but the main difference from tensor they have is a direct access to elements and more efficient copy operations. Additinally you may find some useful in 3D graphics and gaming methods in these special templates(like building special type matrices).