File: vec3.hpp

package info (click to toggle)
sol2 3.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,096 kB
  • sloc: cpp: 43,816; ansic: 1,018; python: 356; sh: 288; makefile: 202
file content (74 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once

#ifndef ZM_VEC3_HPP
#define ZM_VEC3_HPP

#include <cstddef>

namespace zm {

	struct vec3 {
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
#pragma clang diagnostic ignored "-Wnested-anon-types"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4201) // nonstandard extension used :
                                // nameless struct/union
#pragma warning(disable : 4324) // structure was padded due to
                                // alignment specifier
#endif
		union {
			float elements[3];
			struct {
				union {
					float x, r, s;
				};
				union {
					float y, g, t;
				};
				union {
					float z, b, p;
				};
			};
		};

#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif

		vec3() : x(0), y(0), z(0) {
		}

		vec3(float x_, float y_, float z_)
		: x(x_), y(y_), z(z_) {
		}

		constexpr float* data() {
			return elements;
		}

		constexpr const float* data() const {
			return this->elements;
		}

		constexpr float& operator[](std::size_t i) {
			return this->elements[i];
		}

		constexpr const float& operator[](
		     std::size_t i) const {
			return this->elements[i];
		}
	};
} // namespace zm

#endif // ZM_VEC3_HPP