source: tests/vector_math/vec2_int.cfa @ 1b64344

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 1b64344 was aefb247, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Changed vector tests to properly refer to vecX.hfa like normal language headers

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[aefb247]1#include <vec/vec2.hfa>
[1188195]2#include <fstream.hfa>
3#include <limits.hfa>
4
5int 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
[2444324]12    v2 = (vec2(int)){3, 4};
[1188195]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
[2444324]24    vec2(int) v4 = {123};
[1188195]25    sout | "fill-ctor:" | v4;
26
[2444324]27    v1 = (vec2(int)){1, 3};
28    sout | "?-?:" | (v1 - (vec2(int)){1003, -14});
[1188195]29
[2444324]30    v1 -= (vec2(int)){1003, -14};
[1188195]31    sout | "?-=?:" | v1;
32
33    v1 = -v1;
34    sout | "-?:" | v1;
35
[2444324]36    v1 = (vec2(int)){1, 3};
37    sout | "?+?:" | (v1 + (vec2(int)){1003, -14});
[1188195]38
[2444324]39    v1 += (vec2(int)){1003, -14};
[1188195]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
[7799f79]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
[2444324]57    v1 = (vec2(int)){21, -10};
[1188195]58    sout | "?/?:" | (v1 / 3);
59
60    v1 /= 3;
61    sout | "?/=?:" | v1;
62
[7799f79]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
[0b3cdad]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
[7799f79]168    // ~
169    {
170        vec2(int) u = {5, 2};
171        sout | "~?" | (~u);
172    }
173
[1188195]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};
[2444324]185    vec2(int) perturbed_normal = {4,5};
186    vec2(int) eyeline = {-1,0};
[1188195]187    sout | "faceforward_nochange:" | faceforward(perturbed_normal, eyeline, geometric_normal);
188
[2444324]189    eyeline = (vec2(int)){1,0};
[1188195]190    sout | "faceforward_flip:" | faceforward(perturbed_normal, eyeline, geometric_normal);
191}
Note: See TracBrowser for help on using the repository browser.