1 module polyplex.math.geometry; 2 import polyplex.math.vector; 3 4 alias Ray2D = RayT!float2; 5 alias Ray = RayT!float3; 6 /// A ray that supports two and three dimensions 7 struct RayT(VT) if(is(VT==float2) || is(VT==float3)) { 8 public VT ori; 9 public VT dir; 10 immutable alias VectorType = VT; 11 12 /// Constructs a ray with an origin and direction 13 public this ( VT origin, VT direction ) pure nothrow { 14 ori = origin; 15 dir = direction; 16 } 17 18 /// Returns a ray with a normalized ray direction 19 RayT!VT Normalize ( ) pure nothrow { 20 return RayT!VT(ori, dir.Normalize); 21 } 22 } 23 24 unittest { 25 import std.traits; 26 assert(__traits(compiles, Ray(float3(0.5f), float3(0.2f, 0.7f, 0f).Normalize))); 27 assert(__traits(compiles, Ray(float3(0.5f), float3(0.2f, 0.7f, 0f)).Normalize)); 28 }