A lightweight, zero-dependency 2D vector library for Python.
Project description
ezvectors
A fast and lightweight 2D vector class for Python. No dependencies required.
I built this because I needed vectors for my initial prototype of a 2D physics engine and using NumPy for some really simple vector math is genuinely slower than pure Python. The overhead of calling into compiled C code through Python's FFI for something as small as adding two floats together completely negates any performance benefit. So I wrote my own vector library!
ezvectors gives you a Vector2 class that uses __slots__ for a small memory footprint, avoids unnecessary object allocation in arithmetic, and works seamlessly with plain tuples.
You can install ezvectors via pip:
pip install ezvectors
Usage
from ezvectors import Vector2
a = Vector2(3, 4)
b = Vector2(1, 2)
a + b # Vector2(4, 6)
a - (1, 1) # Vector2(2, 3) — tuples work everywhere
a * 2 # Vector2(6, 8)
a.magnitude() # 5.0
a.normalize() # Vector2(0.6, 0.8)
a.dot(b) # 11
a.distance_to(b) # 2.8284...
a.rotate_deg(90) # Vector2(-4, 3)
Full API reference and examples in documentation.md.
Tests
pip install pytest
pytest tests/
License
MIT — see LICENSE.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ezvectors-0.1.2.tar.gz.
File metadata
- Download URL: ezvectors-0.1.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38f0705ac4f6a4057d564d0ac91ec9413ad907751eaffe3c5914cdbd5d342963
|
|
| MD5 |
ea1b25447ce1cd815860d5f2bf007652
|
|
| BLAKE2b-256 |
01a150328e96a102109f82d190005f52320e03d4692b64d9d47b3bc8274244ee
|
File details
Details for the file ezvectors-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ezvectors-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55dfbe0970b2a51b9db4e98e81fafcebfb41da5817351a58308ac3a3831e0a2b
|
|
| MD5 |
f2b579b56193a752def19411a28b85c1
|
|
| BLAKE2b-256 |
09dc73ab5338604fdd78b08e8d2fc84c7daf7c79e598d89ae791e9adcfe2905d
|