## [PyX-user] Some geometry thoughts

 [PyX-user] Some geometry thoughts From: Magnus Lie Hetland - 2004-07-26 22:46:45 Attachments: geom.py ```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 one-way 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. in-place methods, allowing the addition of two-tuples to points, ...) and the API isn't very PyX-like, 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 + (b-a)/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] ```

 [PyX-user] Some geometry thoughts From: Magnus Lie Hetland - 2004-07-26 22:46:45 Attachments: geom.py ```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 one-way 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. in-place methods, allowing the addition of two-tuples to points, ...) and the API isn't very PyX-like, 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 + (b-a)/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] ```
 Re: [PyX-user] Some geometry thoughts From: Andre Wobst - 2004-07-27 06:22:39 ```Hi, On 27.07.04, Magnus Lie Hetland wrote: > 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...) You're a lucky guy ... ;-) > 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 one-way and functional, as opposed to > the general equations in MetaPost). Hmm. Lazy points are definitely the right thing. We will need lazy skalars and a lazy transformation as well ... Beside that my main concern is, whether its enough to stick on this strict assignments. This is quite a limitation. We can't compete to MetaPost by that (but we want, don't we?). I'm not sure whether its possible to cook it all down to an Equality-function: Equal(b, a + Point(10, 0)) or even missuse the Equality comparision "==": b == a + Point(10, 0) Of course, this would mean, that we would need to first defining all lazy variables: a = Lazy_Point(); b = Lazy_Point(); c = Lazy_Point(), but I think that's not a problem to be that verbose. Beside that I would like points with other dimensions (at least 3d as well) and (affine) transformations between Points of different dimensions. At least that's what I would like to have ... ;-) Anyway, I really like your code! André -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX (_/ \_)_/\_/ visit http://pyx.sourceforge.net/ ```