Skip to content

An updated implementation of pygame 2d vector class

Notifications You must be signed in to change notification settings

twh2898/vector-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vectory-py

An updated implementation of https://www.pygame.org/wiki/2DVectorClass

Updates

  • Updated to python 3
  • Renamed Vec2d to Vec2
  • Added a Vec3
  • Updated constructor to take Vec2, list and a single value
  • Added as_vec2 and as_vec3 helper functions
  • Added vec2_like and vec3_like types

Usage

Vec2 and Vec3

v2 = Vec2(num)
v2 = Vec2(x, y)
v2 = Vec2([x, y])
v2 = Vec2(Vec2(0))

v3 = Vec3(num)
v3 = Vec3(x, y, z)
v3 = Vec3([x, y, z])
v3 = Vec3(Vec3(0))

as_vec2 and as_vec3

def as_vec2(obj):
    if isinstance(obj, Vec2):
        return obj
    else:
        return Vec2(obj)

def as_vec3(obj):
    if isinstance(obj, Vec3):
        return obj
    else:
        return Vec3(obj)

vec2_like and vec3_like

from typing import NewType, Tuple, Union

vec2_like = NewType('vec2_like', Union[Vec2, Tuple[float, float]])
vec3_like = NewType('vec3_like', Union[Vec3, Tuple[float, float, float]])

About

An updated implementation of pygame 2d vector class

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages