2 * Copyright 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/types.h>
26 // -------------------------------------------------------------------------------------
29 class tvec4 : public TVecProductOperators<tvec4, T>,
30 public TVecAddOperators<tvec4, T>,
31 public TVecUnaryOperators<tvec4, T>,
32 public TVecComparisonOperators<tvec4, T>,
33 public TVecFunctions<tvec4, T>
36 enum no_init { NO_INIT };
39 typedef T const& const_reference;
40 typedef size_t size_type;
43 struct { T x, y, z, w; };
44 struct { T s, t, p, q; };
45 struct { T r, g, b, a; };
46 Impersonator< tvec2<T> > xy;
47 Impersonator< tvec2<T> > st;
48 Impersonator< tvec2<T> > rg;
49 Impersonator< tvec3<T> > xyz;
50 Impersonator< tvec3<T> > stp;
51 Impersonator< tvec3<T> > rgb;
55 inline static size_type size() { return SIZE; }
58 inline T const& operator [] (size_t i) const { return (&x)[i]; }
59 inline T& operator [] (size_t i) { return (&x)[i]; }
61 // -----------------------------------------------------------------------
62 // we don't provide copy-ctor and operator= on purpose
63 // because we want the compiler generated versions
67 // leaves object uninitialized. use with caution.
68 explicit tvec4(no_init) { }
70 // default constructor
71 tvec4() : x(0), y(0), z(0), w(0) { }
73 // handles implicit conversion to a tvec4. must not be explicit.
75 tvec4(A v) : x(v), y(v), z(v), w(v) { }
77 template<typename A, typename B, typename C, typename D>
78 tvec4(A x, B y, C z, D w) : x(x), y(y), z(z), w(w) { }
80 template<typename A, typename B, typename C>
81 tvec4(const tvec2<A>& v, B z, C w) : x(v.x), y(v.y), z(z), w(w) { }
83 template<typename A, typename B>
84 tvec4(const tvec3<A>& v, B w) : x(v.x), y(v.y), z(v.z), w(w) { }
87 explicit tvec4(const tvec4<A>& v) : x(v.x), y(v.y), z(v.z), w(v.w) { }
90 tvec4(const Impersonator< tvec4<A> >& v)
91 : x(((const tvec4<A>&)v).x),
92 y(((const tvec4<A>&)v).y),
93 z(((const tvec4<A>&)v).z),
94 w(((const tvec4<A>&)v).w) { }
96 template<typename A, typename B>
97 tvec4(const Impersonator< tvec3<A> >& v, B w)
98 : x(((const tvec3<A>&)v).x),
99 y(((const tvec3<A>&)v).y),
100 z(((const tvec3<A>&)v).z),
103 template<typename A, typename B, typename C>
104 tvec4(const Impersonator< tvec2<A> >& v, B z, C w)
105 : x(((const tvec2<A>&)v).x),
106 y(((const tvec2<A>&)v).y),
111 // ----------------------------------------------------------------------------------------
113 typedef tvec4<float> vec4;
115 // ----------------------------------------------------------------------------------------
116 }; // namespace android
118 #endif /* UI_VEC4_H */