From 320d2e1f3bcd1f2cdc057cab2958e0a808685259 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 1 Jul 2023 22:41:19 +0800 Subject: [PATCH] ... --- src/linalg.h | 9 +++++++++ src/linalg.pyi | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/linalg.h b/src/linalg.h index 806421df..193c5e77 100644 --- a/src/linalg.h +++ b/src/linalg.h @@ -305,6 +305,12 @@ PyObject* py_var(VM*, const PyVec4&); PyObject* py_var(VM*, const Mat3x3&); PyObject* py_var(VM*, const PyMat3x3&); +#define BIND_VEC_ADDR(D) \ + vm->bind_method<0>(type, "addr", [](VM* vm, ArgsView args){ \ + PyVec##D& self = _CAST(PyVec##D&, args[0]); \ + return VAR_T(VoidP, &self.x); \ + }); + #define BIND_VEC_VEC_OP(D, name, op) \ vm->bind_method<1>(type, #name, [](VM* vm, ArgsView args){ \ PyVec##D& self = _CAST(PyVec##D&, args[0]); \ @@ -385,6 +391,7 @@ struct PyVec2: Vec2 { return VAR(self); }); + BIND_VEC_ADDR(2) BIND_VEC_VEC_OP(2, __add__, +) BIND_VEC_VEC_OP(2, __sub__, -) BIND_VEC_FLOAT_OP(2, __mul__, *) @@ -433,6 +440,7 @@ struct PyVec3: Vec3 { return VAR_T(PyVec3, self); }); + BIND_VEC_ADDR(3) BIND_VEC_VEC_OP(3, __add__, +) BIND_VEC_VEC_OP(3, __sub__, -) BIND_VEC_FLOAT_OP(3, __mul__, *) @@ -483,6 +491,7 @@ struct PyVec4: Vec4{ return VAR_T(PyVec4, self); }); + BIND_VEC_ADDR(4) BIND_VEC_VEC_OP(4, __add__, +) BIND_VEC_VEC_OP(4, __sub__, -) BIND_VEC_FLOAT_OP(4, __mul__, *) diff --git a/src/linalg.pyi b/src/linalg.pyi index 918f30d0..ea3dff2d 100644 --- a/src/linalg.pyi +++ b/src/linalg.pyi @@ -1,4 +1,5 @@ from typing import overload +from c import float_p class vec2: x: float @@ -16,6 +17,7 @@ class vec2: def length_squared(self) -> float: ... def normalize(self) -> vec2: ... def rotate(self, radians: float) -> vec2: ... + def addr(self) -> float_p: ... class vec3: x: float @@ -33,6 +35,7 @@ class vec3: def length(self) -> float: ... def length_squared(self) -> float: ... def normalize(self) -> vec3: ... + def addr(self) -> float_p: ... class vec4: x: float @@ -50,6 +53,7 @@ class vec4: def length(self) -> float: ... def length_squared(self) -> float: ... def normalize(self) -> vec4: ... + def addr(self) -> float_p: ... class mat3x3: _11: float