Points and Vectors in 3D

Spacen Jasset spacenjasset at yahoo.co.uk
Sun Mar 13 04:07:36 PDT 2011


On 13/03/2011 00:06, Bekenn wrote:
> On 3/12/2011 2:20 PM, Simon wrote:
>> I've done lots of 3d over the years and used quite a lot of different
>> libraries and I've come to prefer code that makes a distinction between
>> points and vectors.
>
> Agreed. This has some nice benefits with operator overloading, as well:
>
> vec v = ...;
> pt p = ...;
> auto p2 = p + v; // p2 is pt
> auto p3 = p + p2; // error
> auto v2 = v + v; // v2 is vec
>
> ...and with properties:
>
> p.x = 5; // p is pt, sets p._vals[0]
> v.dx = 3; // v is vec, sets v._vals[0]
Would you then go on to define things like a cross product as an 
operator overload?


More information about the Digitalmars-d-learn mailing list