 #
 # The triangulation is abstract in the sense that we do not impose any
 # restrictions on the objects representing vertices.
-#
-# Most of the implementation details are hidden within a closure via the `do
-# ->` construct.
-
 triangulation = do ->
-  # We use a hidden class to encapsulate the implementation details.
+
+  # The hidden class `Triangulation` implements our data structure.
   class Triangulation
 
     # The constructor takes a set of triangles and a map specifying the


# The function `delaunayTriangulation` creates the Delaunay triangulation of a
# set of points in the x,y-plane using the so-called incremental flip method.
# As before, we hide implementation details within a closure.

delaunayTriangulation = do ->

  # Again, we use a hidden class to encapsulate the implementation details.
  class Triangulation
    # The triangle `outer` is a conceptual, 'infinitely large' triangle which
    # is added to avoid special boundary considerations within the algorithm.
    outer = seq -1, -2, -3

    # The constructor arguments are specific to this particular
    # algorithm.
    constructor: (
      # The abstract triangulation:
      @triangulation__ = triangulation(outer),
      # Maps vertex numbers to `Point2d` instances:
      @coords__ = new HashMap(),
      # The set of all `Point2d` instances present:
      @points__ = new HashSet(),
      # Defines the history DAG used to locate which triangle a point is in:
      @children__ = new HashMap().plus [outer, seq()]) ->


# ----

    # an oriented triangle.
    constructor: (@triangles__ = new HashSet(), @third__ = new HashMap()) ->

    # The method `toSeq` returns the triangles contained in the triangulation
    # as a lazy sequence.
    toSeq: -> @triangles__.toSeq()

