[Python-Dev] Second post: PEP 557, Data Classes
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Nov 27 08:14:28 EST 2017
Chris Angelico wrote:
> I'm not sure there's any distinction between a "point" and a "vector
> from the origin to a point".
They transform differently. For example, translation affects
a point, but makes no difference to a vector.
There are two ways of dealing with that. One is to use vectors
to represent both and have two different operations, "transform
point" and "transform vector".
The other is to represent them using different types and have
one operation that does different things depending on the
type.
The advantage of the latter is that you can't accidentally
apply the wrong operation, e.g. transform_point on something
that's actually a vector.
(There's actually a third way -- use homogeneous coordinates
and represent points as (x, y, z, 1) and vectors as
(x, y, z, 0). But that's really a variation on the "different
types" idea.)
--
Greg
More information about the Python-Dev
mailing list