original_docstring: Return a square of equal area to the rectangle. 
docstring: Return a square of equal area to the rectangle.
docstring_tokens: Return a square of equal area to the rectangle .
code: def rectangle2square(rectangle):
      """Return a square of equal area to the rectangle. """
      rect = squish_rectangle(rectangle)
      last = None
      for t in rect:
          if last is not None:
              yield last
          last = t
      rect = last
      a, b, c, d = rect.convex_hull()
      s1 = LineSegment(a, b)
      s2 = LineSegment(b, c)
      if float_eq(s1.length(), s2.length()):
          yield self
      elif s1.length() < s2.length():
          # Ensure s1 is height and s2 is width
          a, b, c, d = b, c, d, a
      s1 = LineSegment(a, b)
      s2 = LineSegment(b, c)
      s3 = LineSegment(c, d)
      s4 = LineSegment(d, a)
      revs4 = LineSegment(a, d)
      assert s1.length() > s2.length()
      square_side = (s1.length() * s2.length())**0.5
      corner1 = s1.point_by_length(square_side)
      corner2 = revs4.point_by_length(square_side)
      cut = LineSegment(b, corner2).to_line()
      r1, r2 = rect.split(cut)
      if len(r1.convex_hull()) == 3:
          triangle = r1
          rest = r2
      elif len(r2.convex_hull()) == 3:
          triangle = r2
          rest = r1
      else:
          raise Exception("Bad cut")
  
      yield Shape(triangle.triangles + rest.triangles)
  
      cut = s1.to_line().perpendicular(corner1)
      r1, r2 = rest.split(cut)
      if len(r1.convex_hull()) == 3:
          rest = r2
          other_triangle = r1
      elif len(r2.convex_hull()) == 3:
          rest = r1
          other_triangle = r2
      else:
          raise Exception("Bad cut")
  
      yield Shape(triangle.triangles + rest.triangles + other_triangle.triangles)
  
      for p in triangle.convex_hull():
          if not point_eq(p, b) and not point_eq(p, c):
              anchor = p
  
      tri_trans = (corner2[0] - anchor[0], corner2[1] - anchor[1])
      triangle = triangle.translate(tri_trans)
      yield Shape(triangle.triangles + rest.triangles + other_triangle.triangles)
      otri_trans = (anchor[0] - b[0], anchor[1] - b[1])
      other_triangle = other_triangle.translate(otri_trans)
      yield Shape(rest.triangles + triangle.triangles + other_triangle.triangles)
code_tokens: def rectangle2square ( rectangle ) : rect = squish_rectangle ( rectangle ) last = None for t in rect : if last is not None : yield last last = t rect = last a , b , c , d = rect . convex_hull ( ) s1 = LineSegment ( a , b ) s2 = LineSegment ( b , c ) if float_eq ( s1 . length ( ) , s2 . length ( ) ) : yield self elif s1 . length ( ) < s2 . length ( ) : a , b , c , d = b , c , d , a s1 = LineSegment ( a , b ) s2 = LineSegment ( b , c ) s3 = LineSegment ( c , d ) s4 = LineSegment ( d , a ) revs4 = LineSegment ( a , d ) assert s1 . length ( ) > s2 . length ( ) square_side = ( s1 . length ( ) * s2 . length ( ) ) ** 0.5 corner1 = s1 . point_by_length ( square_side ) corner2 = revs4 . point_by_length ( square_side ) cut = LineSegment ( b , corner2 ) . to_line ( ) r1 , r2 = rect . split ( cut ) if len ( r1 . convex_hull ( ) ) == 3 : triangle = r1 rest = r2 elif len ( r2 . convex_hull ( ) ) == 3 : triangle = r2 rest = r1 else : raise Exception ( "Bad cut" ) yield Shape ( triangle . triangles + rest . triangles ) cut = s1 . to_line ( ) . perpendicular ( corner1 ) r1 , r2 = rest . split ( cut ) if len ( r1 . convex_hull ( ) ) == 3 : rest = r2 other_triangle = r1 elif len ( r2 . convex_hull ( ) ) == 3 : rest = r1 other_triangle = r2 else : raise Exception ( "Bad cut" ) yield Shape ( triangle . triangles + rest . triangles + other_triangle . triangles ) for p in triangle . convex_hull ( ) : if not point_eq ( p , b ) and not point_eq ( p , c ) : anchor = p tri_trans = ( corner2 [ 0 ] - anchor [ 0 ] , corner2 [ 1 ] - anchor [ 1 ] ) triangle = triangle . translate ( tri_trans ) yield Shape ( triangle . triangles + rest . triangles + other_triangle . triangles ) otri_trans = ( anchor [ 0 ] - b [ 0 ] , anchor [ 1 ] - b [ 1 ] ) other_triangle = other_triangle . translate ( otri_trans ) yield Shape ( rest . triangles + triangle . triangles + other_triangle . triangles )
short_docstring: Return a square of equal area to the rectangle.
short_docstring_tokens: Return a square of equal area to the rectangle .
comment: """Return a square of equal area to the rectangle. """$SEP$# Ensure s1 is height and s2 is width