-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_simple.py
More file actions
109 lines (93 loc) · 3.49 KB
/
test_simple.py
File metadata and controls
109 lines (93 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""
简单测试,不依赖外部库
"""
import sys
import os
# 添加项目根目录到Python路径
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, project_root)
import math
# 测试数学库
print("Testing math library...")
# 导入核心数学模块
try:
from core.math.vector import Vector3
from core.math.matrix import Matrix3
from core.math.quaternion import Quaternion
from core.math.math_utils import MathUtils
# 测试Vector3
print("\n1. Testing Vector3:")
v1 = Vector3(1, 2, 3)
v2 = Vector3(4, 5, 6)
print(f" v1 = {v1}")
print(f" v2 = {v2}")
print(f" v1 + v2 = {v1 + v2}")
print(f" v1 · v2 = {v1.dot(v2)}")
print(f" |v1| = {v1.magnitude()}")
# 测试Matrix3
print("\n2. Testing Matrix3:")
m1 = Matrix3.identity()
m2 = Matrix3.rotation_x(math.pi/2)
print(f" Identity matrix: {m1}")
print(f" Rotation X 90° matrix created")
# 测试Quaternion
print("\n3. Testing Quaternion:")
q1 = Quaternion.identity()
q2 = Quaternion.from_axis_angle(Vector3(1, 0, 0), math.pi/2)
print(f" Identity quaternion: {q1}")
print(f" Rotation X 90° quaternion: {q2}")
# 测试MathUtils
print("\n4. Testing MathUtils:")
print(f" clamp(5, 0, 10) = {MathUtils.clamp(5, 0, 10)}")
print(f" lerp(0, 10, 0.5) = {MathUtils.lerp(0, 10, 0.5)}")
print(f" 180° in radians = {MathUtils.deg_to_rad(180)}")
print("✅ Math library tests passed!")
except ImportError as e:
print(f"❌ Math library import error: {e}")
# 测试刚体
print("\n5. Testing RigidBody (basic):")
try:
from core.physics.rigid_body import RigidBody
body = RigidBody(mass=1.0, position=Vector3(0, 5, 0))
print(f" Created rigid body: mass={body.mass}, position={body.position}")
print("✅ RigidBody test passed!")
except ImportError as e:
print(f"❌ RigidBody import error: {e}")
# 测试碰撞形状
print("\n6. Testing CollisionShape (basic):")
try:
from core.collision.collision_shape import SphereShape, BoxShape
sphere = SphereShape(radius=1.0)
box = BoxShape(half_extents=Vector3(1, 1, 1))
print(f" Created sphere: radius={sphere.radius}")
print(f" Created box: half_extents={box.half_extents}")
print("✅ CollisionShape test passed!")
except ImportError as e:
print(f"❌ CollisionShape import error: {e}")
# 测试分子
print("\n7. Testing Molecule (basic):")
try:
# 直接导入,避免相对导入问题
import molecular.molecule as mol_module
Atom = mol_module.Atom
AtomType = mol_module.AtomType
Molecule = mol_module.Molecule
# 创建原子时避免除零错误
atom = Atom(AtomType.HYDROGEN, position=Vector3(0, 0, 0), mass=1.0)
molecule = Molecule("Test")
molecule.add_atom(atom)
print(f" Created atom: type={atom.atom_type.name}")
print(f" Created molecule: name={molecule.name}, atoms={len(molecule.atoms)}")
print("✅ Molecule test passed!")
except ImportError as e:
print(f"❌ Molecule import error: {e}")
except Exception as e:
print(f"❌ Molecule test error: {type(e).__name__}: {e}")
print("\n" + "="*50)
print("Project structure validation complete!")
print("\nTo run the full demo, install dependencies:")
print(" pip install numpy scipy pygame pyopengl matplotlib")
print("\nThen run:")
print(" cd examples")
print(" python demo_physics.py")