     var dirty = halfEdges
 
     while !dirty.isEmpty {
-        let halfEdge = dirty.removeLast()
-        halfEdge.dirty = false
-
-        if halfEdge.locallyDelaunay {
+        let he = dirty.removeLast()
+        he.dirty = false
+
+        if he.locallyDelaunay {
             continue
         }
 
-        halfEdge.flip()
-
-        let neighbors = [halfEdge.next!, halfEdge.prev!, halfEdge.twin.next!, halfEdge.twin.prev!]
+        he.flip()
+
+        let neighbors = [he.next!, he.prev!, he.twin.next!, he.twin.prev!]
         for neighbor in neighbors where !neighbor.dirty {
             neighbor.dirty = true
             dirty.append(neighbor)

            compareClockwise($0.twin.origin, lessThan: $1.twin.origin, origin: $0.origin)
    }

    // For each pair (a, b) of half-edges with the same origin and in clockwise order, set the
    // 'next' property of a.twin to b. Remarks:
    // - We need to wrap and process the pair (last, first) of half-edges with the same origin.
    // - To avoid setting the 'next' property of half-edges that are on the outside of the convex
    //   hull, we need to check that the two half-edges form a triangle, i.e. that a-b form a
    //   counter-clockwise turn.
    var first = halfEdges[0]
    for i in 0..<halfEdges.count {
        let a = halfEdges[i]
        var b: HalfEdge!

        if i == halfEdges.count - 1 {
            b = first
        } else if halfEdges[i + 1].origin == a.origin {
            b = halfEdges[i + 1]
        } else {
            b = first
            first = halfEdges[i + 1]
        }

        if direction(a.twin.origin, a.origin, b.twin.origin) == .CounterClockwise {
            a.twin.next = b
        }
    }


    ]) > 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
