mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
a97323bcd4
commit
d4bde2fcdd
@ -17,6 +17,7 @@ class vec2:
|
|||||||
def length_squared(self) -> float: ...
|
def length_squared(self) -> float: ...
|
||||||
def normalize(self) -> vec2: ...
|
def normalize(self) -> vec2: ...
|
||||||
def rotate(self, radians: float) -> vec2: ...
|
def rotate(self, radians: float) -> vec2: ...
|
||||||
|
def rotate_(self, radians: float) -> None: ...
|
||||||
def addr(self) -> float_p: ...
|
def addr(self) -> float_p: ...
|
||||||
|
|
||||||
class vec3:
|
class vec3:
|
||||||
|
@ -83,6 +83,18 @@ namespace pkpy{
|
|||||||
return VAR(self);
|
return VAR(self);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vm->bind_method<1>(type, "rotate_", [](VM* vm, ArgsView args){
|
||||||
|
Vec2& self = _CAST(PyVec2&, args[0]);
|
||||||
|
float radian = CAST(f64, args[1]);
|
||||||
|
float cr = cosf(radian);
|
||||||
|
float sr = sinf(radian);
|
||||||
|
Mat3x3 rotate(cr, -sr, 0.0f,
|
||||||
|
sr, cr, 0.0f,
|
||||||
|
0.0f, 0.0f, 1.0f);
|
||||||
|
self = rotate.transform_vector(self);
|
||||||
|
return vm->None;
|
||||||
|
});
|
||||||
|
|
||||||
BIND_VEC_ADDR(2)
|
BIND_VEC_ADDR(2)
|
||||||
BIND_VEC_VEC_OP(2, __add__, +)
|
BIND_VEC_VEC_OP(2, __add__, +)
|
||||||
BIND_VEC_VEC_OP(2, __sub__, -)
|
BIND_VEC_VEC_OP(2, __sub__, -)
|
||||||
|
@ -38,6 +38,12 @@ radians = random.uniform(-10*math.pi, 10*math.pi)
|
|||||||
test_vec2_copy = rotated_vec2(test_vec2_copy, radians)
|
test_vec2_copy = rotated_vec2(test_vec2_copy, radians)
|
||||||
assert test_vec2.rotate(radians).__dict__ == test_vec2_copy.__dict__
|
assert test_vec2.rotate(radians).__dict__ == test_vec2_copy.__dict__
|
||||||
|
|
||||||
|
# test rotate_
|
||||||
|
a = test_vec2.rotate(0.7)
|
||||||
|
assert a is not test_vec2
|
||||||
|
b = test_vec2.rotate_(0.7)
|
||||||
|
assert b is None
|
||||||
|
assert a == test_vec2
|
||||||
|
|
||||||
# test vec3--------------------------------------------------------------------
|
# test vec3--------------------------------------------------------------------
|
||||||
# 生成随机测试目标
|
# 生成随机测试目标
|
||||||
|
Loading…
x
Reference in New Issue
Block a user