[Edu-sig] Properties use case
Scott David Daniels
Scott.Daniels at Acm.Org
Sun Mar 19 17:22:44 CET 2006
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.
>
> ARGHHHH.,
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
Scott.Daniels at Acm.Org
More information about the Edu-sig
mailing list