glue-viz/bermuda — pull request #13 by astrofrog (2014-08-11 20:26:40+00:00)
Title: Added a ``transform`` property that returns a transformation that can be frozen to the data values

@ChrisBeaumont: alternative to #10 and #12. I think think does what we discussed, for example:

```
import numpy as np
from bermuda.bbox import BBox

b = BBox(center=(300, 200), width=20, height=50, theta=30.)

import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle, Circle

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

# Draw bounding box itself
r = Rectangle((0,0),width=1,height=1,
transform=b.transform,
edgecolor='0.8', facecolor='none')
ax.add_patch(r)

# Draw a 'circle' inside the bounding box (actually an ellipse)
c = Circle((0.5,0.5), radius=0.5,
transform=b.transform,
edgecolor='red', facecolor='none')
ax.add_patch(c)

ax.set_xlim(1., 10.)
ax.set_ylim(1., 10.)

# Now tie to the data transformations
b.tie_to_axes(ax)

ax.set_xscale('log')

fig.savefig('ellipse.png')
```

The transformation starts off being in display coordinates, then when tied to the axes it will get distorted with the axes. You can try it out interactively. The reason for using the transform class is that is handles the freezing, and also allows the transformation to be dynamic and automatically gives up-to-date results when the window is resized.

Performance wise, this is still ok, it's around 167µm per transform, but we can make it faster by caching the bbox-related affine transformation, which doesn't change unless the BBox parameters are changed.