   LOOP
     RAISE NOTICE 'Current 2-pt sub-segment: %', currentSubsegment;
 
-    -- if this is the start of a new full segment
+    -- If this is the start of a new full segment
     -- then start the full segment, otherwise add the point to the existing full segment
     IF fullSegment IS NULL
     THEN

  RETURNS SETOF RECORD AS
$BODY$

-- Iterate through the points for this specific mode_s_hex_code, building a line as we go
-- we build the line using subsegments that are created between every pair of neighboring points
-- If the line creates a pattern then we count a it and start over building a new line
--     add the intersection point to the returning recordset
--     add the centroid of the pattern to the resulting recordset
-- pass in the ID of the mode s that we want to calc its patterns
--   SELECT * FROM find_pattern_count(mode_s);


DECLARE

    b.rownum
  FROM pts AS a,
    pts AS b
  -- Work-around to get the current point and the next point in the correct order,
  -- since rownum sorted by timestamp
  WHERE a.rownum = b.rownum - 1
        AND
        b.rownum > 1
