def apply(self, a): if isinstance(a, Scalar) and isVec2TypeName(self.out_type): a = a.toVec2() elif isinstance(a, Scalar) and isVec3TypeName(self.out_type): a = a.toVec3() elif isinstance(a, Scalar) and isVec4TypeName(self.out_type): a = a.toVec4() b = IN_VALUES["float"] out = [Scalar(x) + y for x, y in zip(a.getScalars(), b)] if self.out_type == "float": return out[0].toFloat() elif self.out_type == "uint": return out[0].toUint() elif self.out_type == "vec2": return Vec2(out[0], out[1]).toFloat() elif self.out_type == "uvec2": return Vec2(out[0], out[1]).toUint() elif self.out_type == "vec3": return Vec3(out[0], out[1], out[2]).toFloat() elif self.out_type == "uvec3": return Vec3(out[0], out[1], out[2]).toUint() elif self.out_type == "vec4": return Vec4(out[0], out[1], out[2], out[3]).toFloat() elif self.out_type == "uvec4": return Vec4(out[0], out[1], out[2], out[3]).toUint()
def get_operand(self): operands = { "float": Scalar(2.0), "vec2": Vec2(1.0, 2.0), "vec3": Vec3(1.0, 2.0, 3.0), "vec4": Vec4(1.0, 2.0, 3.0, 4.0), "uint": Uint(2), "uvec2": UVec2(1, 2), "uvec3": UVec3(1, 2, 3), "uvec4": UVec4(1, 2, 3, 4), } assert self.out_type in operands return operands[self.out_type]
(2, 1, 2, 6), (3, 7, 2, 5), ] IN_UVECTOR = [ (2, 3, 5, 8), (4, 6, 2, 9), (1, 13, 7, 4), ] IN_VALUES = { "int": [Scalar(x) for x in IN_ISCALAR], "uint": [Scalar(x) for x in IN_USCALAR], "ivec2": [Vec2(x[0], x[1]) for x in IN_IVECTOR], "uvec2": [Vec2(x[0], x[1]) for x in IN_UVECTOR], "ivec3": [Vec3(x[0], x[1], x[2]) for x in IN_IVECTOR], "uvec3": [Vec3(x[0], x[1], x[2]) for x in IN_UVECTOR], "ivec4": [Vec4(x[0], x[1], x[2], x[3]) for x in IN_IVECTOR], "uvec4": [Vec4(x[0], x[1], x[2], x[3]) for x in IN_UVECTOR], "float": [Scalar(x).toFloat() for x in IN_ISCALAR], "vec2": [Vec2(x[0], x[1]).toFloat() for x in IN_IVECTOR], "vec3": [Vec3(x[0], x[1], x[2]).toFloat() for x in IN_IVECTOR], "vec4": [Vec4(x[0], x[1], x[2], x[3]).toFloat() for x in IN_IVECTOR], } VALID_CONVERSIONS = { "int": ["float", "uint"], "uint": ["float"], "ivec2": ["uvec2", "vec2"], "uvec2": ["vec2"], "ivec3": ["uvec3", "vec3"],