Beispiel #1
0
def Vector(*args):
    from taichi.core import tc_core
    if isinstance(args[0], tc_core.Vector2f):
        return args[0]
    if isinstance(args[0], tc_core.Vector3f):
        return args[0]
    if isinstance(args[0], tc_core.Vector4f):
        return args[0]
    if isinstance(args[0], tuple):
        args = tuple(*args)
    if len(args) == 2:
        return tc_core.Vector2f(float(args[0]), float(args[1]))
    elif len(args) == 3:
        return tc_core.Vector3f(float(args[0]), float(args[1]), float(args[2]))
    elif len(args) == 4:
        return tc_core.Vector4f(float(args[0]), float(args[1]), float(args[2]),
                                float(args[3]))
    else:
        assert False, type(args[0])
Beispiel #2
0
def vec(*args):
    from taichi.core import tc_core
    if isinstance(args[0], tc_core.Vector2f):
        return args[0]
    if isinstance(args[0], tc_core.Vector3f):
        return args[0]
    if isinstance(args[0], tc_core.Vector4f):
        return args[0]
    if isinstance(args[0], tc_core.Vector2d):
        return args[0]
    if isinstance(args[0], tc_core.Vector3d):
        return args[0]
    if isinstance(args[0], tc_core.Vector4d):
        return args[0]
    if isinstance(args[0], tuple):
        args = tuple(*args)
    if tc_core.get_default_float_size() == 4:
        if len(args) == 2:
            return tc_core.Vector2f(float(args[0]), float(args[1]))
        elif len(args) == 3:
            return tc_core.Vector3f(float(args[0]), float(args[1]),
                                    float(args[2]))
        elif len(args) == 4:
            return tc_core.Vector4f(float(args[0]), float(args[1]),
                                    float(args[2]), float(args[3]))
        else:
            assert False, type(args[0])
    else:
        if len(args) == 2:
            return tc_core.Vector2d(float(args[0]), float(args[1]))
        elif len(args) == 3:
            return tc_core.Vector3d(float(args[0]), float(args[1]),
                                    float(args[2]))
        elif len(args) == 4:
            return tc_core.Vector4d(float(args[0]), float(args[1]),
                                    float(args[2]), float(args[3]))
        else:
            assert False, type(args[0])