Skip to content

jloveric/shapely-mojo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shapely-mojo

Mojo-native, minimal Shapely-like geometry library and algorithms.

Requirements

  • Mojo toolchain available on your PATH (mojo)
  • Python 3.13+
  • uv

Setup

Create / sync the virtualenv with dependencies:

uv sync

Run the Mojo tests

uv run mojo run -I . tests/run_tests.mojo

Run + compare benchmarks

Run both the Mojo and Python benchmarks, write the results to JSON, and print a per-benchmark speedup table:

uv run python bench/compare_benchmarks.py

This writes:

  • bench/results/mojo_results.json
  • bench/results/python_results.json

The printed speedup(py/mojo) value is python_seconds / mojo_seconds:

  • values > 1.0 mean Mojo is faster
  • values < 1.0 mean Python Shapely is faster

Run the buffering + matplotlib example

This example:

  • creates a couple of LineStrings
  • buffers them using Mojo Shapely (shapely.constructive.buffer)
  • plots the input lines + buffer result using matplotlib via Mojo Python-interop
  • writes the image to outputs/line_buffer.png
uv run mojo run -I . examples/plot_line_buffer.mojo

The output directory is created automatically.

Images

Line buffer cap/join style comparison (generated by examples/plot_line_buffer.mojo):

Line buffer styles

Polygon buffering with holes (shows buffer for join_style = round/bevel/mitre at distances d=0.6 and d=0.9, including how interior holes shrink/round under each join style):

Polygon buffer with holes

Regenerate:

uv run mojo run -I . examples/plot_polygon_buffer_with_holes.mojo

Tic-tac-toe board linework buffered + unioned into a single footprint (prints area() and length() and saves a plot):

Tic-tac-toe buffer

Regenerate:

uv run mojo run -I . examples/plot_tictactoe_buffer_metrics.mojo

Boolean operations (intersection / union / difference / symmetric difference) between two polygons:

Boolean operations

Regenerate:

uv run mojo run -I . examples/plot_boolean_operations.mojo

STRtree spatial index example (predicate query + nearest / kNN):

STRtree queries

Regenerate:

uv run mojo run -I . examples/plot_strtree_queries.mojo

Project layout

  • shapely/
    • Mojo implementation of geometry types and operations
  • tests/run_tests.mojo
    • Small Mojo test runner
  • examples/
    • Runnable examples (Mojo)
  • outputs/
    • Generated images/artifacts (not tracked)

About

Mojo implementation of shapely

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors