Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/vec/vec.hfa

    rfd54fef r250dbae  
    1 //
    2 // Cforall Version 1.0.0 Copyright (C) 2021 University of Waterloo
    3 //
    4 // The contents of this file are covered under the licence agreement in the
    5 // file "LICENCE" distributed with Cforall.
    6 //
    7 // io/types.hfa --
    8 //
    9 // Author           : Dimitry Kobets
    10 // Created On       :
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     :
    14 //
    15 
    161#pragma once
    172
    183#include <math.hfa>
    194
    20 trait fromint(T) {
     5trait fromint(otype T) {
    216    void ?{}(T&, int);
    227};
    23 trait zeroinit(T) {
     8trait zeroinit(otype T) {
    249    void ?{}(T&, zero_t);
    2510};
    26 trait zero_assign(T) {
     11trait zero_assign(otype T) {
    2712    T ?=?(T&, zero_t);
    2813};
    29 trait subtract(T) {
     14trait subtract(otype T) {
    3015    T ?-?(T, T);
    3116};
    32 trait negate(T) {
     17trait negate(otype T) {
    3318    T -?(T);
    3419};
    35 trait add(T) {
     20trait add(otype T) {
    3621    T ?+?(T, T);
    3722};
    38 trait multiply(T) {
     23trait multiply(otype T) {
    3924    T ?*?(T, T);
    4025};
    41 trait divide(T) {
     26trait divide(otype T) {
    4227    T ?/?(T, T);
    4328};
    44 trait lessthan(T) {
     29trait lessthan(otype T) {
    4530    int ?<?(T, T);
    4631};
    47 trait equality(T) {
     32trait equality(otype T) {
    4833    int ?==?(T, T);
    4934};
    50 trait sqrt(T) {
     35trait sqrt(otype T) {
    5136    T sqrt(T);
    5237};
     
    6853}
    6954
    70 trait dottable(V, T) {
     55trait dottable(otype V, otype T) {
    7156    T dot(V, V);
    7257};
     
    7459static inline {
    7560
    76 forall(T | sqrt(T), V | dottable(V, T))
     61forall(otype T | sqrt(T), otype V | dottable(V, T))
    7762T length(V v) {
    7863   return sqrt(dot(v, v));
    7964}
    8065
    81 forall(T, V | dottable(V, T))
     66forall(otype T, otype V | dottable(V, T))
    8267T length_squared(V v) {
    8368   return dot(v, v);
    8469}
    8570
    86 forall(T, V | { T length(V); } | subtract(V))
     71forall(otype T, otype V | { T length(V); } | subtract(V))
    8772T distance(V v1, V v2) {
    8873    return length(v1 - v2);
    8974}
    9075
    91 forall(T, V | { T length(V); V ?/?(V, T); })
     76forall(otype T, otype V | { T length(V); V ?/?(V, T); })
    9277V normalize(V v) {
    9378    return v / length(v);
     
    9580
    9681// Project vector u onto vector v
    97 forall(T, V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
     82forall(otype T, otype V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
    9883V project(V u, V v) {
    9984    V v_norm = normalize(v);
     
    10287
    10388// Reflect incident vector v with respect to surface with normal n
    104 forall(T | fromint(T), V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
     89forall(otype T | fromint(T), otype V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
    10590V reflect(V v, V n) {
    10691    return v - (T){2} * project(v, n);
     
    11196// entering material (i.e., from air to water, eta = 1/1.33)
    11297// v and n must already be normalized
    113 forall(T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),
    114        V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })
     98forall(otype T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),
     99       otype V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })
    115100V refract(V v, V n, T eta) {
    116101    T dotValue = dot(n, v);
     
    128113// i is the incident vector
    129114// ng is the geometric normal of the surface
    130 forall(T | lessthan(T) | zeroinit(T), V | dottable(V, T) | negate(V))
     115forall(otype T | lessthan(T) | zeroinit(T), otype V | dottable(V, T) | negate(V))
    131116V faceforward(V n, V i, V ng) {
    132117    return dot(ng, i) < (T){0} ? n : -n;
Note: See TracChangeset for help on using the changeset viewer.