Index: libcfa/src/vector.hfa
===================================================================
--- libcfa/src/vector.hfa	(revision a39fd1d24a7ecffae8adaa8089451befbaddc787)
+++ libcfa/src/vector.hfa	(revision e1a094572e4c0697c5a61f32992b2bd1c00fc94a)
@@ -2,7 +2,4 @@
 #include <math.hfa>
 #include <iostream.hfa>
-
-//---------------------- Vector Types ----------------------
-// TODO: make generic, as per glm
 
 struct vec2 {
@@ -10,8 +7,78 @@
 };
 
+// Constructors
+
 void ?{}( vec2 & v, float x, float y) {
     v.[x, y] = [x, y];
 }
+void ?{}(vec2& vec, zero_t) with (vec) {
+    x = y = 0;
+}
+void ?{}(vec2& vec, float val) with (vec) {
+    x = y = val;
+}
+void ?{}(vec2& vec, vec2& other) with (vec) {
+    [x,y] = other.[x,y];
+}
 
+// Assignment
+void ?=?(vec2& vec, const vec2& other) with (vec) {
+    [x,y] = other.[x,y];
+}
+
+// Primitive mathematical operations
+
+// Subtraction
+vec2 ?-?(const vec2& u, const vec2& v) {
+    return [u.x - v.x, u.y - v.y];
+}
+vec2& ?-=?(vec2& u, const vec2& v) {
+    u = u - v;
+    return u;
+}
+vec2 -?(const vec2& v) with (v) {
+    return [-x, -y];
+}
+
+// Addition
+vec2 ?+?(const vec2& u, const vec2& v) {
+    return [u.x + v.x, u.y + v.y];
+}
+vec2& ?+=?(vec2& u, const vec2& v) {
+    u = u + v;
+    return u;
+}
+
+// Scalar Multiplication
+vec2 ?*?(const vec2& v, float scalar) with (v) {
+    return [x * scalar, y * scalar];
+}
+vec2& ?*=?(vec2& v, float scalar) with (v) {
+    v = v * scalar;
+    return v;
+}
+vec2 ?*?(float scalar, const vec2& v) {
+    return v * scalar;
+}
+
+
+// Scalar Division
+vec2 ?/?(const vec2& v, float scalar) with (v) {
+    return [x / scalar, y / scalar];
+}
+vec2& ?/=?(vec2& v, float scalar) with (v) {
+    v = v / scalar;
+    return v;
+}
+
+// Relational Operators
+bool ?==?(const vec2& u, const vec2& v) with (u) {
+    return x == v.x && y == v.y;
+}
+bool ?!=?(const vec2& u, const vec2& v) {
+    return !(u == v);
+}
+
+// Printing the vector (ostream)
 forall( dtype ostype | ostream( ostype ) ) {
     ostype & ?|?( ostype & os, const vec2& v) with (v) {
@@ -25,29 +92,6 @@
 }
 
-void ?{}(vec2& vec, zero_t) with (vec) {
-    x = y = 0;
-}
-void ?{}(vec2& vec, vec2& other) with (vec) {
-    [x,y] = other.[x,y];
-}
-
-vec2 ?-?(const vec2& u, const vec2& v) {
-    return [u.x - v.x, u.y - v.y];
-}
-vec2 ?*?(const vec2& v, float scalar) with (v) {
-    return [x * scalar, y * scalar];
-}
-vec2 ?*?(float scalar, const vec2& v) {
-    return v * scalar;
-}
-vec2 ?/?(const vec2& v, float scalar) with (v) {
-    return [x / scalar, y / scalar];
-}
-vec2 -?(const vec2& v) with (v) {
-    return [-x, -y];
-}
-
 /* //---------------------- Geometric Functions ---------------------- */
-/* // These functions implement the Geometric Functions section of GLSL */
+/* // These functions implement the Geometric Functions section of GLSL for 2D vectors*/
 
 static inline float dot(const vec2& u, const vec2& v) {
@@ -59,5 +103,4 @@
 }
 
-// Returns the distance betwwen v1 and v2, i.e., length(p0 - p1).
 static inline float distance(const vec2& v1, const vec2& v2) {
     return length(v1 - v2);
@@ -65,11 +108,8 @@
 
 static inline vec2 normalize(const vec2& v) {
-    // TODO(dkobets) -- show them inversesqrt
-    // https://github.com/g-truc/glm/blob/269ae641283426f7f84116f2fe333472b9c914c9/glm/detail/func_exponential.inl
-    /* return v * inversesqrt(dot(v, v)); */
     return v / sqrt(dot(v, v));
 }
 
-// project vector u onto vector v
+// Project vector u onto vector v
 static inline vec2 project(const vec2& u, const vec2& v) {
     vec2 v_norm = normalize(v);
@@ -77,13 +117,11 @@
 }
 
-/* returns the reflection direction : v - 2.0 * project(v, n)
- * for incident vector v and surface normal n
- */
+// Reflect incident vector v with respect to surface with normal n
 static inline vec2 reflect(const vec2& v, const vec2& n) {
     return v - 2 * project(v, n);
 }
 
-// incident vector v, surface normal n
-// eta = ratio of indices of refraction between starting material and
+// Refract incident vector v with respect to surface with normal n
+// 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) {
@@ -96,3 +134,11 @@
 }
 
-// TODO: I don't quite understand the use-case for faceforward
+// Used to render perturbed surfaces by ensuring that a perturbed normal
+// is pointing in the same direction as the geometric normal of the
+// surface.
+// 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;
+}
