#NEWLINE# def HPlusSolution( s1 , s2 ) : #NEWLINE# #INDENT# "The Solution that results from joining two Solutions side-by-side.\n\n  Args:\n    s1: Solution object\n    s2: Solution object\n  Returns:\n    A new Solution reflecting a layout in which s2 ('s layout) is placed\n    immediately to the right of s1.\n\n  The resulting Solution object maps each prospective left margin m to the\n  span, cost and layout information that would result from siting Solution s1\n  at m, and then placing s2 at margin m + sp1(m), where sp1(m) is the span\n  of characters occupied by the layout to which s1 maps m. In general, of\n  course, both s1 and s2's layouts may occupy multiple lines, in which case\n  s2's layout begins at the end of the last line of s1's layout---the span\n  in this case is the span of s1's last line.\n  " #NEWLINE# col = SolutionFactory ( ) #NEWLINE# s1 . Reset ( ) #NEWLINE# s2 . Reset ( ) #NEWLINE# s1_margin = 0 #NEWLINE# s2_margin = s1 . CurSpan ( ) #NEWLINE# s2 . MoveToMargin ( s2_margin ) #NEWLINE# while True : #NEWLINE# #INDENT# g1 = s1 . CurGradient ( ) #NEWLINE# g2 = s2 . CurGradient ( ) #NEWLINE# overhang0 = ( s2_margin - options . m0 ) #NEWLINE# overhang1 = ( s2_margin - options . m1 ) #NEWLINE# g_cur = ( ( ( g1 + g2 ) - ( options . c0 * ( overhang0 >= 0 ) ) ) - ( options . c1 * ( overhang1 >= 0 ) ) ) #NEWLINE# i_cur = ( ( ( s1 . CurValueAt ( g_cur ) + s2 . CurValueAt ( s2_margin ) ) - ( options . c0 * max ( overhang0 , 0 ) ) ) - ( options . c1 * max ( overhang1 , 0 ) ) ) #NEWLINE# col . Append ( s1_margin , ( s1 . CurSpan ( ) + s2 . CurSpan ( ) ) , i_cur , g_cur , Layout ( [ LayoutElement . PrintLayout ( s1 . CurLayout ( ) ) , LayoutElement . PrintLayout ( s2 . CurLayout ( ) ) ] ) ) #NEWLINE# kn1 = s1 . NextKnot ( ) #NEWLINE# kn2 = s2 . NextKnot ( ) #NEWLINE# if ( ( kn1 == INFINITY ) and ( kn2 == INFINITY ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if ( ( kn1 - s1_margin ) <= ( kn2 - s2_margin ) ) : #NEWLINE# #INDENT# s1 . Advance ( ) #NEWLINE# s1_margin = kn1 #NEWLINE# s2_margin = ( s1_margin + s1 . CurSpan ( ) ) #NEWLINE# s2 . MoveToMargin ( s2_margin ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s2 . Advance ( ) #NEWLINE# s2_margin = kn2 #NEWLINE# s1_margin = ( s2_margin - s1 . CurSpan ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# return col . MkSolution ( )