Note: This is a work in progress. Only a portion of the ray tracer is currently implemented.
This repository is a Python implementation of the ray tracer found in The Ray Tracer Challenge: A Test-Driven Guide to Your First 3D Renderer by Jamis Buck.
This code is effectively a port of that found in bmitc/the-ray-tracer-challenge-fsharp, but the port was not dogmatic in carrying over the F# style. In other words, it has been attempted to be as idiomatic to Python as possible, given my personal up to date knowledge of Python. The style will certainly be adjusted as I move more towards a Pythonic implementation and continue to evolve the codebase by finishing the ray tracer implementation and performing refactors. Updating my knowledge of the latest and greatest in Python 3.12, which is the latest Python version just released, and the ecosystem was a primary impetus for this project (I even discovered an issue with Mypy for Python 3.12), so there is a lot of incentive in evolving this code rather than maintaining its status as a port of the F# code. The port is only to kickstart the initial implementation, and even then, the word port is used loosely here.
One might notice some similarity, perhaps unexpected if one is unfamiliar with F#, between the F# and Python code. One of the main differences is due to the fact that F# is statically typed but has type inference, which means type annotations are not required except for clarity and certain situations. Python is dynamically typed, which necessitates the heavy use of type hints, as found in this project. Thus, Mypy was utilized to do as much static type checking as possible. This project utilizes Poetry to organize the project and has incorporated Mypy, Pylint, and Black to enforce types, style, and formatting. All of the tests found in the book, since the book is effectively a test-driven design book, are implemented via unittest
. Pytest may be investigated in the future.
To run the script and see the image, run:
poetry run projectile
This project is configured as a Poetry project. All dependencies are listed in pyproject.toml
. The following assumes python
is Python 3, so you can replace python
with python3
if your system needs that disambiguation.
python -m pip install --user pipx
python -m pipx ensurepath
pipx install poetry
poetry install
This installs all needed dependencies.
All of the following commands should be run at the repository's root. And all of these checks are currently run in a GitHub Action to verify that the code maintains full compliance with the checks.
poetry run python -m unittest discover tests
Mypy is configured in pyproject.toml
to run in strict mode.
poetry run mypy ray_tracer_challenge
Black is configured in pyproject.toml
.
poetry run black .
Pylint is configured in .pylintrc
.
poetry run pylint ray_tracer_challenge