mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
allow vec2(vec2i)
This commit is contained in:
parent
6266161118
commit
05e1de4101
@ -48,7 +48,10 @@ class vec2(_vecF['vec2']):
|
|||||||
def with_y(self, y: float) -> vec2: ...
|
def with_y(self, y: float) -> vec2: ...
|
||||||
def with_z(self, z: float) -> vec3: ...
|
def with_z(self, z: float) -> vec3: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
def __init__(self, x: float, y: float) -> None: ...
|
def __init__(self, x: float, y: float) -> None: ...
|
||||||
|
@overload
|
||||||
|
def __init__(self, xy: vec2i) -> None: ...
|
||||||
|
|
||||||
def rotate(self, radians: float) -> vec2: ...
|
def rotate(self, radians: float) -> vec2: ...
|
||||||
|
|
||||||
@ -159,7 +162,10 @@ class vec3(_vecF['vec3']):
|
|||||||
def with_z(self, z: float) -> vec3: ...
|
def with_z(self, z: float) -> vec3: ...
|
||||||
def with_xy(self, xy: vec2) -> vec3: ...
|
def with_xy(self, xy: vec2) -> vec3: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
def __init__(self, x: float, y: float, z: float) -> None: ...
|
def __init__(self, x: float, y: float, z: float) -> None: ...
|
||||||
|
@overload
|
||||||
|
def __init__(self, xyz: vec3i) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,11 +110,18 @@ static py_Ref _const(py_Type type, const char* name) {
|
|||||||
|
|
||||||
#define DEF_VECTOR_OPS(D) \
|
#define DEF_VECTOR_OPS(D) \
|
||||||
static bool vec##D##__new__(int argc, py_Ref argv) { \
|
static bool vec##D##__new__(int argc, py_Ref argv) { \
|
||||||
PY_CHECK_ARGC(D + 1); \
|
|
||||||
c11_vec##D res; \
|
c11_vec##D res; \
|
||||||
|
if(argc == 2) { \
|
||||||
|
PY_CHECK_ARG_TYPE(1, tp_vec##D##i); \
|
||||||
|
c11_vec##D##i v = py_tovec##D##i(&argv[1]); \
|
||||||
|
for(int i = 0; i < D; i++) \
|
||||||
|
res.data[i] = v.data[i]; \
|
||||||
|
} else { \
|
||||||
|
PY_CHECK_ARGC(D + 1); \
|
||||||
for(int i = 0; i < D; i++) { \
|
for(int i = 0; i < D; i++) { \
|
||||||
if(!py_castfloat32(&argv[i + 1], &res.data[i])) return false; \
|
if(!py_castfloat32(&argv[i + 1], &res.data[i])) return false; \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
py_newvec##D(py_retval(), res); \
|
py_newvec##D(py_retval(), res); \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
|
@ -400,3 +400,8 @@ a[vec2i(1, 2)] = 1
|
|||||||
assert a[vec2i(1, 2)] == 1
|
assert a[vec2i(1, 2)] == 1
|
||||||
a[vec3i(1, 2, 3)] = 2
|
a[vec3i(1, 2, 3)] = 2
|
||||||
assert a[vec3i(1, 2, 3)] == 2
|
assert a[vec3i(1, 2, 3)] == 2
|
||||||
|
|
||||||
|
assert vec2(vec2i.LEFT) == vec2(-1, 0)
|
||||||
|
assert vec2(vec2i.RIGHT) == vec2(1, 0)
|
||||||
|
assert vec3(vec3i.ONE) == vec3(1, 1, 1)
|
||||||
|
assert vec3(vec3i.ZERO) == vec3(0, 0, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user