Ignore:
File:
1 edited

Legend:

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

    r250dbae rfd54fef  
     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
    116#pragma once
    217
    318#include <math.hfa>
    419
    5 trait fromint(otype T) {
     20trait fromint(T) {
    621    void ?{}(T&, int);
    722};
    8 trait zeroinit(otype T) {
     23trait zeroinit(T) {
    924    void ?{}(T&, zero_t);
    1025};
    11 trait zero_assign(otype T) {
     26trait zero_assign(T) {
    1227    T ?=?(T&, zero_t);
    1328};
    14 trait subtract(otype T) {
     29trait subtract(T) {
    1530    T ?-?(T, T);
    1631};
    17 trait negate(otype T) {
     32trait negate(T) {
    1833    T -?(T);
    1934};
    20 trait add(otype T) {
     35trait add(T) {
    2136    T ?+?(T, T);
    2237};
    23 trait multiply(otype T) {
     38trait multiply(T) {
    2439    T ?*?(T, T);
    2540};
    26 trait divide(otype T) {
     41trait divide(T) {
    2742    T ?/?(T, T);
    2843};
    29 trait lessthan(otype T) {
     44trait lessthan(T) {
    3045    int ?<?(T, T);
    3146};
    32 trait equality(otype T) {
     47trait equality(T) {
    3348    int ?==?(T, T);
    3449};
    35 trait sqrt(otype T) {
     50trait sqrt(T) {
    3651    T sqrt(T);
    3752};
     
    5368}
    5469
    55 trait dottable(otype V, otype T) {
     70trait dottable(V, T) {
    5671    T dot(V, V);
    5772};
     
    5974static inline {
    6075
    61 forall(otype T | sqrt(T), otype V | dottable(V, T))
     76forall(T | sqrt(T), V | dottable(V, T))
    6277T length(V v) {
    6378   return sqrt(dot(v, v));
    6479}
    6580
    66 forall(otype T, otype V | dottable(V, T))
     81forall(T, V | dottable(V, T))
    6782T length_squared(V v) {
    6883   return dot(v, v);
    6984}
    7085
    71 forall(otype T, otype V | { T length(V); } | subtract(V))
     86forall(T, V | { T length(V); } | subtract(V))
    7287T distance(V v1, V v2) {
    7388    return length(v1 - v2);
    7489}
    7590
    76 forall(otype T, otype V | { T length(V); V ?/?(V, T); })
     91forall(T, V | { T length(V); V ?/?(V, T); })
    7792V normalize(V v) {
    7893    return v / length(v);
     
    8095
    8196// Project vector u onto vector v
    82 forall(otype T, otype V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
     97forall(T, V | dottable(V, T) | { V normalize(V); V ?*?(V, T); })
    8398V project(V u, V v) {
    8499    V v_norm = normalize(v);
     
    87102
    88103// Reflect incident vector v with respect to surface with normal n
    89 forall(otype T | fromint(T), otype V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
     104forall(T | fromint(T), V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })
    90105V reflect(V v, V n) {
    91106    return v - (T){2} * project(v, n);
     
    96111// entering material (i.e., from air to water, eta = 1/1.33)
    97112// v and n must already be normalized
    98 forall(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); })
     113forall(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); })
    100115V refract(V v, V n, T eta) {
    101116    T dotValue = dot(n, v);
     
    113128// i is the incident vector
    114129// ng is the geometric normal of the surface
    115 forall(otype T | lessthan(T) | zeroinit(T), otype V | dottable(V, T) | negate(V))
     130forall(T | lessthan(T) | zeroinit(T), V | dottable(V, T) | negate(V))
    116131V faceforward(V n, V i, V ng) {
    117132    return dot(ng, i) < (T){0} ? n : -n;
Note: See TracChangeset for help on using the changeset viewer.