mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
...
This commit is contained in:
parent
8b32296c9c
commit
e2d4f57859
@ -1,117 +0,0 @@
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
def malloc(size: int) -> 'void_p': ...
|
||||
def free(ptr: 'void_p') -> None: ...
|
||||
def memset(ptr: 'void_p', value: int, size: int) -> None: ...
|
||||
def memcpy(dst: 'void_p', src: 'void_p', size: int) -> None: ...
|
||||
|
||||
T = TypeVar('T')
|
||||
Tp = TypeVar('Tp', bound='void_p')
|
||||
|
||||
def p_cast(ptr: 'void_p', cls: type[T]) -> T:
|
||||
"""Cast a pointer to a specific type."""
|
||||
def p_value(ptr: 'void_p') -> int:
|
||||
"""Get the value of a pointer."""
|
||||
def pp_deref(ptr: Tp) -> Tp:
|
||||
"""Dereference a double pointer."""
|
||||
|
||||
class void_p:
|
||||
def __init__(self, addr: int): ...
|
||||
def __eq__(self, other: 'void_p') -> bool: ...
|
||||
def __ne__(self, other: 'void_p') -> bool: ...
|
||||
def __lt__(self, other: 'void_p') -> bool: ...
|
||||
def __le__(self, other: 'void_p') -> bool: ...
|
||||
def __gt__(self, other: 'void_p') -> bool: ...
|
||||
def __ge__(self, other: 'void_p') -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def __repr__(self) -> str: ...
|
||||
|
||||
class Pointer(Generic[T], void_p):
|
||||
def read(self) -> T: ...
|
||||
def write(self, value: T) -> None: ...
|
||||
def __getitem__(self, index: int) -> T: ...
|
||||
def __setitem__(self, index: int, value: T) -> None: ...
|
||||
|
||||
class char_p(Pointer[int]):
|
||||
def read_string(self) -> str: ...
|
||||
def write_string(self, value: str) -> None: ...
|
||||
|
||||
class uchar_p(Pointer[int]): pass
|
||||
class short_p(Pointer[int]): pass
|
||||
class ushort_p(Pointer[int]): pass
|
||||
class int_p(Pointer[int]): pass
|
||||
class uint_p(Pointer[int]): pass
|
||||
class long_p(Pointer[int]): pass
|
||||
class ulong_p(Pointer[int]): pass
|
||||
class longlong_p(Pointer[int]): pass
|
||||
class ulonglong_p(Pointer[int]): pass
|
||||
class float_p(Pointer[float]): pass
|
||||
class double_p(Pointer[float]): pass
|
||||
class bool_p(Pointer[bool]): pass
|
||||
|
||||
class struct:
|
||||
def __init__(self, size: int): ...
|
||||
def addr(self) -> 'void_p': ...
|
||||
def copy(self) -> 'struct': ...
|
||||
def sizeof(self) -> int: ...
|
||||
def __eq__(self, other: 'struct') -> bool: ...
|
||||
def __ne__(self, other: 'struct') -> bool: ...
|
||||
|
||||
def hex(self) -> str: ...
|
||||
@staticmethod
|
||||
def fromhex(s: str) -> 'struct': ...
|
||||
|
||||
def read_char(self, offset=0) -> int: ...
|
||||
def read_uchar(self, offset=0) -> int: ...
|
||||
def read_short(self, offset=0) -> int: ...
|
||||
def read_ushort(self, offset=0) -> int: ...
|
||||
def read_int(self, offset=0) -> int: ...
|
||||
def read_uint(self, offset=0) -> int: ...
|
||||
def read_long(self, offset=0) -> int: ...
|
||||
def read_ulong(self, offset=0) -> int: ...
|
||||
def read_longlong(self, offset=0) -> int: ...
|
||||
def read_ulonglong(self, offset=0) -> int: ...
|
||||
def read_float(self, offset=0) -> float: ...
|
||||
def read_double(self, offset=0) -> float: ...
|
||||
def read_bool(self, offset=0) -> bool: ...
|
||||
def read_void_p(self, offset=0) -> 'void_p': ...
|
||||
def write_char(self, value: int, offset=0) -> None: ...
|
||||
def write_uchar(self, value: int, offset=0) -> None: ...
|
||||
def write_short(self, value: int, offset=0) -> None: ...
|
||||
def write_ushort(self, value: int, offset=0) -> None: ...
|
||||
def write_int(self, value: int, offset=0) -> None: ...
|
||||
def write_uint(self, value: int, offset=0) -> None: ...
|
||||
def write_long(self, value: int, offset=0) -> None: ...
|
||||
def write_ulong(self, value: int, offset=0) -> None: ...
|
||||
def write_longlong(self, value: int, offset=0) -> None: ...
|
||||
def write_ulonglong(self, value: int, offset=0) -> None: ...
|
||||
def write_float(self, value: float, offset=0) -> None: ...
|
||||
def write_double(self, value: float, offset=0) -> None: ...
|
||||
def write_bool(self, value: bool, offset=0) -> None: ...
|
||||
def write_void_p(self, value: 'void_p', offset=0) -> None: ...
|
||||
|
||||
def char_(val: int) -> struct: ...
|
||||
def uchar_(val: int) -> struct: ...
|
||||
def short_(val: int) -> struct: ...
|
||||
def ushort_(val: int) -> struct: ...
|
||||
def int_(val: int) -> struct: ...
|
||||
def uint_(val: int) -> struct: ...
|
||||
def long_(val: int) -> struct: ...
|
||||
def ulong_(val: int) -> struct: ...
|
||||
def longlong_(val: int) -> struct: ...
|
||||
def ulonglong_(val: int) -> struct: ...
|
||||
def float_(val: float) -> struct: ...
|
||||
def double_(val: float) -> struct: ...
|
||||
def bool_(val: bool) -> struct: ...
|
||||
|
||||
class _StructLike(Generic[T]):
|
||||
def tostruct(self) -> struct: ...
|
||||
@classmethod
|
||||
def fromstruct(cls, s: struct) -> T: ...
|
||||
|
||||
def addr(self) -> 'Pointer[T]': ...
|
||||
def copy(self) -> T: ...
|
||||
def sizeof(self) -> int: ...
|
||||
def __eq__(self, other: T) -> bool: ...
|
||||
def __ne__(self, other: T) -> bool: ...
|
||||
|
@ -1,4 +1,4 @@
|
||||
from linalg import mat3x3, vec2, vec3, vec4
|
||||
from linalg import mat3x3, vec2, vec3
|
||||
import random
|
||||
import sys
|
||||
import math
|
||||
@ -69,25 +69,6 @@ element_value_list = [getattr(test_vec3, attr) for attr in element_name_list]
|
||||
copy_element_value_list = [getattr(test_vec3, attr) for attr in element_name_list]
|
||||
assert element_value_list == copy_element_value_list
|
||||
|
||||
# test vec4--------------------------------------------------------------------
|
||||
# 生成随机测试目标
|
||||
min_num = -10.0
|
||||
max_num = 10.0
|
||||
test_vec4 = vec4(*tuple([random.uniform(min_num, max_num) for _ in range(4)]))
|
||||
static_test_vec4_float = vec4(3.1886954323, -1098399.59932453432, 9.00000000000002765, 4565400000000.0000000045)
|
||||
static_test_vec4_int = vec4(278, -13919730938747, 1364223456756456, -37)
|
||||
|
||||
# test __repr__
|
||||
assert str(static_test_vec4_float).startswith('vec4(')
|
||||
assert str(static_test_vec4_int).startswith('vec4(')
|
||||
|
||||
# test copy
|
||||
element_name_list = ['x', 'y', 'z', 'w']
|
||||
element_value_list = [getattr(test_vec4, attr) for attr in element_name_list]
|
||||
copy_element_value_list = [getattr(test_vec4.copy(), attr) for attr in element_name_list]
|
||||
assert element_value_list == copy_element_value_list
|
||||
|
||||
|
||||
# test mat3x3--------------------------------------------------------------------
|
||||
def mat_to_str_list(mat):
|
||||
ret = [[0,0,0], [0,0,0], [0,0,0]]
|
||||
@ -446,13 +427,6 @@ assert test_mat_copy.inverse_transform_point(test_vec2_copy) == test_mat_copy.in
|
||||
# test inverse_transform_vector
|
||||
assert test_mat_copy.inverse_transform_vector(test_vec2_copy) == test_mat_copy.inverse().transform_vector(test_vec2_copy)
|
||||
|
||||
import c
|
||||
a = vec4(1, 2, 3, 4)
|
||||
b = a.tostruct()
|
||||
assert a.sizeof() == 16
|
||||
assert b.sizeof() == 16
|
||||
assert vec4.fromstruct(b) == a
|
||||
|
||||
val = vec2.angle(vec2(-1, 0), vec2(0, -1))
|
||||
assert 1.57 < val < 1.58
|
||||
|
||||
@ -466,12 +440,6 @@ class mymat3x3(mat3x3):
|
||||
|
||||
assert mymat3x3().f()
|
||||
|
||||
|
||||
# test assign
|
||||
c = vec4(1, 2, 3, 4)
|
||||
assert c.copy_(vec4(5, 6, 7, 8)) is None
|
||||
assert c == vec4(5, 6, 7, 8)
|
||||
|
||||
d = mat3x3.identity()
|
||||
assert d.copy_(mat3x3.zeros()) is None
|
||||
assert d == mat3x3.zeros()
|
||||
@ -491,9 +459,7 @@ except IndexError:
|
||||
# test vec * vec
|
||||
assert vec2(1, 2) * vec2(3, 4) == vec2(3, 8)
|
||||
assert vec3(1, 2, 3) * vec3(4, 5, 6) == vec3(4, 10, 18)
|
||||
assert vec4(1, 2, 3, 4) * vec4(5, 6, 7, 8) == vec4(5, 12, 21, 32)
|
||||
|
||||
# test vec.__getitem__
|
||||
assert vec2(1, 2)[0] == 1 and vec2(1, 2)[1] == 2
|
||||
assert vec3(1, 2, 3)[0] == 1 and vec3(1, 2, 3)[1] == 2 and vec3(1, 2, 3)[2] == 3
|
||||
assert vec4(1, 2, 3, 4)[0] == 1 and vec4(1, 2, 3, 4)[1] == 2 and vec4(1, 2, 3, 4)[2] == 3 and vec4(1, 2, 3, 4)[3] == 4
|
||||
assert vec3(1, 2, 3)[0] == 1 and vec3(1, 2, 3)[1] == 2 and vec3(1, 2, 3)[2] == 3
|
Loading…
x
Reference in New Issue
Block a user