pyxora.wrapper.functions
1from typing import Tuple 2import pygame 3 4__all__ = ["vector","rect"] 5 6def vector(x: int | float, y: int | float, z: int | float | None = None) -> pygame.math.Vector2 | pygame.math.Vector3: 7 """ 8 Creates a 2D or 3D pygame vector based on the input arguments. 9 10 Args: 11 x (int | float): X value of the vector. 12 y (int | float): Y value of the vector. 13 z (int | float | None): Optional Z value; if provided, returns a 3D vector. 14 15 Returns: 16 pygame.math.Vector2 or pygame.math.Vector3: A 2D or 3D vector. 17 18 Examples: 19 vector(1, 2) -> pygame.math.Vector2(1, 2)\n 20 vector(1, 2, 3) -> pygame.math.Vector3(1, 2, 3) 21 """ 22 if z is not None: 23 return pygame.math.Vector3(x, y, z) 24 return pygame.math.Vector2(x, y) 25 26def rect( 27 pos: Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3, 28 size: Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3 29) -> pygame.Rect | pygame.FRect: 30 """ 31 Returns the bounding rectangle (pygame.Rect or pygame.FRect) based on coordinate types. 32 33 Args: 34 pos (Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3): Position of the rectangle. 35 size (Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3): Size of the rectangle. 36 37 Returns: 38 pygame.Rect | pygame.FRect: The bounding rectangle of the shape. 39 """ 40 if all(isinstance(i, int) for i in (pos[0], pos[1], size[0], size[1])): 41 return pygame.Rect(pos, size) # Use pygame.Rect if all values are integers 42 return pygame.FRect(pos,size) # Use pygame.FRect otherwise
def
vector( x: int | float, y: int | float, z: int | float | None = None) -> pygame.math.Vector2 | pygame.math.Vector3:
7def vector(x: int | float, y: int | float, z: int | float | None = None) -> pygame.math.Vector2 | pygame.math.Vector3: 8 """ 9 Creates a 2D or 3D pygame vector based on the input arguments. 10 11 Args: 12 x (int | float): X value of the vector. 13 y (int | float): Y value of the vector. 14 z (int | float | None): Optional Z value; if provided, returns a 3D vector. 15 16 Returns: 17 pygame.math.Vector2 or pygame.math.Vector3: A 2D or 3D vector. 18 19 Examples: 20 vector(1, 2) -> pygame.math.Vector2(1, 2)\n 21 vector(1, 2, 3) -> pygame.math.Vector3(1, 2, 3) 22 """ 23 if z is not None: 24 return pygame.math.Vector3(x, y, z) 25 return pygame.math.Vector2(x, y)
Creates a 2D or 3D pygame vector based on the input arguments.
Arguments:
- x (int | float): X value of the vector.
- y (int | float): Y value of the vector.
- z (int | float | None): Optional Z value; if provided, returns a 3D vector.
Returns:
pygame.math.Vector2 or pygame.math.Vector3: A 2D or 3D vector.
Examples:
vector(1, 2) -> pygame.math.Vector2(1, 2)
vector(1, 2, 3) -> pygame.math.Vector3(1, 2, 3)
def
rect( pos: Union[Tuple[int | float, int | float], pygame.math.Vector2, pygame.math.Vector3], size: Union[Tuple[int | float, int | float], pygame.math.Vector2, pygame.math.Vector3]) -> pygame.rect.Rect | pygame.rect.FRect:
27def rect( 28 pos: Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3, 29 size: Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3 30) -> pygame.Rect | pygame.FRect: 31 """ 32 Returns the bounding rectangle (pygame.Rect or pygame.FRect) based on coordinate types. 33 34 Args: 35 pos (Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3): Position of the rectangle. 36 size (Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3): Size of the rectangle. 37 38 Returns: 39 pygame.Rect | pygame.FRect: The bounding rectangle of the shape. 40 """ 41 if all(isinstance(i, int) for i in (pos[0], pos[1], size[0], size[1])): 42 return pygame.Rect(pos, size) # Use pygame.Rect if all values are integers 43 return pygame.FRect(pos,size) # Use pygame.FRect otherwise
Returns the bounding rectangle (pygame.Rect or pygame.FRect) based on coordinate types.
Arguments:
- pos (Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3): Position of the rectangle.
- size (Tuple[int | float, int | float] | pygame.math.Vector2 | pygame.math.Vector3): Size of the rectangle.
Returns:
pygame.Rect | pygame.FRect: The bounding rectangle of the shape.