All the functionality is moved to Math::swizzle() and the result is
casted to given type only if its header is included. Thus it is possible
to remove include dependency on Color. The original swizzle() is now
just an alias marked as deprecated and will be removed in future
release.
Consider this craziness when setting up projection or something similar:
Vector2i framebufferSize;
Float aspectRatio = Float(framebufferSize.x())/framebufferSize.y();
And now, behold, the convenience:
Float aspectRatio = Vector2(framebufferSize).aspectRatio();
Operators that are part of Vector are operating only with the same type
as Vector itself, operators for multiplying/dividing integral vectors
with floating-point numbers and vectors are now out-of-class and enabled
only for integer vectors. It allows better control (e.g. multiplying
integer and floating-point vector will _always_ result in floating-point
one). Thoroughly tested integer/FP operations and also reworked and
tested operator and funciton reimplementations in subclasses, both for
value correctness and result type correctness.
Also fixed unary RectangularMatrix::operator-() and Vector::operator-()
documentation (was stating that the operation is done in-place, which is
impossible.
Also updated all dependent classes to follow the change, such as Color
and Rectangle. Backwards compatibility for GCC 4.6 (with lack of support
for delegating constructors) will be done as non-constexpr constructor
using operator=().
Overall architecture is simplififed with this change and also it's not
needed to use reinterpret_cast in matrix internals anymore, thus there
is no need for operator() and [][] works now always as expected without
any risk of GCC misoptimizations.
On the other side, constructing matrix from list of elements is not
possible anymore. You have to specify the elements as list of
column vectors, which might be less convenient to write, but it helps to
distinguish what is column and what is row:
Matrix<2, int> a(1, 2, // before
3, 4);
Matrix<2, int> a(Vector<2, int>(1, 2), // now
Vector<2, int>(3, 4));
For some matrix specializations (i.e. Matrix3 and Matrix4) it is
possible to use list-initialization instead of explicit type
specification:
Matrix<3, int>({1, 2, 3},
{4, 5, 6},
{7, 8, 9});
I didn't yet figure out how to properly implement the general
(constexpr) constructor to also take lists, so it's a bit ugly for now.
Matrix operations are now done column-wise, which should help with
future SIMD implementations, documentation is also updated accordingly.
I also removed forgotten remains of matrix/matrix operator*=(), which
can be confusing, as the multiplication is not commutative. Why it is
not present is explained in d9c900f076.
It prevents unwanted implicit conversions from e.g. nullptr to Camera,
Vector2 to Physics::Point etc. By making all the constructors explicit
it is easier to routinely add the keyword to all new classes instead of
thinking about cases when to add and when not to.
Before it has to be done with overly verbose and cumbersome Java-style:
Vector4 vec;
vec.setX(vec.x() + 5);
vec = Vector4(vec.xyz()*2, vec.w());
Now it can be done this way:
vec.x() += 5;
vec.xyz() *= 2;
Currently moved only non-square functionality from Matrix there. Also
static constant members such as row/column count and size are now
lowercase, as they are variables, not types.
Each function which returned e.g. Vector<size, T> was in subclasses
overloaded with function returning e.g. Vector3<T>, so the user is able
to use subclass-specific functions. It was nightmare to maintain and it
cluttered the documentation a lot.
Long-standing TODO. It is better to have size first, because it is more
significant than type (e.g. because there are Vector4<T> specializations
and not VectorT<4> specializations). It is also IMHO easier for user to
distinguish/read the type than before:
Vector<float, 4> -> Vector4<float> // before
Vector<4, float> -> Vector4<float> // now
Because no operator= which took the class itself as argument (parent
class only), the compiler generated default assignment and assignment
move constructors, e.g.
Vector3<T>& operator=(const Vector3<T>&);
Vector3<T>& operator=(Vector3&&);
Resulting in conflicts when using assignment uniform initialization,
i.e. it wasn't possible to do things like this, but that's now fixed:
Vector3<int> vec;
vec = {0, 1, 2};
Other functions left untouched (they are still taking e.g. Vector<T,
3> instead of Vector3<T>), because it saves one useless dummy
constructor call (which would be visible in profiler, but without
having any performance impacts altogether).
Removed functions at(), set() and add(), everything (and more) can be
now done using operator[]. Accessing matrix elements is now done through
column vectors, e.g.:
Matrix4 a;
a.at(row, col); // before
a[col][row]; // now
Note that because operator[] on Matrix returns column vector (there is
nothing like row vector), the parameter "order" is now swapped.
Marked the constructor as explicit, because we don't want mistakes like
this to happen:
Matrix4::rotation(1.0f, deg(3.0f)); // oops, swapped axis and angle!
Instead, when calling such constructor, the type must be said
explicitly (initializer-list is forbidden, too):
Matrix4::rotation(deg(3.0f), Vector3(1.0f)); // okay
It should improve performance, because what can be computed at compile
time is now computed at compile time. In addition these things have been
changed or improved:
* Removed constructors from T*, as they cannot be AFAIK written using
constexpr functions only and they only do unnecessary data copying
most of the time. The functionality is now provided using static
functions Matrix*::from() and Vector*::from() which returns either
const or non-const reference to original data, so no copy is
performed. These functions also have explicit warning about unsafe
operations.
* Defaulted copy constructors and assignment operators, using
"default initialization" for arrays instead of memsetting it with
zeros. It should behave the same and this way we don't need any
memcpy(), memset() etc. from <cstring>, which is good.
Multiplication, division, addition and substraction is now done
primarily in assigning operators, as they do the computations in-place,
so they are more memory efficient than implementing them using e.g.
`*this = *this+other;`.
Updated unit test only for matrix multiplication, as vector unit tests
test arithmetic asssign operators too.