Changeset 9a83ccd


Ignore:
Timestamp:
Nov 11, 2019, 2:41:41 PM (5 years ago)
Author:
Dmitry Kobets <dkobets@…>
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)
Message:

Add sout override for vec2

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/vector.hfa

    r8bbdfdd r9a83ccd  
    11#pragma once
    2 #include <math.h>
    3 
     2#include "math.hfa"
     3#include <iostream.hfa>
    44
    55//---------------------- Vector Types ----------------------
    66// TODO: make generic, as per glm
     7
    78
    89struct vec2 {
     
    1011};
    1112
    12 //---------------------- Geometric Functions ----------------------
    13 // These functions implement the Geometric Functions section of GLSL
     13void ?{}( vec2 & v, float x, float y) {
     14    v.[x, y] = [x, y];
     15}
    1416
    15 static inline float dot(const vec2& v, const vec2& u) {
    16     return v.x * u.x + v.y * u.y;
     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;
    1737}
    1838
  • main.cfa

    r8bbdfdd r9a83ccd  
     1/* #include <iostream.hfa> */
    12#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
    312
    413int main() {
    514    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); */
    1033}
Note: See TracChangeset for help on using the changeset viewer.