Changeset af0bf71


Ignore:
Timestamp:
Nov 11, 2019, 2:41:41 PM (2 years ago)
Author:
Dmitry Kobets <dkobets@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
0856a96
Parents:
e1a0945
git-author:
Dmitry Kobets <dkobets@…> (10/11/19 15:57:39)
git-committer:
Dmitry Kobets <dkobets@…> (11/11/19 14:41:41)
Message:

Small refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/vector.hfa

    re1a0945 raf0bf71  
    66    float x, y;
    77};
     8
     9static inline {
    810
    911// Constructors
     
    1820    x = y = val;
    1921}
    20 void ?{}(vec2& vec, vec2& other) with (vec) {
     22void ?{}(vec2& vec, const vec2& other) with (vec) {
    2123    [x,y] = other.[x,y];
    2224}
     
    5456    return [x * scalar, y * scalar];
    5557}
     58vec2 ?*?(float scalar, const vec2& v) {
     59    return v * scalar;
     60}
    5661vec2& ?*=?(vec2& v, float scalar) with (v) {
    5762    v = v * scalar;
    5863    return v;
    59 }
    60 vec2 ?*?(float scalar, const vec2& v) {
    61     return v * scalar;
    6264}
    6365
     
    9597/* // These functions implement the Geometric Functions section of GLSL for 2D vectors*/
    9698
    97 static inline float dot(const vec2& u, const vec2& v) {
     99float dot(const vec2& u, const vec2& v) {
    98100    return u.x * v.x + u.y * v.y;
    99101}
    100102
    101 static inline float length(const vec2& v) {
     103float length(const vec2& v) {
    102104   return sqrt(dot(v, v));
    103105}
    104106
    105 static inline float distance(const vec2& v1, const vec2& v2) {
     107float length_squared(const vec2& v) {
     108   return dot(v, v);
     109}
     110
     111float distance(const vec2& v1, const vec2& v2) {
    106112    return length(v1 - v2);
    107113}
    108114
    109 static inline vec2 normalize(const vec2& v) {
     115vec2 normalize(const vec2& v) {
    110116    return v / sqrt(dot(v, v));
    111117}
    112118
    113119// Project vector u onto vector v
    114 static inline vec2 project(const vec2& u, const vec2& v) {
     120vec2 project(const vec2& u, const vec2& v) {
    115121    vec2 v_norm = normalize(v);
    116122    return v_norm * dot(u, v_norm);
     
    118124
    119125// Reflect incident vector v with respect to surface with normal n
    120 static inline vec2 reflect(const vec2& v, const vec2& n) {
     126vec2 reflect(const vec2& v, const vec2& n) {
    121127    return v - 2 * project(v, n);
    122128}
     
    125131// eta is the ratio of indices of refraction between starting material and
    126132// entering material (i.e., from air to water, eta = 1/1.33)
    127 static inline vec2 refract(const vec2& v, const vec2& n, float eta) {
     133vec2 refract(const vec2& v, const vec2& n, float eta) {
    128134    float dotValue = dot(n, v);
    129     float k = 1 - eta * eta * (1 - dotValue * dotValue);
     135    float k = 1 - eta \ 2 * (1 - dotValue \ 2);
    130136    if (k < 0) {
    131137        return 0;
     
    134140}
    135141
    136 // Used to render perturbed surfaces by ensuring that a perturbed normal
    137 // is pointing in the same direction as the geometric normal of the
    138 // surface.
     142// Given a perturbed normal and a geometric normal,
     143// flip the perturbed normal if the geometric normal is pointing away
     144// from the observer.
    139145// n is the perturbed vector that we want to align
    140146// i is the incident vector
    141147// ng is the geometric normal of the surface
    142 static inline vec2 faceforward(const vec2& n, const vec2& i, float ng) {
    143     return dot(n, i) < 0 ? ng : -ng;
     148vec2 faceforward(const vec2& n, const vec2& i, const vec2& ng) {
     149    return dot(ng, i) < 0 ? n : -n;
    144150}
     151
     152}
Note: See TracChangeset for help on using the changeset viewer.