source: tests/vector_math/vec2_float.cfa @ 960665c

Last change on this file since 960665c 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: 2.9 KB
Line 
1#include <vec/vec2.hfa>
2#include <fstream.hfa>
3
4int main(void) {
5    vec2(float) v1 = {1.f,2.f};
6    sout | "ctor(x,y):" | v1;
7
8    vec2(float) v2 = v1;
9    sout | "copy ctor:" | v2;
10
11    v2 = (vec2(float)){3.f, 4.2f};
12    sout | "assignment:" | v2;
13
14    v2 = v1;
15    sout | "move assignment:" | v2;
16
17    vec2(float) v3 = 0;
18    sout | "zero-init:" | v3;
19
20    v1 = 0;
21    sout | "zero-assign:" | v1;
22
23    vec2(float) v4 = {1.23f};
24    sout | "fill-ctor:" | v4;
25
26    v1 = (vec2(float)){1.23f, 3.43f};
27    sout | "?-?:" | (v1 - (vec2(float)){1.21f,3});
28
29    v1 -= (vec2(float)){-2, 10};
30    sout | "?-=?:" | v1;
31
32    v1 = -v1;
33    sout | "-?:" | v1;
34
35    v1 = (vec2(float)){1.5f, 2.75f};
36    sout | "?+?:" | (v1 + (vec2(float)){0.8f, -0.3f});
37
38    v1 += (vec2(float)){0.8f, -0.3f};
39    sout | "?+=?:" | v1;
40
41    v1 = (vec2(float)){1.5f, 2.75f};
42    sout | "v*s:" | v1 * 3.f;
43
44    sout | "s*v:" | 3.f * v1;
45
46    v1 *= 3;
47    sout | "?*=?:" | v1;
48
49    {
50        vec2(float) u = {1.2f, -5.8f};
51        vec2(float) v = {2.2f, 3};
52        sout | "?*?(vec)" | (u * v);
53        sout | "?*=?(vec)" | (u *= v);
54    }
55
56
57    v1 = (vec2(float)){2, -0.1f};
58    sout | "?/?:" | (v1 / 3);
59
60    v1 /= 3;
61    sout | "?/=?:" | v1;
62
63    {
64        vec2(float) u = {1.2f, -5.8f};
65        vec2(float) v = {2.2f, 3};
66        sout | "?/?(vec)" | (u / v);
67        sout | "?/=?(vec)" | (u /= v);
68    }
69
70    {
71        vec2(float) u = {1.2f, -3.5f};
72        sout | "++?" | ++u;
73    }
74    {
75        vec2(float) u = {1.2f, -3.5f};
76        sout | "--?" | ++u;
77    }
78    {
79        vec2(float) u = {1.2f, -3.5f};
80        sout | "?++(part 1)" | u++;
81        sout | "?++(part 2)" | u;
82    }
83    {
84        vec2(float) u = {1.2f, -3.5f};
85        sout | "?--(part 1)" | u--;
86        sout | "?--(part 2)" | u;
87    }
88
89    v1 = (vec2(float)){2, 3};
90    v2 = (vec2(float)){-3, 2};
91    sout | "dot_1:" | dot(v1, v2);
92
93    v2 = (vec2(float)){1.3f, 2};
94    sout | "dot_2:" | dot(v1, v2);
95
96    v1 = (vec2(float)){4, 3};
97    sout | "length:" | length(v1);
98
99    sout | "length_squared:" | length_squared(v1);
100
101    v2 = (vec2(float)){6, -3.2f};
102    sout | "distance:" | distance(v1, v2);
103
104    sout | "normalize:" | normalize(v2);
105
106    v1 = (vec2(float)){1,0};
107    sout | "normalize_2:" | normalize(v1);
108
109    sout | "project:" | project((vec2(float)){5,6}, (vec2(float)){1, 0});
110    sout | "project_2:" | project((vec2(float)){5,6}, (vec2(float)){1, 1});
111
112    v1 = (vec2(float)){5,6};
113    v2 = (vec2(float)){1,0};
114    sout | "reflect:" | reflect(v1,v2);
115
116    v2 = (vec2(float)){0,-1};
117    sout | "refract:" | refract(v1,normalize(v2),1.f);
118    sout | "refract:" | refract(v1,normalize(v2),1.f/1.33f);
119
120    vec2(float) geometric_normal = {5,6};
121    vec2(float) perturbed_normal = {4,5.5f};
122    vec2(float) eyeline = {-1,0.002f};
123    sout | "faceforward_nochange:" | faceforward(perturbed_normal, eyeline, geometric_normal);
124
125    eyeline = (vec2(float)){1,0.002f};
126    sout | "faceforward_flip:" | faceforward(perturbed_normal, eyeline, geometric_normal);
127}
Note: See TracBrowser for help on using the repository browser.