[Tutor] Triangle structure for triangulation

Alan Gauld alan.gauld at btinternet.com
Thu Aug 30 17:33:34 CEST 2007


"János Juhász" <janos.juhasz at VELUX.com> wrote

> ## I can translate it into python in this way
> class Triangle:
>    def __init__(self, points, neighbours):
>        self.points = points
>        self.neighbours = neighbours
>
>      def TOR(self, direction):
>        return (self, (direction+1)%3)
>
>      def ROT(self, direction):
>        return (self, (direction+2)%3)
>
>      def RIGHT(self, direction):
>        return (self.neighbours[(direction+2)%3])
>
> I would ask your opinions to encapsulate a triangle into a directed
> triangle.

I'm not totally sure what you are looking for but my first
guess would be to add a direction argument to the init
and store it as an attribute. But it sounds like you need
to add some methods too. What do you do with these
triangles? From your descriptionI'd expect to see some
methods taking other triangles as arguments?

For example you store the points but never use them.
Attributes in a class shjould be thee to support the metjods.
If the atrributes are not used by any method that implies
that they are not needed or that you are accessing them
from some function outside the class, which is probably
an indication of bad OO design.

> I made my first trial on the way to keep a directed triangle as a 
> tuple
> (triangle, direction)  and register it in that way.

> I would like to use directed triangles, but wouldn't like to use too 
> much
> memory.

How much memory would be too much?

If you don't know, then go with the best design and optimise the
memory only when you know that there is a need.
Prematurely optimising memory is just as bad as prematurely
optimising speed. It usually leads to bad code when there is no need.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list