1 /*
2                                     __
3                                    / _|
4   __ _ _   _ _ __ ___  _ __ __ _  | |_ ___  ___ ___
5  / _` | | | | '__/ _ \| '__/ _` | |  _/ _ \/ __/ __|
6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \
7  \__,_|\__,_|_|  \___/|_|  \__,_| |_| \___/|___/___/
8 
9 Copyright (C) 2018-2019 Aurora Free Open Source Software.
10 
11 This file is part of the Aurora Free Open Source Software. This
12 organization promote free and open source software that you can
13 redistribute and/or modify under the terms of the GNU Lesser General
14 Public License Version 3 as published by the Free Software Foundation or
15 (at your option) any later version approved by the Aurora Free Open Source
16 Software Organization. The license is available in the package root path
17 as 'LICENSE' file. Please review the following information to ensure the
18 GNU Lesser General Public License version 3 requirements will be met:
19 https://www.gnu.org/licenses/lgpl.html .
20 
21 Alternatively, this file may be used under the terms of the GNU General
22 Public License version 3 or later as published by the Free Software
23 Foundation. Please review the following information to ensure the GNU
24 General Public License requirements will be met:
25 http://www.gnu.org/licenses/gpl-3.0.html.
26 
27 NOTE: All products, services or anything associated to trademarks and
28 service marks used or referenced on this file are the property of their
29 respective companies/owners or its subsidiaries. Other names and brands
30 may be claimed as the property of others.
31 
32 For more info about intellectual property visit: aurorafoss.org or
33 directly send an email to: contact (at) aurorafoss.org .
34 */
35 
36 module aurorafw.math.vector;
37 
38 @nogc pure @safe struct vec(T, size_t N)
39 {
40 	private static string _elements(string[4] l)
41 	{
42 		string ret;
43 		foreach (size_t i; 0 .. N)
44 		{
45 			ret ~= "T " ~ l[i] ~ "; ";
46 		}
47 		return ret;
48 	}
49 
50 	union
51 	{
52 		T[N] vec;
53 		static if (N <= 4)
54 		{
55 			struct
56 			{
57 				mixin(_elements(["x", "y", "z", "w"]));
58 			}
59 
60 			struct
61 			{
62 				mixin(_elements(["r", "g", "b", "a"]));
63 			}
64 
65 			struct
66 			{
67 				mixin(_elements(["s", "t", "p", "q"]));
68 			}
69 		}
70 	}
71 }
72 
73 //TODO: Add unittesting
74 
75 alias Vector2i = vec!(int, 2), ivec2 = vec!(int, 2);
76 alias Vector2u = vec!(uint, 2), uvec2 = vec!(uint, 2);
77 alias Vector2f = vec!(float, 2), vec2 = vec!(float, 2);
78 alias Vector2d = vec!(double, 2), dvec2 = vec!(double, 2);
79 
80 alias Vector3i = vec!(int, 3), ivec3 = vec!(int, 3);
81 alias Vector3u = vec!(uint, 3), uvec3 = vec!(uint, 3);
82 alias Vector3f = vec!(float, 3), vec3 = vec!(float, 3);
83 alias Vector3d = vec!(double, 3), dvec3 = vec!(double, 3);
84 
85 alias Vector4i = vec!(int, 4), ivec4 = vec!(int, 4);
86 alias Vector4u = vec!(uint, 4), uvec4 = vec!(uint, 4);
87 alias Vector4f = vec!(float, 4), vec4 = vec!(float, 4);
88 alias Vector4d = vec!(double, 4), dvec4 = vec!(double, 4);