- All Points are Vectors, and all Vectors are Points.
- All Directions are Vectors, NOT all Vectors are Directions (this shouldn't mean both way conversion shouldn't be allowed).
I want to have the operators overridden once for all preferably since they're all completely identical. In C++ I can just define class Vector { float x,y,z; }, and do typedef Point = Vector, typedef Direction = Vector; In C# there is no equivalent ("using Point=Vector;" sucks as you have to place it in every single document you use, and it's not enforced by the compiler).
I tried to define 3 different classes and override the operators for each, then do implicit type casting which would make the code run slower, etc.
I tried defining just Vector, then Point:Vector and Direction:Vector, this way I only write the operators once but then I can't do implicit type casting Point <-> Vector or Direction <->Vector.
I could simply define the Vector class and use that everywhere, but that would create ambiguity as to weather a variable is supposed to be a position in space (Point), a relative position in space (Vector) or a unit vector (Direction). For example the function:
Vector GetOrthogon(Vector a, Vector b) {
// ....
}
You can't know whether it's expecting any vectors or unit vectors. In C++ you could do that, so why not in C#?
So what's the best way to implement these in C#?
Note: having structs instead of classes would be ideal if possible.