Robin Dunn wrote:
For DrawLineList does having the two parallel sequences of points make sense
to everybody or would a sequence of (x1, y1, x2, y2) tuples be more
intuitive and useful?
I think the sequence of 4-tuples would make the most sense, as it
parallels what the exisiting DrawLine() takes. All the Draw*List methods
should take a sequence of the same input that the regular Draw* methods
do. As Tim is working on this, I'm sure it's already in there, but it
should take a NX4 NumPy array as well.
By the way, is there any real reason for DrawLine() to exist at all,
rather than using DrawLines() with just two points??
Tim Hochberg wrote:
> I'm not thrilled with having a separate pen list. [None |
> wxPen] makes sense where None just means use the default pen. If a list of
> pens is going to be supported, then the pen should be part of the list
(x1,
> y1, x2, y2, wxPen).
This makes no sense to me. Supplying a single pen argument adds no
functionality that you can't do just as fast using:
wxDC.SetPen(pen)
wxDC.DrawLineList(points)
In fact I'm very tempted to rip out the single pen option.
Quite true. I'm the one that argued for the single pen option. I still
think is a good idea, just tho keep the API clean, To me , it kindo of
mirrors the ideas of array broadcasting in NumPy, and other Array
oriented languages. For example, A*B works for A an array and B either
an Array of the same shape, or a scalar. If B is a scalar, it is
broadcast over all the elements of A (Broadcasting works on higher rank
arrays in very nifty ways, but that's not the point). Anyway, with my
background in MATLAB and NumPy, I tend to like this interace. It's also
a little more object oriented way to think about drawing: I want to draw
a given object (in this case a line, or set of lines with a given pen).
The current syntax is really a mirror of how a drawing process works:
set the pen, set the brush, draw the object. I'd rather be hidden from
those mechanics. Of course, the whole way DCs work is already set, and
I've written a more object oriented wrapper around them anyway, so there
may be little point in adding this small feature.
Actually, for real consistancy, a singleton sequence might be better
than a pen itself [pen], rather than pen. Hmmm..
That was a long-winded way to say: I'd like to have the single pen
option, but it's no big deal. He who writes the code, make the decision,
so go ahead and do what you want, Tim.
On the other hand, allowing a pen list allows this:
for i in range(len(points)):
wxDC.SetPen(pens[i])
wxDC.DrawLine(*points[i])
as wxDC.DrawLineList(points, pens) which is about 10x faster.
That, of course, is really the whole point of the exercise. While I,
too, most frequently want to draw a bunch of lines and points in a
single pen, The same is not true for rectangles and polygons, which I am
more likely to want in different colors, etc.
The final suggestion that the points and the pen combined into a single list
would be very bad for those of us that use Numeric to manipulate out points.
Exactly. While it is more object-oriented to think of a sequence of
objects, each object having all it's properties together, for
performance reasons, keeping the sequence of coordinates separate from
the other properties is crucial. You can manipulate all the coordinates
as a package. Even in C, there is always the choice between an array of
structs, and a struct of arrays.
Robin Dunn wrote:
the pen should be part of the list
(x1, y1, x2, y2, wxPen).
That would increase the complexity by a couple orders of magnitude.
Another good reason to keep them separate. If that's not enough, we want
the option of using a single pen (either by passing it in, or pre
setting it), so we can't go this route.
Tim Hochberg wrote:
Ah, now I understand. No, DrawLineList just draws a list of lines not a
polygon. DrawLines and/or DrawPolygon already does what you're thinking of.
right, which is exactly why it should be called DrawPolyline, because
that's what it does. And DrawPolylineList() (or DrawLinesList() ) will
draw a list of polylines. The point of this is twofold:
1) to have a cleaner syntax to draw a bunch of object (I always feel
like I'm writting clunky code when I write a for loop to do exactly the
same thing to each item in a list)
2) to have a faster way to draw a bunch of objects. This is perhaps the
stronger motivator. Without the speed issue, you culd wite this in
Python (and I have)
Kevin Altis wrote:
Sorry, I meant that wxPython DrawLines doesn't allow you to draw
(x1,y1,x2,y2), (x3,y3,x4,y4), etc.
That's because it draws a single Polyline....(x1,y1),(x2,y2),(x3,y3),
....
I'm mostly interested in
drawing a bunch of points or lines or rects or polygons, etc. using a single
pen, since that is the most common case I can think of.
It's the most common case for me two (at least for points and lines),
but while we are at it, being able to have them use different pens is a
very nice feature too.
I think you're on the right track.
So do I.
Kevin, did you try out my Python prototype of all this? Except for a few
details of the syntax, Tim is doing the same thing, but in C++.
Tim and Robin, thanks for putting your time into this, I, at least am
really going to appreciate it.
-Chris
···
--
Christopher Barker,
Ph.D.
ChrisHBarker@home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------