Paste: Crying for simplification

Author: Twinside
Mode: factor
Date: Fri, 9 Apr 2010 16:51:45
Plain Text |
TUPLE: line x1 y1 x2 y2 ;

GENERIC: tosvgString ( object -- string )

: xfield ( name num -- str )
    [ "=\"" append ] dip
    number>string append
    "\" " append
    ;


: mergeField ( obj str quote: ( obj -- str ) -- obj str )
    dip swap append
    ; inline

: <line> ( x y x y -- line ) line boa ;
M: line tosvgString
    "<line "
    [ "x1" over x1>> xfield ] mergeField
    [ "y1" over y1>> xfield ] mergeField
    [ "x2" over x2>> xfield ] mergeField
    [ "y2" over y2>> xfield ] mergeField
    "/>" append
    swap drop ; ! remove the original object

Annotation: mirrors - refactor as neccessary

Author: ceninan
Mode: factor
Date: Fri, 9 Apr 2010 18:19:33
Plain Text |
TUPLE: line x1 y1 x2 y2 ;
C: <line> line

GENERIC: >svg ( object -- string )

M: line >svg
    <mirror> unzip
    [ number>string "\"" dup surround "=" glue ] 2map
    " " join "<line " "/>" surround ;

Annotation: using [XML

Author: ceninan
Mode: factor
Date: Fri, 9 Apr 2010 23:07:39
Plain Text |
TUPLE: line x1 y1 x2 y2 ;
C: <line> line

GENERIC: >svg ( object -- string )

M: line >svg
    [ <line> ] undo
    [XML
        <line x1=<-> y1=<-> x2=<-> y2=<->/>
    XML] ;

New Annotation

Summary:
Author:
Mode:
Body: