Index: libcfa/src/vector.hfa
===================================================================
--- libcfa/src/vector.hfa	(revision e1a094572e4c0697c5a61f32992b2bd1c00fc94a)
+++ libcfa/src/vector.hfa	(revision af0bf717a77bfa4e23a4aed6ede389abab2b7627)
@@ -6,4 +6,6 @@
     float x, y;
 };
+
+static inline {
 
 // Constructors
@@ -18,5 +20,5 @@
     x = y = val;
 }
-void ?{}(vec2& vec, vec2& other) with (vec) {
+void ?{}(vec2& vec, const vec2& other) with (vec) {
     [x,y] = other.[x,y];
 }
@@ -54,10 +56,10 @@
     return [x * scalar, y * scalar];
 }
+vec2 ?*?(float scalar, const vec2& v) {
+    return v * scalar;
+}
 vec2& ?*=?(vec2& v, float scalar) with (v) {
     v = v * scalar;
     return v;
-}
-vec2 ?*?(float scalar, const vec2& v) {
-    return v * scalar;
 }
 
@@ -95,22 +97,26 @@
 /* // These functions implement the Geometric Functions section of GLSL for 2D vectors*/
 
-static inline float dot(const vec2& u, const vec2& v) {
+float dot(const vec2& u, const vec2& v) {
     return u.x * v.x + u.y * v.y;
 }
 
-static inline float length(const vec2& v) {
+float length(const vec2& v) {
    return sqrt(dot(v, v));
 }
 
-static inline float distance(const vec2& v1, const vec2& v2) {
+float length_squared(const vec2& v) {
+   return dot(v, v);
+}
+
+float distance(const vec2& v1, const vec2& v2) {
     return length(v1 - v2);
 }
 
-static inline vec2 normalize(const vec2& v) {
+vec2 normalize(const vec2& v) {
     return v / sqrt(dot(v, v));
 }
 
 // Project vector u onto vector v
-static inline vec2 project(const vec2& u, const vec2& v) {
+vec2 project(const vec2& u, const vec2& v) {
     vec2 v_norm = normalize(v);
     return v_norm * dot(u, v_norm);
@@ -118,5 +124,5 @@
 
 // Reflect incident vector v with respect to surface with normal n
-static inline vec2 reflect(const vec2& v, const vec2& n) {
+vec2 reflect(const vec2& v, const vec2& n) {
     return v - 2 * project(v, n);
 }
@@ -125,7 +131,7 @@
 // eta is the ratio of indices of refraction between starting material and
 // entering material (i.e., from air to water, eta = 1/1.33)
-static inline vec2 refract(const vec2& v, const vec2& n, float eta) {
+vec2 refract(const vec2& v, const vec2& n, float eta) {
     float dotValue = dot(n, v);
-    float k = 1 - eta * eta * (1 - dotValue * dotValue);
+    float k = 1 - eta \ 2 * (1 - dotValue \ 2);
     if (k < 0) {
         return 0;
@@ -134,11 +140,13 @@
 }
 
-// Used to render perturbed surfaces by ensuring that a perturbed normal
-// is pointing in the same direction as the geometric normal of the
-// surface.
+// Given a perturbed normal and a geometric normal,
+// flip the perturbed normal if the geometric normal is pointing away
+// from the observer.
 // n is the perturbed vector that we want to align
 // i is the incident vector
 // ng is the geometric normal of the surface
-static inline vec2 faceforward(const vec2& n, const vec2& i, float ng) {
-    return dot(n, i) < 0 ? ng : -ng;
+vec2 faceforward(const vec2& n, const vec2& i, const vec2& ng) {
+    return dot(ng, i) < 0 ? n : -n;
 }
+
+}
