1 module aurorafw.math.vector;
2 
3 /****************************************************************************
4 ** ┌─┐┬ ┬┬─┐┌─┐┬─┐┌─┐  ┌─┐┬─┐┌─┐┌┬┐┌─┐┬ ┬┌─┐┬─┐┬┌─
5 ** ├─┤│ │├┬┘│ │├┬┘├─┤  ├┤ ├┬┘├─┤│││├┤ ││││ │├┬┘├┴┐
6 ** ┴ ┴└─┘┴└─└─┘┴└─┴ ┴  └  ┴└─┴ ┴┴ ┴└─┘└┴┘└─┘┴└─┴ ┴
7 ** A Powerful General Purpose Framework
8 ** More information in: https://aurora-fw.github.io/
9 **
10 ** Copyright (C) 2018 Aurora Framework, All rights reserved.
11 **
12 ** This file is part of the Aurora Framework. This framework is free
13 ** software; you can redistribute it and/or modify it under the terms of
14 ** the GNU Lesser General Public License version 3 as published by the
15 ** Free Software Foundation and appearing in the file LICENSE included in
16 ** the packaging of this file. Please review the following information to
17 ** ensure the GNU Lesser General Public License version 3 requirements
18 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
19 ****************************************************************************/
20 
21 @nogc pure @safe struct vec(T, size_t N) {
22 	private static enum string _elements(string[4] l)
23 	{
24 		string ret;
25 		foreach (size_t i; 0 .. N)
26 		{
27 			ret ~= "T " ~ l[i] ~ "; ";
28 		}
29 		return ret;
30 	}
31 
32 	union
33 	{
34 		T[N] vec;
35 		static if (N < 5)
36 		{
37 			struct { mixin(_elements(["x", "y", "z", "w"])); }
38 			struct { mixin(_elements(["r", "g", "b", "a"])); }
39 			struct { mixin(_elements(["s", "t", "p", "q"])); }
40 		}
41 	}
42 }
43 
44 alias vec!(int, 2) Vector2i;
45 alias vec!(uint, 2) Vector2u;
46 alias vec!(float, 2) Vector2f;
47 alias vec!(double, 2) Vector2d;
48 
49 alias vec!(int, 3) Vector3i;
50 alias vec!(uint, 3) Vector3u;
51 alias vec!(float, 3) Vector3f;
52 alias vec!(double, 3) Vector3d;
53 
54 alias vec!(int, 4) Vector4i;
55 alias vec!(uint, 4) Vector4u;
56 alias vec!(float, 4) Vector4f;
57 alias vec!(double, 4) Vector4d;
58 
59 alias Vector2i ivec2;
60 alias Vector2u uvec2;
61 alias Vector2f vec2;
62 alias Vector2d dvec2;
63 
64 alias Vector3i ivec3;
65 alias Vector3u uvec3;
66 alias Vector3f vec3;
67 alias Vector3d dvec3;
68 
69 alias Vector4i ivec4;
70 alias Vector4u uvec4;
71 alias Vector4f vec4;
72 alias Vector4d dvec4;