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 private static enum string _elements(string[4] l) 40 { 41 string ret; 42 foreach (size_t i; 0 .. N) 43 { 44 ret ~= "T " ~ l[i] ~ "; "; 45 } 46 return ret; 47 } 48 49 union 50 { 51 T[N] vec; 52 static if (N < 5) 53 { 54 struct { mixin(_elements(["x", "y", "z", "w"])); } 55 struct { mixin(_elements(["r", "g", "b", "a"])); } 56 struct { mixin(_elements(["s", "t", "p", "q"])); } 57 } 58 } 59 } 60 61 alias vec!(int, 2) Vector2i, ivec2; 62 alias vec!(uint, 2) Vector2u, uvec2; 63 alias vec!(float, 2) Vector2f, vec2; 64 alias vec!(double, 2) Vector2d, dvec2; 65 66 alias vec!(int, 3) Vector3i, ivec3; 67 alias vec!(uint, 3) Vector3u, uvec3; 68 alias vec!(float, 3) Vector3f, vec3; 69 alias vec!(double, 3) Vector3d, dvec3; 70 71 alias vec!(int, 4) Vector4i, ivec4; 72 alias vec!(uint, 4) Vector4u, uvec4; 73 alias vec!(float, 4) Vector4f, vec4; 74 alias vec!(double, 4) Vector4d, dvec4;