Changeset 9a83ccd
- Timestamp:
- Nov 11, 2019, 2:41:41 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 44f41997
- Parents:
- 8bbdfdd
- git-author:
- Dmitry Kobets <dkobets@…> (10/04/19 14:20:38)
- git-committer:
- Dmitry Kobets <dkobets@…> (11/11/19 14:41:41)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/vector.hfa
r8bbdfdd r9a83ccd 1 1 #pragma once 2 #include <math.h>3 2 #include "math.hfa" 3 #include <iostream.hfa> 4 4 5 5 //---------------------- Vector Types ---------------------- 6 6 // TODO: make generic, as per glm 7 7 8 8 9 struct vec2 { … … 10 11 }; 11 12 12 //---------------------- Geometric Functions ---------------------- 13 // These functions implement the Geometric Functions section of GLSL 13 void ?{}( vec2 & v, float x, float y) { 14 v.[x, y] = [x, y]; 15 } 14 16 15 static inline float dot(const vec2& v, const vec2& u) { 16 return v.x * u.x + v.y * u.y; 17 forall( 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 28 vec2 ?-?(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 35 static inline float dot(const vec2& u, const vec2& v) { 36 return u.x * v.x + u.y * v.y; 17 37 } 18 38 -
main.cfa
r8bbdfdd r9a83ccd 1 /* #include <iostream.hfa> */ 1 2 #include <fstream.hfa> 2 #include <vector.hfa> 3 #include "libcfa/src/vector.hfa" 4 5 /* [float, float] tuple(const vec2& v) { */ 6 /* return [v.x, v.y]; */ 7 /* } */ 8 9 10 11 3 12 4 13 int main() { 5 14 vec2 v1 = {1,2}; 6 sout | length(v1); 7 8 vec2 v2 = {1,2}; 9 sout | dot(v1, v2); 15 sout | true; 16 sout | v1; 17 sout | "wot"; 18 sout | ((vec2){1,2} - (vec2){3,2}); 19 sout | "a" | "b"; 20 /* sout | nlOff; */ 21 /* sout | sepOff; */ 22 /* sout | nlOff; */ 23 /* #<{(| sout | nlOff; |)}># */ 24 /* */ 25 /* vec2 v1 = {1,2}; */ 26 /* sout | "w" | 2.2 | "at" | v1; */ 27 /* sout | length(v1); */ 28 /* */ 29 /* vec2 v2 = {1,1}; */ 30 /* sout | dot(v1, v2); */ 31 /* */ 32 /* sout | (v2 - v1) | " " | (v1 - v2); */ 10 33 }
Note: See TracChangeset
for help on using the changeset viewer.