original_docstring: Return a sample point guaranteed to be within a ring, by efficiently
      finding the first centroid of a coordinate triplet whose orientation
      matches the orientation of the ring and passes the point-in-ring test.
      The orientation of the ring is assumed to be clockwise, unless ccw
      (counter-clockwise) is set to True. 
      
docstring: Return a sample point guaranteed to be within a ring, by efficiently
  finding the first centroid of a coordinate triplet whose orientation
  matches the orientation of the ring and passes the point-in-ring test.
  The orientation of the ring is assumed to be clockwise, unless ccw
  (counter-clockwise) is set to True.
docstring_tokens: Return a sample point guaranteed to be within a ring by efficiently finding the first centroid of a coordinate triplet whose orientation matches the orientation of the ring and passes the point - in - ring test . The orientation of the ring is assumed to be clockwise unless ccw ( counter - clockwise ) is set to True .
code: def ring_sample(coords, ccw=False):
      """Return a sample point guaranteed to be within a ring, by efficiently
      finding the first centroid of a coordinate triplet whose orientation
      matches the orientation of the ring and passes the point-in-ring test.
      The orientation of the ring is assumed to be clockwise, unless ccw
      (counter-clockwise) is set to True. 
      """
      triplet = []
      def itercoords():
          # iterate full closed ring
          for p in coords:
              yield p
          # finally, yield the second coordinate to the end to allow checking the last triplet
          yield coords[1]
          
      for p in itercoords(): 
          # add point to triplet (but not if duplicate)
          if p not in triplet:
              triplet.append(p)
              
          # new triplet, try to get sample
          if len(triplet) == 3:
              # check that triplet does not form a straight line (not a triangle)
              is_straight_line = (triplet[0][1] - triplet[1][1]) * (triplet[0][0] - triplet[2][0]) == (triplet[0][1] - triplet[2][1]) * (triplet[0][0] - triplet[1][0])
              if not is_straight_line:
                  # get triplet orientation
                  closed_triplet = triplet + [triplet[0]]
                  triplet_ccw = signed_area(closed_triplet) >= 0
                  # check that triplet has the same orientation as the ring (means triangle is inside the ring)
                  if ccw == triplet_ccw:
                      # get triplet centroid
                      xs,ys = zip(*triplet)
                      xmean,ymean = sum(xs) / 3.0, sum(ys) / 3.0
                      # check that triplet centroid is truly inside the ring
                      if ring_contains_point(coords, (xmean,ymean)):
                          return xmean,ymean
  
              # failed to get sample point from this triplet
              # remove oldest triplet coord to allow iterating to next triplet
              triplet.pop(0)
              
      else:
          raise Exception('Unexpected error: Unable to find a ring sample point.')
code_tokens: def ring_sample ( coords , ccw = False ) : triplet = [ ] def itercoords ( ) : for p in coords : yield p yield coords [ 1 ] for p in itercoords ( ) : if p not in triplet : triplet . append ( p ) if len ( triplet ) == 3 : is_straight_line = ( triplet [ 0 ] [ 1 ] - triplet [ 1 ] [ 1 ] ) * ( triplet [ 0 ] [ 0 ] - triplet [ 2 ] [ 0 ] ) == ( triplet [ 0 ] [ 1 ] - triplet [ 2 ] [ 1 ] ) * ( triplet [ 0 ] [ 0 ] - triplet [ 1 ] [ 0 ] ) if not is_straight_line : closed_triplet = triplet + [ triplet [ 0 ] ] triplet_ccw = signed_area ( closed_triplet ) >= 0 if ccw == triplet_ccw : xs , ys = zip ( * triplet ) xmean , ymean = sum ( xs ) / 3.0 , sum ( ys ) / 3.0 if ring_contains_point ( coords , ( xmean , ymean ) ) : return xmean , ymean triplet . pop ( 0 ) else : raise Exception ( 'Unexpected error: Unable to find a ring sample point.' )
short_docstring: Return a sample point guaranteed to be within a ring, by efficiently
  finding the first centroid of a coordinate triplet whose orientation
  matches the orientation of the ring and passes the point-in-ring test.
short_docstring_tokens: Return a sample point guaranteed to be within a ring by efficiently finding the first centroid of a coordinate triplet whose orientation matches the orientation of the ring and passes the point - in - ring test .
comment: """Return a sample point guaranteed to be within a ring, by efficiently
      finding the first centroid of a coordinate triplet whose orientation
      matches the orientation of the ring and passes the point-in-ring test.
      The orientation of the ring is assumed to be clockwise, unless ccw
      (counter-clockwise) is set to True. 
      """$SEP$# iterate full closed ring
  $SEP$# finally, yield the second coordinate to the end to allow checking the last triplet
  $SEP$# add point to triplet (but not if duplicate)
  $SEP$# new triplet, try to get sample
  $SEP$# check that triplet does not form a straight line (not a triangle)
  $SEP$# get triplet orientation
  $SEP$# check that triplet has the same orientation as the ring (means triangle is inside the ring)
  $SEP$# get triplet centroid
  $SEP$# check that triplet centroid is truly inside the ring
  $SEP$# failed to get sample point from this triplet
  $SEP$# remove oldest triplet coord to allow iterating to next triplet
  