Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ezvectors-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ezvectors-0.1.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file ezvectors-0.1.1.tar.gz.

File metadata

  • Download URL: ezvectors-0.1.1.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

Hashes for ezvectors-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5a184cf270db28752aebdef234c465860490e427e42562ef56b1edc6aa229155
MD5 e48ca58cb94d1827432a923efa2b90e7
BLAKE2b-256 3bf15e91eee1fd50eced7d502cbd6236bd50fb8d3b2b277b199bae6ac01ebbfe

See more details on using hashes here.

File details

Details for the file ezvectors-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ezvectors-0.1.1-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

Hashes for ezvectors-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec1cc1b3395cd6d366a6d29e014b673668c27fb60c4b0c6643612934313df9a5
MD5 6388a0c384b575c47ca000742b8423cc
BLAKE2b-256 a4895864c9e2a2af87b4c00799563e9fd79bf17ccc00ca4849537f518f39bf8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page