Skip to main content

This package provides foundational data structures for representing and manipulating tile maps in 2D and 3D environments. Its primary purpose is to enable efficient spatial organization and management of map data for games, simulations, and applications that require robust handling of coordinates, regions, and chunked regions. By offering specialized classes for coordinates, regions, and chunked regions, the package simplifies the development of systems that need precise and scalable map logic.

Project description

tstructs

Tile map data structures for 2D and 3D worlds.

License: GPL v3 Version 1.1

Table of Contents

Overview

tstructs is a Python package providing foundational data structures for representing and manipulating tile maps in both 2D and 3D environments. It is designed for use in games, simulations, and applications that require efficient spatial organization of map data.

Features

  • Coordinate: Immutable tuple subclass for 2D/3D coordinates with convenient accessors.
  • Region: Represents a square 3D region in a tile map, with properties for area, volume, and bounds checking.
  • ChunkedRegion: Extends Region to support chunking, allowing subdivision of regions into smaller, manageable chunks.

Module Information

  • Name: tstructs
  • Version: 1.1
  • Description: Tile map data structures for 2D and 3D worlds.

Installation

This package is intended for use as part of a larger project. To use it directly or install it as a package.

# Example pip install
pip install tstructs
# Example: Add to PYTHONPATH
export PYTHONPATH="$PYTHONPATH:/path/to/install/tstructs"

Usage

Import the classes you need:

from tstructs import Coordinate, Region, ChunkedRegion, Cell, Group, Properties

# 2D coordinate
c2 = Coordinate(1, 2)

# 3D coordinate
c3 = Coordinate(1, 2, 3)

# Create a region
region = Region(region_x=0, region_y=0, region_size=16, region_location=Coordinate(0, 0))

# Create a chunked region
chunked = ChunkedRegion(region_x=0, region_y=0, region_size=16, chunk_size=4, region_location=Coordinate(0, 0))

# Create a cell
cell = Cell(coord=Coordinate(1, 2), value=5)

# Create a group of cells
group = Group([cell])

# Create and use properties
props = Properties({'walkable': True, 'cost': 1})
is_walkable = props['walkable']

API Reference

Coordinate

  • 2D or 3D immutable coordinate: Coordinate(x, y) or Coordinate(x, y, z)
  • Properties: .x, .y, .z (z only for 3D)

Region

  • Region(region_x, region_y, region_size, region_location=Coordinate(0,0))
  • Properties: .name, .n (size), .area, .volume, .centre
  • Methods: .clamp_coordinates(start_x, start_y, end_x, end_y), .is_edge(x, y)

ChunkedRegion

  • ChunkedRegion(region_x, region_y, region_size, chunk_size, region_location=Coordinate(0,0))
  • Properties: .chunks_per_side, .total_chunks
  • Methods: .get_chunk_coordinates(loc), .get_chunks_in_area(start, end)

Cell

  • Cell(coord, value=None, **attributes)
  • Represents a single tile or cell in a map, with a coordinate and optional value/attributes.
  • Properties: .coord, .value, .attributes (dict of extra attributes)
  • Example: Cell(Coordinate(1,2), value=5, terrain='grass')

Group

  • Group(cells=None)
  • Represents a collection of Cell objects.
  • Methods:
    • .add(cell): Add a cell to the group
    • .remove(cell): Remove a cell from the group
    • .find_by_coord(coord): Find a cell by its coordinate
  • Iterable: Can be iterated over like a list of cells

Properties

  • Properties(data=None)
  • Dictionary-like class for storing arbitrary properties for tiles, cells, or regions.
  • Behaves like a dict: supports item access, update, iteration, etc.
  • Example: Properties({'walkable': True, 'cost': 1})

Testing

See docs/testing.md for information on testing and usage examples.

License

This package is licensed under the GNU General Public License v3.0 (GPLv3). See the LICENSE file for details.

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

tstructs-1.1.1.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

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

tstructs-1.1.1-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file tstructs-1.1.1.tar.gz.

File metadata

  • Download URL: tstructs-1.1.1.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.8

File hashes

Hashes for tstructs-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ade68c5b0d2ce3b156254bb044c32d3fd6fbd727c10d3db8c74d72b3a585de2a
MD5 5e56f5dbd15449eed20bb665f145671d
BLAKE2b-256 f8d6a98cd936d5b98bbc53cb52efa79d88b2b636517e92e29d6dc5b165c58dae

See more details on using hashes here.

File details

Details for the file tstructs-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: tstructs-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.8

File hashes

Hashes for tstructs-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7784d5d11885159f37aea009e773a6d85b8b9c4bf1ac48738c84102e5b2a8e14
MD5 41fcec1a0dbd44cba21e1917cb0c03eb
BLAKE2b-256 84dd2dfb6ad9d7a57073a801cd1752524209203777f0f091b7c5cd9ddb072c84

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