     // Create all half-edges without setting their 'next' property yet, and keep a mapping between
     // origins and half-edges.
     for edge in edges {
-        let a = HalfEdge(origin: edge.0)
-        let b = HalfEdge(origin: edge.1)
-        a.twin = b
-        b.twin = a
-        halfEdges += [a, b]
+        let he1 = HalfEdge(origin: edge.0)
+        let he2 = HalfEdge(origin: edge.1)
+        he1.twin = he2
+        he2.twin = he1
+        halfEdges += [he1, he2]
     }
 
     // Sort the half-edges by origin first, and then by clockwise order.

    var dirty = halfEdges

    while !dirty.isEmpty {
        let halfEdge = dirty.removeLast()
        halfEdge.dirty = false

        if halfEdge.locallyDelaunay {
            continue
        }

        halfEdge.flip()

        let neighbors = [halfEdge.next!, halfEdge.prev!, halfEdge.twin.next!, halfEdge.twin.prev!]
        for neighbor in neighbors where !neighbor.dirty {
            neighbor.dirty = true
            dirty.append(neighbor)

    ]) > 0
}

// Compare a and b based on the clockwise angle the rays origin->a and origin->b form relatively to
// to the ray going straight up from origin (i.e. the "12 o'clock").
// We can ignore some edges cases because we know that for this application:
// - a, b and origin are always distinct
// - if a, b and origin are collinear then origin must be the middle point
func compareClockwise(a: Point, lessThan b: Point, origin: Point) -> Bool {
    // Handle case where a and b are not on the same vertical half of the plane.
    if a.x >= origin.x && b.x < origin.x {
        return true
    }
    if b.x >= origin.x && a.x < origin.x {
        return false
    }

    switch direction(a, origin, b) {
    case .Collinear:
        //  One of a, b is on the "12 o'clock" and the other is on the "6 o'clock".
        return a.y > b.y

    case .CounterClockwise:
        return true
