Hi David,
On 07.03.04, David J. C. Beach wrote:
> I've recently started using PyX to prepare a few presentation quality
> graphics and I really like the quality of output it produces.
>
> I've been trying to add some "layout-management" type classes so that I
> can combine multiple images into larger layouts (such as grids/tables).
> In so doing, I ran into the problem that instances of the unit.length()
> class do not numerically compare, but simply have the default
> "compare-by-id" behavior implemented by Python. I don't like this at
> all. :)
>
> I patched my own installation of PyX to ammend this, and am offering the
> change here. Can this go back into the distribution?
Of course, we can take this into the distribtion. But I would like to
hear a response from Jörg first (he wrote the unit-implementation).
While he's at a conference this week, we should wait until he's back.
> (in unit.length...)
>
> def __cmp__(self, other):
> l1 = tom(self)
> l2 = tom(other)
> if l1 <> l2: return cmp(l1,l2)
> return cmp(id(self), id(other))
I should tell you, that I do have similar problems in the graph
module. Here I have to compare lengths as well. While there is in
principle a possibility to internally work in PostScript points
already (there are _pt-like classes and methods almost everywhere like
path.line and path.line_pt), you can then only return PostScript
points or faked PyX lengths (as "true pt" and the like). The other
possibility is to manually convert the lengths into plain numbers
yourself before comparing. This is what I do in the graph module at
various places. I was not satisfied about adding a comparision like
you suggest it, because you can easily compare "apples and oranges" by
that. What about allowing for the comparision, when both parameters
are PyX lengths only? (This should be the case I'm doing in the graph
module all the time.) Would this be your use case as well? I would
feel much happier with that ...
And about you patch ... is there a reason why having the id-comparion
in the end? This looks totally unnatural to me ... did you step into
troubles when not having this extra interpretation of the comparision
operation???
André
--
by _ _ _ Dr. André Wobst
/ \ \ / ) wo...@us..., http://www.wobsta.de/
/ _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX
(_/ \_)_/\_/ visit http://pyx.sourceforge.net/
|