1 | #include "../../libcfa/src/vec/vec2.hfa" |
---|
2 | #include <fstream.hfa> |
---|
3 | #include <limits.hfa> |
---|
4 | |
---|
5 | int main(void) { |
---|
6 | vec2(int) v1 = {1,2}; |
---|
7 | sout | "ctor(x,y):" | v1; |
---|
8 | |
---|
9 | vec2(int) v2 = v1; |
---|
10 | sout | "copy ctor:" | v2; |
---|
11 | |
---|
12 | v2 = (vec2(int)){3, 4}; |
---|
13 | sout | "assignment:" | v2; |
---|
14 | |
---|
15 | v2 = v1; |
---|
16 | sout | "move assignment:" | v2; |
---|
17 | |
---|
18 | vec2(int) v3 = 0; |
---|
19 | sout | "zero-init:" | v3; |
---|
20 | |
---|
21 | v1 = 0; |
---|
22 | sout | "zero-assign:" | v1; |
---|
23 | |
---|
24 | vec2(int) v4 = {123}; |
---|
25 | sout | "fill-ctor:" | v4; |
---|
26 | |
---|
27 | v1 = (vec2(int)){1, 3}; |
---|
28 | sout | "?-?:" | (v1 - (vec2(int)){1003, -14}); |
---|
29 | |
---|
30 | v1 -= (vec2(int)){1003, -14}; |
---|
31 | sout | "?-=?:" | v1; |
---|
32 | |
---|
33 | v1 = -v1; |
---|
34 | sout | "-?:" | v1; |
---|
35 | |
---|
36 | v1 = (vec2(int)){1, 3}; |
---|
37 | sout | "?+?:" | (v1 + (vec2(int)){1003, -14}); |
---|
38 | |
---|
39 | v1 += (vec2(int)){1003, -14}; |
---|
40 | sout | "?+=?:" | v1; |
---|
41 | |
---|
42 | v1 = (vec2(int)){15, 275}; |
---|
43 | sout | "v*s:" | v1 * 3; |
---|
44 | |
---|
45 | sout | "s*v:" | 3 * v1; |
---|
46 | |
---|
47 | v1 *= 3; |
---|
48 | sout | "?*=?:" | v1; |
---|
49 | |
---|
50 | { |
---|
51 | vec2(int) u = {1, -5}; |
---|
52 | vec2(int) v = {2, 3}; |
---|
53 | sout | "?*?(vec)" | (u * v); |
---|
54 | sout | "?*=?(vec)" | (u *= v); |
---|
55 | } |
---|
56 | |
---|
57 | v1 = (vec2(int)){21, -10}; |
---|
58 | sout | "?/?:" | (v1 / 3); |
---|
59 | |
---|
60 | v1 /= 3; |
---|
61 | sout | "?/=?:" | v1; |
---|
62 | |
---|
63 | { |
---|
64 | vec2(int) u = {11, -5}; |
---|
65 | vec2(int) v = {2, 3}; |
---|
66 | sout | "?/?(vec)" | (u / v); |
---|
67 | sout | "?/=?(vec)" | (u /= v); |
---|
68 | } |
---|
69 | |
---|
70 | { |
---|
71 | vec2(int) u = {1, -3}; |
---|
72 | sout | "++?" | ++u; |
---|
73 | } |
---|
74 | { |
---|
75 | vec2(int) u = {1, -3}; |
---|
76 | sout | "--?" | ++u; |
---|
77 | } |
---|
78 | { |
---|
79 | vec2(int) u = {1, -3}; |
---|
80 | sout | "?++(part 1)" | u++; |
---|
81 | sout | "?++(part 2)" | u; |
---|
82 | } |
---|
83 | { |
---|
84 | vec2(int) u = {1, -3}; |
---|
85 | sout | "?--(part 1)" | u--; |
---|
86 | sout | "?--(part 2)" | u; |
---|
87 | } |
---|
88 | |
---|
89 | // % |
---|
90 | { |
---|
91 | vec2(int) u = {-12, 123}; |
---|
92 | sout | "?%?(int)" | (u % 2); |
---|
93 | sout | "?%=?(int)" | (u %= 2); |
---|
94 | } |
---|
95 | { |
---|
96 | vec2(int) u = {-12, 27}; |
---|
97 | vec2(int) v = {5, 4}; |
---|
98 | sout | "?%?(vec)" | (u % v); |
---|
99 | sout | "?%=?(vec)" | (u %= v); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | // & |
---|
104 | { |
---|
105 | vec2(int) u = {5, 8}; |
---|
106 | sout | "?&?(int)" | (u & (1 << 3)); |
---|
107 | sout | "?&=?(int)" | (u &= (1 << 3)); |
---|
108 | } |
---|
109 | { |
---|
110 | vec2(int) u = {5, 6}; |
---|
111 | vec2(int) v = {3, 7}; |
---|
112 | sout | "?&?(vec)" | (u & v); |
---|
113 | sout | "?&=?(vec)" | (u &= v); |
---|
114 | } |
---|
115 | |
---|
116 | // | |
---|
117 | { |
---|
118 | vec2(int) u = {5, 1}; |
---|
119 | sout | "?|?(int)" | (u | 2); |
---|
120 | sout | "?|=?(int)" | (u |= 2); |
---|
121 | } |
---|
122 | { |
---|
123 | vec2(int) u = {5, 1}; |
---|
124 | vec2(int) v = {2, 1}; |
---|
125 | sout | "?|?(vec)" | (u | v); |
---|
126 | sout | "?|=?(vec)" | (u |= v); |
---|
127 | } |
---|
128 | |
---|
129 | // ^ |
---|
130 | { |
---|
131 | vec2(int) u = {9, 5}; |
---|
132 | sout | "?^?(int)" | (u ^ 5); |
---|
133 | sout | "?^=?(int)" | (u ^= 5); |
---|
134 | } |
---|
135 | { |
---|
136 | vec2(int) u = {9, 5}; |
---|
137 | vec2(int) v = {5, 0}; |
---|
138 | sout | "?^?(vec)" | (u ^ v); |
---|
139 | sout | "?^=?(vec)" | (u ^= v); |
---|
140 | } |
---|
141 | |
---|
142 | // << |
---|
143 | { |
---|
144 | vec2(int) u = {2, 1}; |
---|
145 | sout | "?<<?(int)" | (u << 1); |
---|
146 | sout | "?<<=?(int)" | (u <<= 1); |
---|
147 | } |
---|
148 | { |
---|
149 | vec2(int) u = {1, 1}; |
---|
150 | vec2(int) v = {5, 2}; |
---|
151 | sout | "?<<?(vec)" | (u << v); |
---|
152 | sout | "?<<=?(vec)" | (u <<= v); |
---|
153 | } |
---|
154 | |
---|
155 | // >> |
---|
156 | { |
---|
157 | vec2(int) u = {2, 1}; |
---|
158 | sout | "?>>?(int)" | (u >> 1); |
---|
159 | sout | "?>>=?(int)" | (u >>= 1); |
---|
160 | } |
---|
161 | { |
---|
162 | vec2(int) u = {5, 7}; |
---|
163 | vec2(int) v = {1, 2}; |
---|
164 | sout | "?>>?(vec)" | (u >> v); |
---|
165 | sout | "?>>=?(vec)" | (u >>= v); |
---|
166 | } |
---|
167 | |
---|
168 | // ~ |
---|
169 | { |
---|
170 | vec2(int) u = {5, 2}; |
---|
171 | sout | "~?" | (~u); |
---|
172 | } |
---|
173 | |
---|
174 | v1 = (vec2(int)){2, 3}; |
---|
175 | v2 = (vec2(int)){-3, 2}; |
---|
176 | sout | "dot_1:" | dot(v1, v2); |
---|
177 | |
---|
178 | v2 = (vec2(int)){13, 2}; |
---|
179 | sout | "dot_2:" | dot(v1, v2); |
---|
180 | |
---|
181 | v1 = (vec2(int)){4, 3}; |
---|
182 | sout | "length_squared:" | length_squared(v1); |
---|
183 | |
---|
184 | vec2(int) geometric_normal = {5,6}; |
---|
185 | vec2(int) perturbed_normal = {4,5}; |
---|
186 | vec2(int) eyeline = {-1,0}; |
---|
187 | sout | "faceforward_nochange:" | faceforward(perturbed_normal, eyeline, geometric_normal); |
---|
188 | |
---|
189 | eyeline = (vec2(int)){1,0}; |
---|
190 | sout | "faceforward_flip:" | faceforward(perturbed_normal, eyeline, geometric_normal); |
---|
191 | } |
---|