         self.y = y
         self.z = z
     }
+    
+    func pointAbs() -> [Double] {
+        return [abs(x), abs(y), abs(z)]
+    }
+    
+    func largestAbsComponent() -> Int {
+        let temp = pointAbs()
+        if temp[0] > temp[1] {
+            if temp[0] > temp[2] {
+                return 0
+            } else {
+                return 2
+            }
+        } else {
+            if temp[1] > temp[2] {
+                return 1
+            } else {
+                return 2
+            }
+        }
+    }
+    
+    func dotProd(o: S2Point) -> Double {
+        return x * o.x + y * o.y + z * o.z
+    }
+    
+    static func faceUvToXyz(face: Int, u: Double, v: Double) -> S2Point {
+        let uDouble = Double(u)
+        let vDouble = Double(v)
+        if face == 0 {
+            return S2Point(x: 1, y: uDouble, z: vDouble)
+        } else if face == 1 {
+            return S2Point(x: -uDouble, y: 1, z: vDouble)
+        } else if face == 2 {
+            return S2Point(x: -uDouble, y: -vDouble, z: 1)
+        } else if face == 3 {
+            return S2Point(x: -1, y: -vDouble, z: -uDouble)
+        } else if face == 4 {
+            return S2Point(x: vDouble, y: -1, z: -uDouble)
+        } else {
+            return S2Point(x: vDouble, y: uDouble, z: -1)
+        }
+    }
 }
-
 
 class S2LatLon {
     let lat: Double
     let lon: Double
-    
+ 
     init(latDegrees: Double, lonDegrees: Double) {
         lat = latDegrees * M_PI / 180
         lon = lonDegrees * M_PI / 180

}

class S2CellId {
    // projection types
    var LINEAR_PROJECTION: Int = 0
    var TAN_PROJECTION: Int = 1
    var QUADRATIC_PROJECTION: Int = 2
    
    // current projection used
    var PROJECTION: Int = 2
    
    var FACE_BITS: Int = 3
    var NUM_FACES: Int = 6
    
    var MAX_LEVEL: Int = 30
    var POS_BITS: Int = 2 * 30 + 1
    var MAX_SIZE: Int = 1 << 30
    
    var WRAP_OFFSET: UInt64 = 6 << (2 * (30 + 1))
}

import Foundation


enum S2Projection {
    case Linear
    case Tan
    case Quadratic
}

enum S2Constants {
    static let maxLevel = 30
    static let posBits = 2 * (S2Constants.maxLevel + 1)
    static let maxSize = 1 << S2Constants.maxLevel
    static let swapMask = 0x01
    static let invertMask = 0x02
    static let lookupBits = 4
}

var lookupPos: [Int] = []

struct S2FaceUv {
    let face: Int
    let u: Double
    let v: Double
}

struct S2Uv {
    let u: Double
    let v: Double
}

class S2Point {
    let x: Double
    let y: Double
