Hi guys. I pushed some libraries I've been working on to git:// 
repo.or.cz/factor/jcg.git that y'all might find useful:

• svg provides some parsers to help parse out paths and transforms  
from SVG documents, building on Dan's xml libraries. If you've got an  
SVG document like this:

--
<" <svg xmlns="http://www.w3.org/2000/svg";>
     <path d="M 10 10 L 630 470" transform="translate(10.0 10.0)  
rotate(45)" />
</svg> "> string>xml
--

You can extract the path tag and tease out its nodes and transform  
like so:

--
body>> children-tags first [ tag-d ] [ tag-transform ] bi
--

Which'll give you back an array of path commands and an affine- 
transform object, respectively. Speaking of which,

• math.affine-transforms provides operations for affine transforms of  
two-dimensional vectors. You could get the same effect with a 3x3  
matrix, but it'd be less convenient and efficient. There are words for  
transforming vectors ( a.v ), combining transforms ( a. ), and  
inverting transforms ( inverse-transform ), as well as constructors  
for the common cases of translation, rotation, and scaling transforms.

• literals provides syntax for interpolating constant words and  
expressions into literal values at parse time. For example, you can  
evaluate √2/2 to build a literal 45º transform using $[ ] :

--
USE: literals
T{ affine-transform f { $[ 2.0 sqrt 0.5 * ] $[ 2.0 sqrt 0.5 * ] } { $ 
[ 2.0 sqrt -0.5 * ] $[ 2.0 sqrt 0.5 * ] } { 0.0 0.0 } }
--

Or you can define a word for √2/2 and interpolate it using $ :

--
USE: literals
<< : sin-45 ( -- x ) 2.0 sqrt 0.5 * ; >>
T{ affine-transform f { $ sin-45 $ sin-45 } { $[ sin-45 neg ] $  
sin-45 } { 0.0 0.0 } }
--

One caveat is that $ and $[ can't reference words from the same  
compilation unit, hence the << >> in the example above. In real code  
you'd want to shoot your constants out to a separate vocab if you're  
planning on using literals.

• sequences.squish is a replacement for the flatten word from  
sequences.deep that parameterizes the descent predicate. The words in  
sequences.deep are hard-coded to descend into all sequences except  
integers and strings. While this is a pretty sane default, sometimes  
you actually want to descend into strings. squish lets you do that:

--
: squish-strings ( seq -- seq' )
     [ { [ sequence? ] [ integer? not ] } 1&& ] "" squish ;
--

The predicate in that example causes squish to descend all sequences  
besides integers.

-Joe
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to