<commit_before>! Copyright (C) 2005, 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors fry kernel math math.rectangles math.vectors
sequences ui.baseline-alignment ui.gadgets ;
IN: ui.gadgets.borders

TUPLE: border < aligned-gadget
    { size initial: { 0 0 } }
    { fill initial: { 0 0 } }
    { align initial: { 1/2 1/2 } }
    { min-dim initial: { 0 0 } } ;

: new-border ( child class -- border )
    new swap add-gadget ; inline

: <border> ( child gap -- border )
    [ border new-border ] dip >>size ;

: <filled-border> ( child gap -- border )
    <border> { 1 1 } >>fill ;

: border-pref-dim ( border child-dim -- pref-dim )
    '[ size>> 2 v*n _ v+ ] [ min-dim>> ] bi vmax ;

M: border pref-dim*
    dup gadget-child pref-dim border-pref-dim ;

<PRIVATE

: border-major-dim ( border -- dim )
    [ dim>> ] [ size>> 2 v*n ] bi v- ;

: border-minor-dim ( border -- dim )
    gadget-child pref-dim ;

: scale ( a b s -- c )
    [ v* ] [ { 1 1 } swap v- v* ] bi-curry bi* v+ ;

: border-dim ( border -- dim )
    [ border-major-dim ] [ border-minor-dim ] [ fill>> ] tri scale ;

: border-loc ( border dim -- loc )
    [ [ size>> ] [ align>> ] [ border-major-dim ] tri ] dip v- v* v+ ;

: border-child-rect ( border -- rect )
    dup border-dim [ border-loc ] keep <rect> ;

: border-metric ( border quot -- n )<commit_msg>Revert "ui.gadgets.borders: don't convert border-loc to fixnum."<commit_after>! Copyright (C) 2005, 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors fry kernel math math.rectangles math.vectors
sequences ui.baseline-alignment ui.gadgets ;
IN: ui.gadgets.borders

TUPLE: border < aligned-gadget
    { size initial: { 0 0 } }
    { fill initial: { 0 0 } }
    { align initial: { 1/2 1/2 } }
    { min-dim initial: { 0 0 } } ;

: new-border ( child class -- border )
    new swap add-gadget ; inline

: <border> ( child gap -- border )
    [ border new-border ] dip >>size ;

: <filled-border> ( child gap -- border )
    <border> { 1 1 } >>fill ;

: border-pref-dim ( border child-dim -- pref-dim )
    '[ size>> 2 v*n _ v+ ] [ min-dim>> ] bi vmax ;

M: border pref-dim*
    dup gadget-child pref-dim border-pref-dim ;

<PRIVATE

: border-major-dim ( border -- dim )
    [ dim>> ] [ size>> 2 v*n ] bi v- ;

: border-minor-dim ( border -- dim )
    gadget-child pref-dim ;

: scale ( a b s -- c )
    [ v* ] [ { 1 1 } swap v- v* ] bi-curry bi* v+ ;

: border-dim ( border -- dim )
    [ border-major-dim ] [ border-minor-dim ] [ fill>> ] tri scale ;

: border-loc ( border dim -- loc )
    [ [ size>> ] [ align>> ] [ border-major-dim ] tri ] dip
    v- v* v+ [ >fixnum ] map ;

: border-child-rect ( border -- rect )
    dup border-dim [ border-loc ] keep <rect> ;

: border-metric ( border quot -- n )
{'fraction_non_alphanumeric': 0.16874777024616483, 'fraction_numerical': 0.01712450945415626, 'mean_word_length': 2.382388419782871, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 50, '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': '4540323', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1022, 'n_words': 298}