Monday, August 27, 2007

Subway Geography and Geometry

I've written an applet that lets you reimagine the geography of greater Washington, DC area with "distance" measured by subway-travel-time, measured by subway-travel-cost, or as the standard clarified subway wall map would deform it. This was in large part inspired by Oskar Karlin's beautifully rendered Isochronic Elephant-Castle map of the London Underground and the interactive tube mapplet from Tom Carden. Subway Maps of the world all on the same scale is pretty interesting, as is this directory of remixed London Underground maps. There's a few interesting images on wiki commons, like this geographical map within this gallery. Also, you can download the image files (very large, register with each other) from Wikipedia:

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: , , , , , ,

How to make a patch using diff

I always forget the command to use, and google is strangely devoid of helpful/correct advice. Therefore I'm posting this for my own and future generations' reference.

How to Generate a Patch from Standalone Code

For non-(svn|cvs),
  • You should have a directory holding the original source (i.e. "dir") and a directory holding the modified (i.e. "dir-orig").
  • Obviously, don't modify dir-orig (that is, it should match the author's). If you don't trust yourself, do a chmod -R a-w dir-orig to recursively mark the directory read-only.
  • Generate the patch by going to the parent directory (holding dir-orig and dir) and running the command
    diff -Nuwr dir-orig dir > /tmp/my-happy-patch.diff
    • dir and dir-orig should be paths to the dirs in question, obviously.
    • -N creates newly added files (treats absent files as empty files)
    • -u creates a "unified" diff -- it's hunam readable and works well with patch
    • -w ignores whitespace, which is polite if your (clearly superior) formatting policy differs from the original.
    • -r recursively descends the source tree.
  • Other helpful options:
    • -p (applied to C or C++ code) shows the function the new code appears in. Only use this with C or C++ code (i.e. YMMV)
    • -u6 (or any number following the -u) gives that many lines of context (the default is 3, which should be fine for code that isn't changing like the star of a Tootsie stage performance)
    • -x ".??*" ignores .DS_Store, Eclipse and other hidden-file turds, if you have those. Emacsen should add -x "*~".
  • Sanity-check the change less /tmp/my-happy-patch.diff

How to Generate a Patch from Subversion or CVS

To generate a patch from cvs or svn, (advice horked from X-Smiles.org):
  • Make sure you are synchronized with the latest sources: $ cvs update src (or wherever your changes are; use a directory that spans all the changed modules or the trunk directory.)
  • Sanity-check the change: $ cvs diff src
  • Generate the patch (replace -Nuwr with whatever you decided works for you from the options above). $ svn --diff-cmd=diff -x-Nuw src > /tmp/my-happy-patch.diff
  • (Rather than include -x "" args, you should be adding turd files to your ~/.subversion/config, for instance global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store or however you pronounce that in a ~/.cvsrc or .cvsignore.)
  • Sanity-check the patch less /tmp/my-happy-patch.diff
(By the way, if your broken OS lacks a command line, you might be able to add one).

How to use a Patch

To apply such a patch,
  • Download the patch and save it somewhere intelligent.
  • If you're not using version control, !!make a copy of the source tree!!
  • Change directories into that new folder --the one holding the unmolested (or svn trunk) code.
  • Sanity check: run the command cat /tmp/my-happy-patch.diff | patch -p1 --dry-run
  • If you see results like patching file foo/bar/my-happy-file.as ... you're good to go: cat /tmp/my-happy-patch.diff | patch -p1
  • Pitfalls:
    • If you get a patch taken from within the modified directory, change -p1 to -p0.
    • If you get a patch with the original and modified dirs reversed, add a --reverse flag.

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: , , , , , , , , , , , , ,