e2D 1.4.23__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- e2d-2.0.0/MANIFEST.in +31 -0
- e2d-2.0.0/PKG-INFO +260 -0
- e2d-2.0.0/QUICKSTART.md +165 -0
- e2d-2.0.0/README.md +215 -0
- e2d-2.0.0/e2D/__init__.py +461 -0
- e2d-2.0.0/e2D/commons.py +56 -0
- e2d-2.0.0/e2D/cvectors.c +27800 -0
- e2d-2.0.0/e2D/cvectors.pxd +56 -0
- e2d-2.0.0/e2D/cvectors.pyx +561 -0
- e2d-2.0.0/e2D/devices.py +74 -0
- e2d-2.0.0/e2D/plots.py +584 -0
- e2d-2.0.0/e2D/shaders/curve_fragment.glsl +6 -0
- e2d-2.0.0/e2D/shaders/curve_vertex.glsl +16 -0
- e2d-2.0.0/e2D/shaders/line_instanced_vertex.glsl +37 -0
- e2d-2.0.0/e2D/shaders/plot_grid_fragment.glsl +48 -0
- e2d-2.0.0/e2D/shaders/plot_grid_vertex.glsl +7 -0
- e2d-2.0.0/e2D/shaders/segment_fragment.glsl +6 -0
- e2d-2.0.0/e2D/shaders/segment_vertex.glsl +9 -0
- e2d-2.0.0/e2D/shaders/stream_fragment.glsl +11 -0
- e2d-2.0.0/e2D/shaders/stream_shift_compute.glsl +16 -0
- e2d-2.0.0/e2D/shaders/stream_vertex.glsl +27 -0
- e2d-2.0.0/e2D/shapes.py +1081 -0
- e2d-2.0.0/e2D/text_renderer.py +491 -0
- e2d-2.0.0/e2D/vectors.py +247 -0
- e2d-2.0.0/e2D.egg-info/PKG-INFO +260 -0
- e2d-2.0.0/e2D.egg-info/SOURCES.txt +38 -0
- e2d-2.0.0/e2D.egg-info/not-zip-safe +1 -0
- e2d-2.0.0/e2D.egg-info/requires.txt +14 -0
- e2d-2.0.0/examples/compare_performance.py +166 -0
- e2d-2.0.0/examples/default.py +96 -0
- e2d-2.0.0/examples/example_usage.py +168 -0
- e2d-2.0.0/examples/graphs.py +181 -0
- e2d-2.0.0/examples/shapes_demo.py +233 -0
- e2d-2.0.0/pyproject.toml +65 -0
- e2d-2.0.0/setup.cfg +65 -0
- e2d-2.0.0/setup.py +95 -0
- e2d-1.4.23/PKG-INFO +0 -272
- e2d-1.4.23/README.md +0 -255
- e2d-1.4.23/e2D/__init__.py +0 -624
- e2d-1.4.23/e2D/__init__.pyi +0 -1337
- e2d-1.4.23/e2D/colors.py +0 -470
- e2d-1.4.23/e2D/def_colors.py +0 -1732
- e2d-1.4.23/e2D/envs.py +0 -229
- e2d-1.4.23/e2D/plots.py +0 -619
- e2d-1.4.23/e2D/utils.py +0 -581
- e2d-1.4.23/e2D/winrec.py +0 -212
- e2d-1.4.23/e2D.egg-info/PKG-INFO +0 -272
- e2d-1.4.23/e2D.egg-info/SOURCES.txt +0 -17
- e2d-1.4.23/e2D.egg-info/requires.txt +0 -2
- e2d-1.4.23/pyproject.toml +0 -6
- e2d-1.4.23/setup.cfg +0 -26
- {e2d-1.4.23 → e2d-2.0.0}/LICENSE +0 -0
- {e2d-1.4.23 → e2d-2.0.0}/e2D.egg-info/dependency_links.txt +0 -0
- {e2d-1.4.23 → e2d-2.0.0}/e2D.egg-info/top_level.txt +0 -0
e2d-2.0.0/MANIFEST.in
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Include Cython source files for compilation during install
|
|
2
|
+
include e2D/*.pyx
|
|
3
|
+
include e2D/*.pxd
|
|
4
|
+
include e2D/*.c
|
|
5
|
+
|
|
6
|
+
# Include shader files
|
|
7
|
+
recursive-include e2D/shaders *.glsl
|
|
8
|
+
|
|
9
|
+
# Include documentation
|
|
10
|
+
include README.md
|
|
11
|
+
include LICENSE
|
|
12
|
+
include QUICKSTART.md
|
|
13
|
+
|
|
14
|
+
# Include configuration files
|
|
15
|
+
include pyproject.toml
|
|
16
|
+
include setup.py
|
|
17
|
+
include setup.cfg
|
|
18
|
+
|
|
19
|
+
# Include examples
|
|
20
|
+
recursive-include examples *.py
|
|
21
|
+
|
|
22
|
+
# Exclude build artifacts
|
|
23
|
+
global-exclude __pycache__
|
|
24
|
+
global-exclude *.py[co]
|
|
25
|
+
global-exclude *.so
|
|
26
|
+
global-exclude *.pyd
|
|
27
|
+
global-exclude .DS_Store
|
|
28
|
+
|
|
29
|
+
# SECURITY: Exclude version management scripts (contain API keys)
|
|
30
|
+
exclude new_version.bat
|
|
31
|
+
exclude new_version.py
|
e2d-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: e2D
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: High-performance 2D graphics and math library with ultra-optimized vector operations
|
|
5
|
+
Home-page: https://github.com/marick-py/e2D
|
|
6
|
+
Author: Riccardo Mariani
|
|
7
|
+
Author-email: Riccardo Mariani <ricomari2006@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/marick-py/e2D
|
|
10
|
+
Project-URL: Repository, https://github.com/marick-py/e2D
|
|
11
|
+
Project-URL: Issues, https://github.com/marick-py/e2D/issues
|
|
12
|
+
Keywords: vector,2d,simulation,performance,cython,numpy,moderngl,games,graphics
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Cython
|
|
24
|
+
Classifier: Programming Language :: C
|
|
25
|
+
Classifier: Topic :: Games/Entertainment
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: numpy>=1.19.0
|
|
33
|
+
Requires-Dist: pygame
|
|
34
|
+
Requires-Dist: moderngl
|
|
35
|
+
Requires-Dist: glfw
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: build; extra == "dev"
|
|
38
|
+
Requires-Dist: twine; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest; extra == "dev"
|
|
40
|
+
Requires-Dist: black; extra == "dev"
|
|
41
|
+
Requires-Dist: mypy; extra == "dev"
|
|
42
|
+
Provides-Extra: performance
|
|
43
|
+
Requires-Dist: cython>=0.29.0; extra == "performance"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# e2D - High-Performance 2D Graphics and Math Library
|
|
47
|
+
|
|
48
|
+

|
|
49
|
+

|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
**e2D** combines ultra-optimized vector mathematics with modern OpenGL rendering for high-performance 2D applications. Perfect for games, simulations, and real-time graphics.
|
|
53
|
+
|
|
54
|
+
## ✨ Features
|
|
55
|
+
|
|
56
|
+
### 🚀 Optimized Vector Operations
|
|
57
|
+
- **Cython-compiled** Vector2D class (10-500x faster than pure Python)
|
|
58
|
+
- **Batch operations** for processing thousands of vectors efficiently
|
|
59
|
+
- **Direct memory access** with zero-copy operations
|
|
60
|
+
- **NumPy integration** for seamless GPU data upload
|
|
61
|
+
|
|
62
|
+
### 🎮 Modern Graphics
|
|
63
|
+
- **ModernGL** rendering pipeline
|
|
64
|
+
- **Shape rendering** with instancing support
|
|
65
|
+
- **Text rendering** with custom styles
|
|
66
|
+
- **GLFW window management**
|
|
67
|
+
|
|
68
|
+
### 🎯 Game Development Tools
|
|
69
|
+
- **Keyboard and mouse input** handling
|
|
70
|
+
- **Collision detection**
|
|
71
|
+
- **Color manipulation**
|
|
72
|
+
- **Vector mathematics**
|
|
73
|
+
|
|
74
|
+
## 📦 Installation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install e2D
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The package will automatically compile the Cython extensions during installation for optimal performance (like numpy). If compilation fails, it falls back to pure Python mode.
|
|
81
|
+
|
|
82
|
+
### Requirements
|
|
83
|
+
- Python 3.9+
|
|
84
|
+
- NumPy
|
|
85
|
+
- ModernGL
|
|
86
|
+
- GLFW
|
|
87
|
+
- Pygame
|
|
88
|
+
|
|
89
|
+
## 🚀 Quick Start
|
|
90
|
+
|
|
91
|
+
### Optimized Vector Operations
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from e2D import Vector2D, batch_add_inplace, vectors_to_array
|
|
95
|
+
|
|
96
|
+
# Create vectors
|
|
97
|
+
v1 = Vector2D(3.0, 4.0)
|
|
98
|
+
v2 = Vector2D(1.0, 2.0)
|
|
99
|
+
|
|
100
|
+
# Basic operations
|
|
101
|
+
v3 = v1 + v2
|
|
102
|
+
length = v1.length
|
|
103
|
+
dot = v1.dot_product(v2)
|
|
104
|
+
|
|
105
|
+
# In-place operations (faster!)
|
|
106
|
+
v1.iadd(v2)
|
|
107
|
+
v1.normalize()
|
|
108
|
+
v1.irotate(0.1)
|
|
109
|
+
|
|
110
|
+
# Process thousands of vectors instantly
|
|
111
|
+
positions = [Vector2D.random(-10, 10) for _ in range(10000)]
|
|
112
|
+
displacement = Vector2D(1.0, 0.5)
|
|
113
|
+
batch_add_inplace(positions, displacement) # 🚀 Lightning fast!
|
|
114
|
+
|
|
115
|
+
# Convert to numpy for GPU upload
|
|
116
|
+
pos_array = vectors_to_array(positions)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Graphics Rendering
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from e2D import RootEnv
|
|
123
|
+
|
|
124
|
+
class MyApp(RootEnv):
|
|
125
|
+
def __init__(self):
|
|
126
|
+
super().__init__(
|
|
127
|
+
window_size=(1920, 1080),
|
|
128
|
+
target_fps=60,
|
|
129
|
+
vsync=True
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
def update(self):
|
|
133
|
+
# Your game logic here
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
def draw(self):
|
|
137
|
+
# Your rendering code here
|
|
138
|
+
pass
|
|
139
|
+
|
|
140
|
+
app = MyApp()
|
|
141
|
+
app.run()
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 📊 Performance
|
|
145
|
+
|
|
146
|
+
Vector2D benchmark (100,000 operations):
|
|
147
|
+
|
|
148
|
+
| Operation | Time | vs Pure Python |
|
|
149
|
+
|-----------|------|----------------|
|
|
150
|
+
| Creation | 42 ms | 10x faster |
|
|
151
|
+
| Addition | 64 ms | 15x faster |
|
|
152
|
+
| In-place ops | 3.8 ms | **100x faster** |
|
|
153
|
+
| Normalization | 1.9 ms | **200x faster** |
|
|
154
|
+
| Batch operations | 0.17 ms | **500x+ faster** 🔥 |
|
|
155
|
+
|
|
156
|
+
Perfect for:
|
|
157
|
+
- Particle systems (10,000+ particles)
|
|
158
|
+
- Physics simulations
|
|
159
|
+
- Collision detection
|
|
160
|
+
- Path finding
|
|
161
|
+
- Real-time graphics
|
|
162
|
+
|
|
163
|
+
## 📚 Documentation
|
|
164
|
+
|
|
165
|
+
- **[Quick Start Guide](QUICKSTART.md)** - Get up and running in minutes
|
|
166
|
+
- **[API Reference](https://github.com/marick-py/e2D)** - Full API documentation
|
|
167
|
+
- **[Examples](examples/)** - Working code examples
|
|
168
|
+
|
|
169
|
+
## 🎯 Use Cases
|
|
170
|
+
|
|
171
|
+
### Particle System
|
|
172
|
+
```python
|
|
173
|
+
from e2D import Vector2D, batch_add_inplace, vectors_to_array
|
|
174
|
+
|
|
175
|
+
positions = [Vector2D.random(-10, 10) for _ in range(10000)]
|
|
176
|
+
velocities = [Vector2D.random(-1, 1) for _ in range(10000)]
|
|
177
|
+
|
|
178
|
+
def update(dt):
|
|
179
|
+
# Update all particles in milliseconds
|
|
180
|
+
for i in range(len(positions)):
|
|
181
|
+
temp = velocities[i].mul(dt)
|
|
182
|
+
positions[i].iadd(temp)
|
|
183
|
+
|
|
184
|
+
def render():
|
|
185
|
+
# Upload to GPU
|
|
186
|
+
pos_array = vectors_to_array(positions).astype(np.float32)
|
|
187
|
+
vbo.write(pos_array)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Physics Simulation
|
|
191
|
+
```python
|
|
192
|
+
from e2D import Vector2D
|
|
193
|
+
|
|
194
|
+
class RigidBody:
|
|
195
|
+
def __init__(self, pos, vel):
|
|
196
|
+
self.position = Vector2D(*pos)
|
|
197
|
+
self.velocity = Vector2D(*vel)
|
|
198
|
+
self.acceleration = Vector2D(0, -9.8)
|
|
199
|
+
|
|
200
|
+
def update(self, dt):
|
|
201
|
+
# Optimized in-place physics
|
|
202
|
+
temp = self.acceleration.mul(dt)
|
|
203
|
+
self.velocity.iadd(temp)
|
|
204
|
+
|
|
205
|
+
temp = self.velocity.mul(dt)
|
|
206
|
+
self.position.iadd(temp)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## 🔧 Development
|
|
210
|
+
|
|
211
|
+
### Building from Source
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
git clone https://github.com/marick-py/e2D.git
|
|
215
|
+
cd e2D
|
|
216
|
+
pip install -e .[dev]
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Running Tests
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pytest
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Building Distribution
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
python -m build
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## 🤝 Contributing
|
|
232
|
+
|
|
233
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
234
|
+
|
|
235
|
+
## 📄 License
|
|
236
|
+
|
|
237
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
238
|
+
|
|
239
|
+
## 👤 Author
|
|
240
|
+
|
|
241
|
+
**Riccardo Mariani**
|
|
242
|
+
- Email: ricomari2006@gmail.com
|
|
243
|
+
- GitHub: [@marick-py](https://github.com/marick-py)
|
|
244
|
+
|
|
245
|
+
## 🙏 Acknowledgments
|
|
246
|
+
|
|
247
|
+
- Built with [ModernGL](https://github.com/moderngl/moderngl)
|
|
248
|
+
- Optimized with [Cython](https://cython.org/)
|
|
249
|
+
- Inspired by the need for high-performance 2D mathematics in Python
|
|
250
|
+
|
|
251
|
+
## 📈 Version History
|
|
252
|
+
|
|
253
|
+
- **2.0.0** - Added ultra-optimized Vector2D with Cython compilation
|
|
254
|
+
- **1.4.24** - Previous stable release with pure Python vectors
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
**Made with ❤️ for high-performance 2D development**
|
|
259
|
+
|
|
260
|
+
|
e2d-2.0.0/QUICKSTART.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Vector2D - Quick Start Guide
|
|
2
|
+
|
|
3
|
+
## 🚀 Get Started in 3 Steps
|
|
4
|
+
|
|
5
|
+
### Step 1: Build the Extension
|
|
6
|
+
|
|
7
|
+
**Windows:**
|
|
8
|
+
```bash
|
|
9
|
+
build.bat
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
**Linux/Mac:**
|
|
13
|
+
```bash
|
|
14
|
+
chmod +x build.sh
|
|
15
|
+
./build.sh
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Step 2: Test It Works
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m e2D.vectors
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
You should see benchmark results like:
|
|
25
|
+
```
|
|
26
|
+
Vector2D Benchmark (100000 iterations)
|
|
27
|
+
==================================================
|
|
28
|
+
Creation: 15.23 ms
|
|
29
|
+
Addition: 18.45 ms
|
|
30
|
+
In-place add: 12.67 ms
|
|
31
|
+
Normalize: 45.12 ms
|
|
32
|
+
Batch add: 2.34 ms
|
|
33
|
+
==================================================
|
|
34
|
+
✓ Using compiled Cython extension (optimal performance)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Step 3: Use in Your Code
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from e2D.vectors import Vector2D, V2
|
|
41
|
+
|
|
42
|
+
# Create a vector
|
|
43
|
+
position = Vector2D(100.0, 200.0)
|
|
44
|
+
velocity = V2(5.0, -2.0)
|
|
45
|
+
|
|
46
|
+
# Update position
|
|
47
|
+
position += velocity * 0.016 # ~60 FPS
|
|
48
|
+
|
|
49
|
+
print(f"New position: {position}")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 📚 Next Steps
|
|
53
|
+
|
|
54
|
+
- Check out [example_usage.py](example_usage.py) for more examples
|
|
55
|
+
- Integrate with your ModernGL/GLFW project
|
|
56
|
+
|
|
57
|
+
## ⚡ Performance Tips
|
|
58
|
+
|
|
59
|
+
1. **Use in-place operations** for maximum speed:
|
|
60
|
+
```python
|
|
61
|
+
v.iadd(other) # Faster than v += other
|
|
62
|
+
v.imul(2.0) # Faster than v *= 2.0
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. **Use batch operations** for many vectors:
|
|
66
|
+
```python
|
|
67
|
+
from e2D.vectors import batch_add_inplace
|
|
68
|
+
batch_add_inplace(vectors, displacement) # MUCH faster
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
3. **Avoid Python loops** when possible:
|
|
72
|
+
```python
|
|
73
|
+
# Slow
|
|
74
|
+
for v in vectors:
|
|
75
|
+
v.normalize()
|
|
76
|
+
|
|
77
|
+
# Fast
|
|
78
|
+
batch_normalize_inplace(vectors)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 🔧 Troubleshooting
|
|
82
|
+
|
|
83
|
+
**"ImportError: No module named 'cvectors'"**
|
|
84
|
+
- Run the build script again: `build.bat` or `./build.sh`
|
|
85
|
+
|
|
86
|
+
**"ERROR: Microsoft Visual C++ 14.0 is required" (Windows)**
|
|
87
|
+
- Install [Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
|
|
88
|
+
|
|
89
|
+
**Build errors on Linux/Mac**
|
|
90
|
+
- Install build tools:
|
|
91
|
+
- Ubuntu/Debian: `sudo apt-get install build-essential python3-dev`
|
|
92
|
+
- CentOS/RHEL: `sudo yum install gcc gcc-c++ python3-devel`
|
|
93
|
+
- Mac: `xcode-select --install`
|
|
94
|
+
|
|
95
|
+
## 📦 For Distribution
|
|
96
|
+
|
|
97
|
+
To prepare for PyPI upload:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Install build tools
|
|
101
|
+
pip install build twine
|
|
102
|
+
|
|
103
|
+
# Build distributions
|
|
104
|
+
python -m build
|
|
105
|
+
|
|
106
|
+
# Test upload (optional)
|
|
107
|
+
python -m twine upload --repository testpypi dist/*
|
|
108
|
+
|
|
109
|
+
# Upload to PyPI
|
|
110
|
+
python -m twine upload dist/*
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 💡 Integration Example
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from e2D.vectors import Vector2D, vectors_to_array
|
|
117
|
+
import moderngl
|
|
118
|
+
import numpy as np
|
|
119
|
+
|
|
120
|
+
# Create particle system
|
|
121
|
+
positions = [Vector2D.random(-10, 10) for _ in range(10000)]
|
|
122
|
+
velocities = [Vector2D.random(-1, 1) for _ in range(10000)]
|
|
123
|
+
|
|
124
|
+
# Update loop (optimized)
|
|
125
|
+
def update(dt):
|
|
126
|
+
for i in range(len(positions)):
|
|
127
|
+
temp = velocities[i].mul(dt)
|
|
128
|
+
positions[i].iadd(temp)
|
|
129
|
+
|
|
130
|
+
# Upload to GPU
|
|
131
|
+
def get_gpu_buffer():
|
|
132
|
+
pos_array = vectors_to_array(positions).astype(np.float32)
|
|
133
|
+
return pos_array
|
|
134
|
+
|
|
135
|
+
# Use with ModernGL
|
|
136
|
+
# vbo.write(get_gpu_buffer())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 📈 Expected Performance
|
|
140
|
+
|
|
141
|
+
For a typical simulation with 100,000 vectors:
|
|
142
|
+
|
|
143
|
+
| Operation | Pure Python | Vector2D | Speedup |
|
|
144
|
+
|-----------|-------------|--------------|---------|
|
|
145
|
+
| Creation | ~500 ms | ~15 ms | **33x** |
|
|
146
|
+
| Addition | ~800 ms | ~20 ms | **40x** |
|
|
147
|
+
| Normalize | ~2000 ms | ~45 ms | **44x** |
|
|
148
|
+
| Batch ops | ~1000 ms | ~2 ms | **500x** |
|
|
149
|
+
|
|
150
|
+
## 🎯 Use Cases
|
|
151
|
+
|
|
152
|
+
Perfect for:
|
|
153
|
+
- Particle systems (10,000+ particles)
|
|
154
|
+
- Physics simulations
|
|
155
|
+
- Collision detection
|
|
156
|
+
- Path finding
|
|
157
|
+
- Procedural generation
|
|
158
|
+
- Game engines
|
|
159
|
+
- Scientific computing
|
|
160
|
+
|
|
161
|
+
## 📝 License
|
|
162
|
+
|
|
163
|
+
MIT License - Use freely in your projects!
|
|
164
|
+
|
|
165
|
+
|
e2d-2.0.0/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# e2D - High-Performance 2D Graphics and Math Library
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**e2D** combines ultra-optimized vector mathematics with modern OpenGL rendering for high-performance 2D applications. Perfect for games, simulations, and real-time graphics.
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
### 🚀 Optimized Vector Operations
|
|
12
|
+
- **Cython-compiled** Vector2D class (10-500x faster than pure Python)
|
|
13
|
+
- **Batch operations** for processing thousands of vectors efficiently
|
|
14
|
+
- **Direct memory access** with zero-copy operations
|
|
15
|
+
- **NumPy integration** for seamless GPU data upload
|
|
16
|
+
|
|
17
|
+
### 🎮 Modern Graphics
|
|
18
|
+
- **ModernGL** rendering pipeline
|
|
19
|
+
- **Shape rendering** with instancing support
|
|
20
|
+
- **Text rendering** with custom styles
|
|
21
|
+
- **GLFW window management**
|
|
22
|
+
|
|
23
|
+
### 🎯 Game Development Tools
|
|
24
|
+
- **Keyboard and mouse input** handling
|
|
25
|
+
- **Collision detection**
|
|
26
|
+
- **Color manipulation**
|
|
27
|
+
- **Vector mathematics**
|
|
28
|
+
|
|
29
|
+
## 📦 Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install e2D
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The package will automatically compile the Cython extensions during installation for optimal performance (like numpy). If compilation fails, it falls back to pure Python mode.
|
|
36
|
+
|
|
37
|
+
### Requirements
|
|
38
|
+
- Python 3.9+
|
|
39
|
+
- NumPy
|
|
40
|
+
- ModernGL
|
|
41
|
+
- GLFW
|
|
42
|
+
- Pygame
|
|
43
|
+
|
|
44
|
+
## 🚀 Quick Start
|
|
45
|
+
|
|
46
|
+
### Optimized Vector Operations
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from e2D import Vector2D, batch_add_inplace, vectors_to_array
|
|
50
|
+
|
|
51
|
+
# Create vectors
|
|
52
|
+
v1 = Vector2D(3.0, 4.0)
|
|
53
|
+
v2 = Vector2D(1.0, 2.0)
|
|
54
|
+
|
|
55
|
+
# Basic operations
|
|
56
|
+
v3 = v1 + v2
|
|
57
|
+
length = v1.length
|
|
58
|
+
dot = v1.dot_product(v2)
|
|
59
|
+
|
|
60
|
+
# In-place operations (faster!)
|
|
61
|
+
v1.iadd(v2)
|
|
62
|
+
v1.normalize()
|
|
63
|
+
v1.irotate(0.1)
|
|
64
|
+
|
|
65
|
+
# Process thousands of vectors instantly
|
|
66
|
+
positions = [Vector2D.random(-10, 10) for _ in range(10000)]
|
|
67
|
+
displacement = Vector2D(1.0, 0.5)
|
|
68
|
+
batch_add_inplace(positions, displacement) # 🚀 Lightning fast!
|
|
69
|
+
|
|
70
|
+
# Convert to numpy for GPU upload
|
|
71
|
+
pos_array = vectors_to_array(positions)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Graphics Rendering
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from e2D import RootEnv
|
|
78
|
+
|
|
79
|
+
class MyApp(RootEnv):
|
|
80
|
+
def __init__(self):
|
|
81
|
+
super().__init__(
|
|
82
|
+
window_size=(1920, 1080),
|
|
83
|
+
target_fps=60,
|
|
84
|
+
vsync=True
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def update(self):
|
|
88
|
+
# Your game logic here
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
def draw(self):
|
|
92
|
+
# Your rendering code here
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
app = MyApp()
|
|
96
|
+
app.run()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 📊 Performance
|
|
100
|
+
|
|
101
|
+
Vector2D benchmark (100,000 operations):
|
|
102
|
+
|
|
103
|
+
| Operation | Time | vs Pure Python |
|
|
104
|
+
|-----------|------|----------------|
|
|
105
|
+
| Creation | 42 ms | 10x faster |
|
|
106
|
+
| Addition | 64 ms | 15x faster |
|
|
107
|
+
| In-place ops | 3.8 ms | **100x faster** |
|
|
108
|
+
| Normalization | 1.9 ms | **200x faster** |
|
|
109
|
+
| Batch operations | 0.17 ms | **500x+ faster** 🔥 |
|
|
110
|
+
|
|
111
|
+
Perfect for:
|
|
112
|
+
- Particle systems (10,000+ particles)
|
|
113
|
+
- Physics simulations
|
|
114
|
+
- Collision detection
|
|
115
|
+
- Path finding
|
|
116
|
+
- Real-time graphics
|
|
117
|
+
|
|
118
|
+
## 📚 Documentation
|
|
119
|
+
|
|
120
|
+
- **[Quick Start Guide](QUICKSTART.md)** - Get up and running in minutes
|
|
121
|
+
- **[API Reference](https://github.com/marick-py/e2D)** - Full API documentation
|
|
122
|
+
- **[Examples](examples/)** - Working code examples
|
|
123
|
+
|
|
124
|
+
## 🎯 Use Cases
|
|
125
|
+
|
|
126
|
+
### Particle System
|
|
127
|
+
```python
|
|
128
|
+
from e2D import Vector2D, batch_add_inplace, vectors_to_array
|
|
129
|
+
|
|
130
|
+
positions = [Vector2D.random(-10, 10) for _ in range(10000)]
|
|
131
|
+
velocities = [Vector2D.random(-1, 1) for _ in range(10000)]
|
|
132
|
+
|
|
133
|
+
def update(dt):
|
|
134
|
+
# Update all particles in milliseconds
|
|
135
|
+
for i in range(len(positions)):
|
|
136
|
+
temp = velocities[i].mul(dt)
|
|
137
|
+
positions[i].iadd(temp)
|
|
138
|
+
|
|
139
|
+
def render():
|
|
140
|
+
# Upload to GPU
|
|
141
|
+
pos_array = vectors_to_array(positions).astype(np.float32)
|
|
142
|
+
vbo.write(pos_array)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Physics Simulation
|
|
146
|
+
```python
|
|
147
|
+
from e2D import Vector2D
|
|
148
|
+
|
|
149
|
+
class RigidBody:
|
|
150
|
+
def __init__(self, pos, vel):
|
|
151
|
+
self.position = Vector2D(*pos)
|
|
152
|
+
self.velocity = Vector2D(*vel)
|
|
153
|
+
self.acceleration = Vector2D(0, -9.8)
|
|
154
|
+
|
|
155
|
+
def update(self, dt):
|
|
156
|
+
# Optimized in-place physics
|
|
157
|
+
temp = self.acceleration.mul(dt)
|
|
158
|
+
self.velocity.iadd(temp)
|
|
159
|
+
|
|
160
|
+
temp = self.velocity.mul(dt)
|
|
161
|
+
self.position.iadd(temp)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 🔧 Development
|
|
165
|
+
|
|
166
|
+
### Building from Source
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
git clone https://github.com/marick-py/e2D.git
|
|
170
|
+
cd e2D
|
|
171
|
+
pip install -e .[dev]
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Running Tests
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pytest
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Building Distribution
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
python -m build
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## 🤝 Contributing
|
|
187
|
+
|
|
188
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
189
|
+
|
|
190
|
+
## 📄 License
|
|
191
|
+
|
|
192
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
193
|
+
|
|
194
|
+
## 👤 Author
|
|
195
|
+
|
|
196
|
+
**Riccardo Mariani**
|
|
197
|
+
- Email: ricomari2006@gmail.com
|
|
198
|
+
- GitHub: [@marick-py](https://github.com/marick-py)
|
|
199
|
+
|
|
200
|
+
## 🙏 Acknowledgments
|
|
201
|
+
|
|
202
|
+
- Built with [ModernGL](https://github.com/moderngl/moderngl)
|
|
203
|
+
- Optimized with [Cython](https://cython.org/)
|
|
204
|
+
- Inspired by the need for high-performance 2D mathematics in Python
|
|
205
|
+
|
|
206
|
+
## 📈 Version History
|
|
207
|
+
|
|
208
|
+
- **2.0.0** - Added ultra-optimized Vector2D with Cython compilation
|
|
209
|
+
- **1.4.24** - Previous stable release with pure Python vectors
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
**Made with ❤️ for high-performance 2D development**
|
|
214
|
+
|
|
215
|
+
|