allow vectors to be assigned from arrays of convertible types
This commit is contained in:
parent
0120100cc7
commit
e10033bb74
14
math.d
14
math.d
@ -100,12 +100,18 @@ struct Vector(T, int N)
|
||||
}
|
||||
}
|
||||
|
||||
ref Vector opAssign(U)(U x) if (is(U: T))
|
||||
ref Vector opAssign(U)(U x) if (is(U: T) || isAssignable!(T, U))
|
||||
{
|
||||
mixin(GenerateLoop!("v[@] = x;", N)());
|
||||
return this;
|
||||
}
|
||||
|
||||
ref Vector opAssign(U)(U u) if (isStaticArray!(U) && U.length == N && isAssignable!(T, typeof(*U.init.ptr)))
|
||||
{
|
||||
mixin(GenerateLoop!("v[@] = u[@];", N)());
|
||||
return this;
|
||||
}
|
||||
|
||||
ref Vector opAssign(U)(U u) if (is(U : Vector))
|
||||
{
|
||||
v[] = u.v[];
|
||||
@ -1113,4 +1119,10 @@ unittest
|
||||
assert(v3 == v4, "Vec3 CrossN failure");
|
||||
}
|
||||
*/
|
||||
|
||||
{ // Vectors
|
||||
u32[4] arr = [1, 2, 3, 4];
|
||||
Vec4 vec = Vec4(arr);
|
||||
assert(vec == Vec4(1.0, 2.0, 3.0, 4.0));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user