blob: 798382d2bd9e4124a4fada40f2e448860d8bbfd0 [file] [log] [blame]
Mathias Agopian595ea772013-08-21 23:10:41 -07001/*
2 * Copyright 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef UI_VEC4_H
18#define UI_VEC4_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <ui/vec3.h>
24
25namespace android {
26// -------------------------------------------------------------------------------------
27
28template <typename T>
29class tvec4 : public TVecArithmeticOperators<tvec4, T>,
30 public TVecUnaryOperators<tvec4, T>,
31 public TVecComparisonOperators<tvec4, T>,
32 public TVecFunctions<tvec4, T>
33{
34public:
35 enum no_init { NO_INIT };
36 typedef T value_type;
37 typedef T& reference;
38 typedef T const& const_reference;
39 typedef size_t size_type;
40
41 union {
42 struct { T x, y, z, w; };
43 struct { T s, t, p, q; };
44 struct { T r, g, b, a; };
45 Impersonator< tvec2<T> > xy;
46 Impersonator< tvec2<T> > st;
47 Impersonator< tvec2<T> > rg;
48 Impersonator< tvec3<T> > xyz;
49 Impersonator< tvec3<T> > stp;
50 Impersonator< tvec3<T> > rgb;
51 };
52
53 enum { SIZE = 4 };
54 inline static size_type size() { return SIZE; }
55
56 // array access
57 inline T const& operator [] (size_t i) const { return (&x)[i]; }
58 inline T& operator [] (size_t i) { return (&x)[i]; }
59
60 // -----------------------------------------------------------------------
61 // we don't provide copy-ctor and operator= on purpose
62 // because we want the compiler generated versions
63
64 // constructors
65
66 // leaves object uninitialized. use with caution.
67 explicit tvec4(no_init) { }
68
69 // default constructor
70 tvec4() : x(0), y(0), z(0), w(0) { }
71
72 // handles implicit conversion to a tvec4. must not be explicit.
73 template<typename A>
74 tvec4(A v) : x(v), y(v), z(v), w(v) { }
75
76 template<typename A, typename B, typename C, typename D>
77 tvec4(A x, B y, C z, D w) : x(x), y(y), z(z), w(w) { }
78
79 template<typename A, typename B, typename C>
80 tvec4(const tvec2<A>& v, B z, C w) : x(v.x), y(v.y), z(z), w(w) { }
81
82 template<typename A, typename B>
83 tvec4(const tvec3<A>& v, B w) : x(v.x), y(v.y), z(v.z), w(w) { }
84
85 template<typename A>
86 explicit tvec4(const tvec4<A>& v) : x(v.x), y(v.y), z(v.z), w(v.w) { }
87
88 template<typename A, typename B>
89 tvec4(const Impersonator< tvec3<A> >& v, B w)
90 : x(((const tvec3<A>&)v).x),
91 y(((const tvec3<A>&)v).y),
92 z(((const tvec3<A>&)v).z),
93 w(w) { }
94
95 template<typename A, typename B, typename C>
96 tvec4(const Impersonator< tvec2<A> >& v, B z, C w)
97 : x(((const tvec2<A>&)v).x),
98 y(((const tvec2<A>&)v).y),
99 z(z),
100 w(w) { }
101};
102
103// ----------------------------------------------------------------------------------------
104
105typedef tvec4<float> vec4;
106
107// ----------------------------------------------------------------------------------------
108}; // namespace android
109
110#endif /* UI_VEC4_H */