Points and Vectors in 3D

Bekenn leaveme at alone.com
Sat Mar 12 16:06:17 PST 2011


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]


More information about the Digitalmars-d-learn mailing list