Metadata-Version: 2.4
Name: spatial-reasoner
Version: 0.1.0
Summary: A flexible 3D spatial reasoning library for Python
Author: Steven Häsler, Philipp Ackermann
License-Expression: CC0-1.0
Project-URL: Documentation, https://github.com/metason/SpatialReasoner
Project-URL: Issues, https://github.com/metason/SRpy/issues
Project-URL: Paper, https://doi.org/10.1109/ICVARS66454.2025.11198690
Project-URL: Repository, https://github.com/metason/SRpy
Keywords: 3d,inference,reasoning,spatial,xr
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26
Provides-Extra: export
Requires-Dist: usd-core>=25.2; extra == "export"
Provides-Extra: test
Requires-Dist: coverage[toml]<8,>=7; extra == "test"
Requires-Dist: pytest<9,>=8; extra == "test"
Provides-Extra: dev
Requires-Dist: build<2,>=1.3; extra == "dev"
Requires-Dist: ruff<0.17,>=0.16; extra == "dev"
Requires-Dist: twine<7,>=6.2; extra == "dev"
Dynamic: license-file

# Spatial Reasoner for Python

`spatial-reasoner` is a 3D spatial-reasoning library derived from the CC0
[SRSwift reference implementation](https://github.com/metason/SpatialReasoner). It models
oriented spatial objects and evaluates explicit pipelines for topology, directionality,
visibility, connectivity, comparison, and similarity predicates.

This is an alpha release. Version 0.1.x preserves the SRSwift-facing camelCase API and
reasoning behavior, but the Python package API may still evolve before 1.0.

## Installation

Spatial Reasoner supports Python 3.11 through 3.14.

```bash
python -m pip install spatial-reasoner
```

OpenUSD scene export is optional:

```bash
python -m pip install "spatial-reasoner[export]"
```

## Quick start

The principal classes are available directly from `spatial_reasoner`:

```python
from spatial_reasoner import SpatialObject, SpatialReasoner, Vector3

crate = SpatialObject(
    "crate",
    position=Vector3(0.0, 0.0, 0.0),
    width=2.0,
    height=2.0,
    depth=2.0,
)
marker = SpatialObject(
    "marker",
    position=Vector3(3.0, 0.0, 0.0),
    width=0.1,
    height=0.1,
    depth=0.1,
)

reasoner = SpatialReasoner()
reasoner.load([crate, marker])
assert reasoner.run("filter(volume > 0.5)")
assert [obj.id for obj in reasoner.result()] == ["crate"]
```

Pipeline predicates may be addressed by their SRSwift-compatible enum names. For example,
`seenleft` selects the predicate whose readable value is `"seen left"`.

> [!WARNING]
> Pipeline filter, select, map, calculate, and produce expressions use dynamic evaluation.
> Never accept pipeline text or expression fragments from an untrusted source without an
> external validator and a strict allowlist.

## OpenUSD export

Import the exporter from its optional module so normal package imports never require OpenUSD:

```python
from spatial_reasoner import SpatialObject
from spatial_reasoner.exporter import SceneExporter

objects = [SpatialObject("box")]
SceneExporter("exports").exportUSDZ(objects, "scene.usdz")
```

The exporter uses OpenUSD's packaging API and does not require an external `usdzip` executable.

## Status and parity

- The reasoning classes, method names, predicates, formulas, and pipeline behavior track SRSwift.
- CamelCase methods are retained deliberately for cross-language parity.
- The experimental font-based 3D utility is not distributed.
- Type annotations are incomplete; this distribution does not claim PEP 561 typed-package status.

Full conceptual documentation lives in the
[SpatialReasoner repository](https://github.com/metason/SpatialReasoner).

## Development

```bash
python -m pip install -e ".[test,dev]"
ruff check src tests
ruff format --check src tests
coverage run -m pytest -m "not export and not distribution"
coverage report
```

To run the optional exporter test, install `.[export,test]` and run
`pytest -m export`. Function-length and complexity checks are intentionally not part of the
style policy because the reasoning implementation follows its reference implementation.

## Citation

If this software supports your research, cite Häsler and Ackermann, “Spatial Reasoner: A 3D
Inference Pipeline for XR Applications” (2025),
[doi:10.1109/ICVARS66454.2025.11198690](https://doi.org/10.1109/ICVARS66454.2025.11198690).

## License

Spatial Reasoner for Python is released under [CC0-1.0](LICENSE).
