From: Magnus Lie Hetland <magnus@he...>  20040726 22:46:45

Hi! Just threw together a little geometry module to illustrate some ideas I've had; it's rather small, so I've attached it to this email. (Not quite sure if the list lets attachments through, but...) The main point isn't the geometry in itself (quite trivial) but the laziness; because there are lazy points that are calculated from other points on demand it is possible to emulate the equations of MetaPost (even though the emulation is oneway and functional, as opposed to the general equations in MetaPost). The API is a bit verbose at present (i.e. having to explicitly instantiate LazyPoint with the relevant points), lots of room for expansion (e.g. inplace methods, allowing the addition of twotuples to points, ...) and the API isn't very PyXlike, I guess; I can have a look and see if I can make it fit more with the standard decorator paradigm used in PyX (along with the naming convention). For example, one could do a = point(b, [shifted(x, y), rotated(a)]) or something like that. I think that would work just nicely. With the current (quick scribble) API, the following would draw a triangle, shifted into the page: """ from geom import * from pyx import * from math import pi # Order is important here: a = Point(0, 0) b = a + Point(10, 0) c = a + LazyPoint(rotated, (Point(10, 0), pi/3)) # This will shift all the points: a.x += 10 a.y += 10 # Order is not important here: p = path.path(path.moveto(c.x, c.y), path.lineto(a.x, a.y), path.lineto(b.x, b.y), path.closepath()) c = canvas.canvas() c.stroke(p) c.writeEPSfile('test.eps') """ The following finds the midway point between two other points: """ from geom import * a = Point(0, 0) b = Point(0, 0) c = a + (ba)/2 # a += (10, 10) etc. might be nice (and easy) here: a.x = 10 a.y = 10 b.x = 20 b.y = 20 print c.x, c.y """ What do you think? With a little polish, the basic scheme could work, couldn't it?  Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] 