Saturday, September 1, 2007

as3mathlib (formerly WIS math libraries)

I've just imported the WIS mathematics library -- an excellent collection of mathematics routines -- onto Google Code. (You'll find the Actionscript 2 version of the library at its original site)

This library carries a BSD-ish license and includes support for

  • Geometric Objects and Intersection calculations
  • Integral and Differential equation calculations
  • Bezier, Quadric, Polynomial, Complex, Vector and Matrix calculations
  • Symbolic expression parsing

I'm converting the library to Actionscript 3 from Actionscript 2 as time and necessity allow. (That's converting as in getting it to work, and converting as in getting it to be object/pattern oriented). Right now it builds without errors and only a few warnings, but I haven't applied any of the unit tests or checked it for correctness or compatibility.

If you see the value of updating this well-thought out collection of functions, please get in touch and I will add you as a developer. The code is quite modular: it will be straigforward to take modest chunks and get them working independently. I wrote the original author and maintainer, who responded "By all means, continue in the evolution/integration of my library to support AS3" -- but please let me know of any other efforts to update this code, or if a similar or superior math library exists, so that I don't waste my time :).

Email me [flip at the mrflip with the dot and the com] or comment on this post if you'd like to pitch in!

Labels: , , , , , , , , , , , , , , , ,

Friday, August 24, 2007

Patches to the AS3 Cookbook Code

The Actionscript 3 Cookbook is a very helpful reference, and the example code that came with it has many good examples. Unfortunately there's a modicum of bitrot in the code: compiler warnings and errors when compiling under strict mode.

Here is a patch against the version of the code I downloaded on 2007-08-24:

files/AS3CB-patch-2007-08-24.diff

Apply it thusly.

Labels: , , , , , ,

Monday, August 20, 2007

Flex Demo: Matrix Math (and an error in the Actionscript docs)

I'm working on something that uses (an algorithm similar to) texture mapping, for which I want to precalculate the .invert() of a whole bunch of .transform.matrix objects. I'll post something about that in the next coupla days. Meanwhile, I found something perplexing in the Actionscript documentation but the possibility exists that I am just a dope so please point out an error in my reasoning. As you may know, you can represent any arbitrary combination of 2-D scalings, skews, rotations and translations using standard matrix operations. The Actionscript docs for the Matrix class mention this in passing, but has elements .b and .c switched: it should be
right: [ [a,c,tx] [b,d,ty] [0,0,1] ] and not wrong: [ [a,c,tx] [c,d,ty] [0,0,1] ].
I whipped up a MatrixMathDemo in flex to demonstrate the issue: and a writeup on Mathematical matrices and the actionscript Matrix transformations [PDF]. The 2d, 3d, 4th tabs compare the Matrix methods concat(), invert() and (deltaP/p)ointTransform() respectively with an explicit calculation of the corresponding Matrix operation: they show that in fact the documentation has b and c switched. (The code is free to reuse or modify (but give credit) in case that's useful.) Some references:

Labels: , , , , , , , , , , , , ,

Wednesday, July 25, 2007

Emacs modes for Flex

  • Emacs modes for Flex:
    • XML: nXML-mode for Emacs from James Clark Using Emacs for XML documents
    • Actionscript: actionscript-mode.el for editing actionscript files in emacs.
    • At least right now it seems you want this xml mode and this actionscript-mode.el.
    • Then, add
      (setq auto-mode-alist (append (list
       '("\\.as\\'"   . actionscript-mode)
       '("\\.\\(xml\\|xsl\\|rng\\|xhtml\\|mxml\\)\\'" . nxml-mode)
       ;; add more modes here
       ) auto-mode-alist))
      
      ;;
      ;; ------------------ Magic for XML Mode ----------------
      ;;
      
      (setq nxml-mode-hook
          '(lambda ()
       (setq tab-width        2
             indent-tabs-mode nil)
             (set-variable 'nxml-child-indent     2)
             (set-variable 'nxml-attribute-indent 2)
             ))
      
    • You can use M-x customize-group RET nxml-highlighting-faces RET to fix your colors the way you like 'em.
  • Setting up asdoc to work within Flex Builder:
    • First, install ant support (Ant is an offshoot of apache and is like Makefile only more betterer.)
    • Then set up a build.xml in your docs/ directory to build the documentation set.
    • I had to modify mine a bit: I added <property name="Templates.dir" location="${FlexSDK.dir}/asdoc/templates/"/> <arg line='-templates-path ${Templates.dir}'/>
    • I also linked the flex home to a no-funny-characters dir:
          ln -s "/Applications/Applications/Adobe Flex Builder 2" /work/ProgramStores/Flex
         cd /work/ProgramStores/Flex
         ln -s "Flex SDK 2" FlexSDK
      Then I exported the location for the asdoc file:
          export FLEX_HOME=/work/ProgramStores/Flex/FlexSDK
      or else I got the error message:
          Exception in thread "main" java.lang.NoClassDefFoundError: Flex

Labels: , , , , , , ,

Tuesday, July 24, 2007

How to use exuberant CTAGS with ActionScript and Flex

How to fix CTAGS to work with ActionScript, from the vim-taglist project:
  • ActionScript Add the following lines to the $HOME/.ctags or $HOME/ctags.conf file:
    --langdef=actionscript
    --langmap=actionscript:.as
    --regex-actionscript=/^[ \t]*[(private| public|static) ( \t)]*function[ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1/f, function, functions/
    --regex-actionscript=/^[ \t]*[(public) ( \t)]*function[ \t]+(set|get) [ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1 \2/p,property, properties/
    --regex-actionscript=/^[ \t]*[(private| public|static) ( \t)]*var[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/v,variable, variables/
    --regex-actionscript=/.*\.prototype \.([A-Za-z0-9 ]+)=([ \t]?)function( [ \t]?)*\(/\1/ f,function, functions/
    --regex-actionscript=/^[ \t]*class[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class, classes/
    
    Add the following lines to the ~/.vimrc or $HOME\_vimrc file:
    " actionscript language
    let tlist_actionscript_settings = 'actionscript;c:class;f:method;p:property;v:variable'
    
I actually just add these lines to my maintenance Makefile:
CTAGLANGS = --langdef=actionscript \
--langmap=actionscript:.as \
--regex-actionscript='/^[ \t]*[(private| public|static) ( \t)]*function[\t]+([A-Za-z0-9_]+)[ \t]*\(/\1/f, function, functions/' \
--regex-actionscript='/^[ \t]*[(public) ( \t)]*function[ \t]+(set|get) [ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1 \2/p,property, properties/' \
--regex-actionscript='/^[ \t]*[(private| public|static) ( \t)]*var[  \t]+([A-Za-z0-9_]+)[\t]*/\1/v,variable, variables/' \
--regex-actionscript='/.*\.prototype \.([A-Za-z0-9 ]+)=([ \t]?)function( [  \t]?)*\(/\1/f,function, functions/' \
--regex-actionscript='/^[ \t]*class[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class, classes/'

.PHONY: ctags
ctags:
-rm -f TAGS
find . -name "*.as" -or -name "*.mxml" | ctags -eL - $(CTAGLANGS)
Take off the -e (ctags -L - $(CTAGLANGS)) if you're one of those vi users (I'm being polite because, after all, it's from them comes this tip)

Labels: , , , , , , , ,

Wednesday, June 20, 2007

Resources for learning Flex

Hints I gathered for learning Flex:

Labels: , , , , ,