Skip to main content

Data structures for spatial queries.

Project description

locus

Github Actions Documentation Codecov License PyPI

In what follows python is an alias for python3.10 or pypy3.10 or any later version (python3.11, pypy3.11 and so on).

Installation

Prerequisites

Install the latest pip & setuptools packages versions

python -m pip install --upgrade pip setuptools

User

Download and install the latest stable version from PyPI repository

python -m pip install --upgrade locus

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/locus.git
cd locus

Install

python -m pip install -e '.'

Usage

>>> import math
>>> from fractions import Fraction
>>> from ground.context import Context
>>> context = Context(coordinate_factory=Fraction, sqrt=math.sqrt)
>>> Box, Point, Segment = (
...     context.box_cls,
...     context.point_cls,
...     context.segment_cls
... )
>>> from locus import kd
>>> points = list(map(Point, range(-10, 11), range(0, 20)))
>>> kd_tree = kd.Tree(points, context=context)
>>> kd_tree.nearest_index(Point(0, 0)) == 5
True
>>> kd_tree.nearest_point(Point(0, 0)) == Point(-5, 5)
True
>>> kd_tree.n_nearest_indices(2, Point(0, 0)) == [6, 5]
True
>>> kd_tree.n_nearest_points(2, Point(0, 0)) == [Point(-4, 6), Point(-5, 5)]
True
>>> kd_tree.find_box_indices(Box(-1, 1, 0, 10)) == [9, 10]
True
>>> kd_tree.find_box_points(Box(-1, 1, 0, 10)) == [Point(-1, 9), Point(0, 10)]
True
>>> from locus import r
>>> boxes = list(
...     map(Box, range(-10, 11), range(0, 20), range(-20, 0), range(-10, 11))
... )
>>> r_tree = r.Tree(boxes, context=context)
>>> r_tree.nearest_index(Point(0, 0)) == 10
True
>>> r_tree.nearest_box(Point(0, 0)) == Box(0, 10, -10, 0)
True
>>> r_tree.n_nearest_indices(2, Point(0, 0)) == [10, 11]
True
>>> r_tree.n_nearest_boxes(2, Point(0, 0)) == [
...     Box(0, 10, -10, 0), Box(1, 11, -9, 1)
... ]
True
>>> r_tree.find_subsets_indices(Box(0, 10, -10, 10)) == [10]
True
>>> r_tree.find_subsets(Box(0, 10, -10, 10)) == [Box(0, 10, -10, 0)]
True
>>> r_tree.find_supersets_indices(Box(0, 10, -10, 0)) == [10]
True
>>> r_tree.find_supersets(Box(0, 10, -10, 0)) == [Box(0, 10, -10, 0)]
True

Development

Bumping version

Prerequisites

Install bump-my-version.

Release

Choose which version number category to bump following semver specification.

Test bumping version

bump-my-version bump --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump-my-version bump --verbose $CATEGORY

This will set version to major.minor.patch.

Running tests

Plain

Install with dependencies

python -m pip install -e '.[tests]'

Run

pytest

Docker container

Run

  • with CPython

    docker-compose --file docker-compose.cpython.yml up
    
  • with PyPy

    docker-compose --file docker-compose.pypy.yml up
    

Bash script

Run

  • with CPython

    ./run-tests.sh
    

    or

    ./run-tests.sh cpython
    
  • with PyPy

    ./run-tests.sh pypy
    

PowerShell script

Run

  • with CPython

    .\run-tests.ps1
    

    or

    .\run-tests.ps1 cpython
    
  • with PyPy

    .\run-tests.ps1 pypy
    

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

locus-11.0.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

locus-11.0.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file locus-11.0.0.tar.gz.

File metadata

  • Download URL: locus-11.0.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for locus-11.0.0.tar.gz
Algorithm Hash digest
SHA256 18c5ddead08b6576abeeb1eba49111cfdfcf2f9c84f056c7c3dab657334266ca
MD5 a89ef1630eed384fb86b38e2dc65838e
BLAKE2b-256 27bb2ff19d2365bd7efa4b882e9686dd0f4ef6ad663af32446a2b545bb29928c

See more details on using hashes here.

File details

Details for the file locus-11.0.0-py3-none-any.whl.

File metadata

  • Download URL: locus-11.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for locus-11.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7108293bdc633cd07b038b717966eb074c14fc69d7bc9b96e8ceab59b67d7fcb
MD5 c9b1e5b3670b6542f21af35e6b889d00
BLAKE2b-256 727381eb4bdce630dbaff892c5e4f74290a87e1f553f612150902a679bc57e91

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