source: libcfa/src/vector.hfa @ 9a83ccd

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 9a83ccd was 9a83ccd, checked in by Dmitry Kobets <dkobets@…>, 5 years ago

Add sout override for vec2

  • Property mode set to 100644
File size: 967 bytes
Line 
1#pragma once
2#include "math.hfa"
3#include <iostream.hfa>
4
5//---------------------- Vector Types ----------------------
6// TODO: make generic, as per glm
7
8
9struct vec2 {
10    float x, y;
11};
12
13void ?{}( vec2 & v, float x, float y) {
14    v.[x, y] = [x, y];
15}
16
17forall( dtype ostype | ostream( ostype ) ) {
18    ostype & ?|?( ostype & os, const vec2& v) with (v) {
19        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
20        fmt( os, "<%g,%g>", x, y);
21        return os;
22    }
23    void ?|?( ostype & os, const vec2 v ) {
24        (ostype &)(os | v); ends( os );
25    }
26}
27
28vec2 ?-?(const vec2& u, const vec2& v) {
29    return [u.x - v.x, u.y - v.y];
30}
31
32/* //---------------------- Geometric Functions ---------------------- */
33/* // These functions implement the Geometric Functions section of GLSL */
34
35static inline float dot(const vec2& u, const vec2& v) {
36    return u.x * v.x + u.y * v.y;
37}
38
39static inline float length(const vec2& v) {
40   return sqrt(dot(v, v));
41}
Note: See TracBrowser for help on using the repository browser.