Re: [Edu-sig] Properties use case

2006-03-19 Thread Scott David Daniels
Arthur wrote:
  
 The small problem at the moment being the laptop on which I have my latest
 working version ain't taking well to getting powered up.
 
 ARG.,
Laptops are, in my experience fragile little beasties.


So, this discussion has led me to think about a structure like:
 import numarray

 class PointHolder(object):
 def __init__(self):
 self.points  = numarray.array((0., 0., 0.))
 self.nextalloc = 0

 def new(self, point):
 if self.nextalloc = self.points[0]:
 self.points.resize(((self.points.shape[0] * 2,)
 + self.points.shape[1:]))
 result = self.nextalloc
 self.points[result] = point
 self.nextalloc += 1
 return result

 def positions(self, index):
 return self.points[index]

 class Vertex(object):
 positions = PointHolder()

 def __init__(self, point):
 self.location = self.positions.new(point)

 def position(self):
 seturn self.positions.position(self.location)


A Vertex is a point on a polyhedron and it is shared by all of
the faces that contain it.  The 3-space position of the point is
kept remotely in a numarray (or Numeric if you prefer) array
named Vertex.positions.points; the position of a particular Vertex
is available as a method.

The value of such a system is that you can apply a transformation
(scale, shift, rotate, ...) to all points in a single matrix operation.
The work to do such transformations would be proportional to the number
of distinct vertices, rather than to the number of mentions in such
structures as faces making up a polygon.

What got me thinking about this was why would you want to share mutable
state on complexes (and then on points) -- the answer is when you are
applying a uniform transformation to a bunch of points.

--Scott David Daniels
[EMAIL PROTECTED]

___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Properties use case

2006-03-19 Thread Arthur
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of kirby urner
 Sent: Sunday, March 19, 2006 10:58 AM

  Arthur is a really smart guy -- 
 knows enough to get himself in real trouble.  

And generally have. 

Just a little more cautious, with age, about the kind of trouble ;)

Art


___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig


Re: [Edu-sig] Properties use case

2006-03-19 Thread Arthur
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] 

 On Behalf Of Scott David Daniels

 What got me thinking about this was why would you want to 
 share mutable state on complexes (and then on points) -- 
 the answer is when you are applying a uniform transformation 
 to a bunch of points.

A lot of what I am doing is about uniform transformations on bunches of
points - so I will be looking carefully at the idea you are presenting.

To some extent it has been almost scary how straight forward what I am
trying to do can be expressed/implemented in Python.  Understanding what
__iter__, combined with duck typing, can get me in terms of what I am trying
to express was the most recent major revelation.

Art



___
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig