<commit_before>! Copyright (C) 2006, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors io kernel math namespaces
sequences words math.vectors ui.gadgets ui.gadgets.packs math.geometry.rect ;
IN: ui.gadgets.tracks

TUPLE: track < pack sizes ;

: normalized-sizes ( track -- seq )
    track-sizes
    [ sift sum ] keep [ dup [ over / ] when ] map nip ;

: new-track ( orientation class -- track )
  new-gadget
    swap       >>orientation
    V{ } clone >>sizes
    1          >>fill ; inline

: <track> ( orientation -- track ) track new-track ;

: alloted-dim ( track -- dim )
  [ children>> ] [ sizes>> ] bi { 0 0 }
  [ [ drop { 0 0 } ] [ pref-dim ] if v+ ] 2reduce ;

: available-dim ( track -- dim ) [ dim>> ] [ alloted-dim ] bi v- ;

: track-layout ( track -- sizes )
    dup available-dim over gadget-children rot normalized-sizes
    [ [ over n*v ] [ pref-dim ] ?if ] 2map nip ;

M: track layout* ( track -- ) dup track-layout pack-layout ;

: track-pref-dims-1 ( track -- dim ) children>> pref-dims max-dim ;

: track-pref-dims-2 ( track -- dim )
    dup gadget-children pref-dims swap normalized-sizes
    [ [ v/n ] when* ] 2map max-dim [ >fixnum ] map ;

M: track pref-dim* ( gadget -- dim )
   [ track-pref-dims-1                           ]
   [ [ alloted-dim ] [ track-pref-dims-1 ] bi v+ ]<commit_msg>ui.gadgets.tracks: rewrite track-layout<commit_after>! Copyright (C) 2006, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors io kernel math namespaces
sequences words math.vectors ui.gadgets ui.gadgets.packs math.geometry.rect ;
IN: ui.gadgets.tracks

TUPLE: track < pack sizes ;

: normalized-sizes ( track -- seq )
    track-sizes
    [ sift sum ] keep [ dup [ over / ] when ] map nip ;

: new-track ( orientation class -- track )
  new-gadget
    swap       >>orientation
    V{ } clone >>sizes
    1          >>fill ; inline

: <track> ( orientation -- track ) track new-track ;

: alloted-dim ( track -- dim )
  [ children>> ] [ sizes>> ] bi { 0 0 }
  [ [ drop { 0 0 } ] [ pref-dim ] if v+ ] 2reduce ;

: available-dim ( track -- dim ) [ dim>> ] [ alloted-dim ] bi v- ;

: track-layout ( track -- sizes )
    [ available-dim ] [ children>> ] [ normalized-sizes ] tri
    [ [ over n*v ] [ pref-dim ] ?if ] 2map nip ;

M: track layout* ( track -- ) dup track-layout pack-layout ;

: track-pref-dims-1 ( track -- dim ) children>> pref-dims max-dim ;

: track-pref-dims-2 ( track -- dim )
    dup gadget-children pref-dims swap normalized-sizes
    [ [ v/n ] when* ] 2map max-dim [ >fixnum ] map ;

M: track pref-dim* ( gadget -- dim )
   [ track-pref-dims-1                           ]
   [ [ alloted-dim ] [ track-pref-dims-1 ] bi v+ ]
{'fraction_non_alphanumeric': 0.15077035950110051, 'fraction_numerical': 0.014673514306676448, 'mean_word_length': 2.34601226993865, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2632800', 'n_tokens_mistral': 968, 'n_tokens_neox': 951, 'n_words': 266}