A 2D/3D geometry library for CAD/CAM applications.
Project description
raygeo
A high-performance 2D/3D geometry library for Python, built in Rust with PyO3.
raygeo provides vector path construction, polygon boolean operations, curve fitting, path transformations, and geometric queries — all backed by a native Rust extension.
Installation
pip install raygeo
Requires Python 3.10+ and a compatible platform (Linux, Windows, macOS Intel, or macOS Apple Silicon). Pre-compiled wheels are available on PyPI.
Quick Start
Building Paths
The Geometry class is the core abstraction. It stores a vector path as a
sequence of move, line, arc, and cubic Bezier commands:
from raygeo import Geometry
# Create a 10x10 square
g = Geometry()
g.move_to(0, 0)
g.line_to(10, 0)
g.line_to(10, 10)
g.line_to(0, 10)
g.close_path()
print(g.area()) # 100.0
print(g.rect()) # (0.0, 0.0, 10.0, 10.0)
print(g.is_closed()) # True
You can also create paths from point lists:
triangle = Geometry.from_points([(0, 0), (10, 0), (5, 8.66)])
Accessing Raw Data
Internally, geometry data is stored as an (N, 8) NumPy float64 array.
Each row represents one command:
import numpy as np
from raygeo import COL_TYPE, COL_X, COL_Y, CMD_TYPE_LINE
data = g.data # numpy array, shape (N, 8)
print(data[:, COL_X]) # all x coordinates
The 8 columns are:
| Column | Index | Description |
|---|---|---|
COL_TYPE |
0 | Command type (move/line/arc/bezier) |
COL_X |
1 | X coordinate |
COL_Y |
2 | Y coordinate |
COL_Z |
3 | Z coordinate |
COL_I / COL_C1X |
4 | Arc center offset X / Bezier control 1 X |
COL_J / COL_C1Y |
5 | Arc center offset Y / Bezier control 1 Y |
COL_CW / COL_C2X |
6 | Arc clockwise flag / Bezier control 2 X |
— / COL_C2Y |
7 | (unused for arcs) / Bezier control 2 Y |
Arcs and Bezier Curves
g = Geometry()
g.move_to(0, 0)
g.arc_to(10, 0, i=5, j=0, clockwise=False) # semicircular arc
g.close_path()
# Bezier curves
g2 = Geometry()
g2.move_to(0, 0)
g2.bezier_to(10, 0, c1x=3, c1y=5, c2x=7, c2y=5)
# Convert arcs to Bezier curves (for non-uniform scaling)
g3 = Geometry()
g3.move_to(0, 0)
g3.arc_to_as_bezier(10, 0, i=5, j=0)
g3.upgrade_to_scalable()
Path Analysis
print(g.distance()) # total path length
print(g.area()) # signed enclosed area
print(g.rect()) # bounding box (x_min, y_min, x_max, y_max)
print(g.is_closed()) # path closure check
print(g.segments()) # split into sub-paths
# Find closest point on path
result = g.find_closest_point(5, 5) # (segment_index, distance, (px, py))
# Point and tangent at parameter t on a segment
pos, tangent = g.get_point_and_tangent_at(segment_index=0, t=0.5)
Transformations
import numpy as np
from raygeo import Geometry
g = Geometry.from_points([(0, 0), (10, 0), (10, 10), (0, 10)])
# Offset (grow/shrink)
grown = g.grow(2.0) # offset outward by 2 units
shrunk = g.grow(-1.0) # offset inward by 1 unit
# Affine transform (4x4 matrix)
matrix = [
[1, 0, 0, 5], # translate x by 5
[0, 1, 0, 3], # translate y by 3
[0, 0, 1, 0],
[0, 0, 0, 1],
]
g.transform(matrix)
# Map geometry into a frame
mapped = g.map_to_frame(
origin=(0, 0),
p_width=(100, 0),
p_height=(0, 100),
)
g.flip_x() # negate all x coordinates
g.flip_y() # negate all y coordinates
Contour Operations
# Split into separate closed contours
contours = g.split_into_contours()
# Split into disconnected components
components = g.split_into_components()
# Separate holes from solids
inner, outer = g.split_inner_and_outer_contours()
# Remove shared edges between sub-paths
outer_only = g.remove_inner_edges()
Polygon Operations
The shape.polygon submodule provides polygon-specific operations powered by Clipper2:
from raygeo import Geometry
from raygeo.shape.polygon import (
get_polygon_area,
get_polygon_bounds,
offset_polygon,
get_polygons_union,
get_polygons_intersection,
get_polygons_difference,
is_point_inside_polygon,
polygons_intersect,
get_polygon_convex_hull,
)
square = [(0, 0), (10, 0), (10, 10), (0, 10)]
circle_approx = [(5 + 5 * math.cos(a), 5 + 5 * math.sin(a))
for a in [i * math.pi / 20 for i in range(40)]]
get_polygon_area(square) # 100.0
get_polygon_bounds(square) # (0.0, 0.0, 10.0, 10.0)
is_point_inside_polygon((5, 5), square) # True
# Boolean operations
union = get_polygons_union([square, circle_approx])
intersection = get_polygons_intersection([square, circle_approx])
difference = get_polygons_difference([square], [circle_approx])
# Offset
inflated = offset_polygon(square, 2.0)
# NumPy variants are also available (suffixed with _numpy)
import numpy as np
sq_np = np.array(square)
get_polygon_area(sq_np) # also works with numpy arrays
Curve Fitting
from raygeo import Geometry
# Simplify a path
g.simplify(tolerance=0.1)
# Convert curves to line segments
g.linearize(tolerance=0.01)
# Fit arcs and beziers to linear data
g.fit_arcs(tolerance=0.5)
g.fit_curves(tolerance=0.5, beziers=True, arcs=True)
# Convert geometry to polygons
polygons = g.to_polygons(tolerance=0.01)
Self-Intersection Detection
g.has_self_intersections() # check for self-intersections
g.intersects_with(other_geometry) # check intersection with another geometry
g.encloses(other_geometry) # check if this fully encloses another
Serialization
# Dump to dict (JSON-safe)
data = g.dump()
# Load from dict
g2 = Geometry.load(data)
# Pickle support (via __reduce_ex__)
import pickle
g3 = pickle.loads(pickle.dumps(g))
Documentation
Full API documentation is available in the docs/ directory:
| Document | Description |
|---|---|
docs/raygeo.md |
Top-level: Geometry, constants, types, utils |
docs/geometry.md |
Geometry class — commands, properties, transforms |
docs/path.md |
Path ops: splitting, contours, winding, fitting |
docs/shape.md |
Shape primitives: arcs, beziers, circles, polygons |
docs/algo.md |
Algorithms: clipping, fitting, Minkowski, smooth |
Development
Prerequisites
pip install maturin pytest
Build and Test
maturin develop
pytest tests/ -v
Running Rust Tests
cargo test
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file raygeo-0.1.2.tar.gz.
File metadata
- Download URL: raygeo-0.1.2.tar.gz
- Upload date:
- Size: 163.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bab5ffe14aef4f2af3c0944ebea3300c7a7a79650f7335a0b019560bfcedb0c0
|
|
| MD5 |
8faba74467ff4e0bb4147ef88e5140be
|
|
| BLAKE2b-256 |
c9cf7684f8c179f7dc932fd11f911ab066d26c5ebde2b8427ba487836184b7a8
|
Provenance
The following attestation bundles were made for raygeo-0.1.2.tar.gz:
Publisher:
release.yml on barebaric/raygeo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raygeo-0.1.2.tar.gz -
Subject digest:
bab5ffe14aef4f2af3c0944ebea3300c7a7a79650f7335a0b019560bfcedb0c0 - Sigstore transparency entry: 1551603184
- Sigstore integration time:
-
Permalink:
barebaric/raygeo@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/barebaric
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Trigger Event:
release
-
Statement type:
File details
Details for the file raygeo-0.1.2-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: raygeo-0.1.2-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 529.8 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba7e70c121926293c5a0236c96a36aad762d42c97523df0ae687892d1fc40b55
|
|
| MD5 |
daf2beaed5a398c81c354a8e07b2f96d
|
|
| BLAKE2b-256 |
d7fe4e61480e2ef6a1566527a3713097f866f12bdbbcb5cf4573c48f4da0b1e7
|
Provenance
The following attestation bundles were made for raygeo-0.1.2-cp313-cp313-win_amd64.whl:
Publisher:
release.yml on barebaric/raygeo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raygeo-0.1.2-cp313-cp313-win_amd64.whl -
Subject digest:
ba7e70c121926293c5a0236c96a36aad762d42c97523df0ae687892d1fc40b55 - Sigstore transparency entry: 1551604437
- Sigstore integration time:
-
Permalink:
barebaric/raygeo@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/barebaric
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Trigger Event:
release
-
Statement type:
File details
Details for the file raygeo-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: raygeo-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 695.0 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a8373c8eaf5f5dd77d92919452c09353952bc1cb204e1f7835fca01547cebd2
|
|
| MD5 |
726ffe7880a63f9504a036b48e0c594d
|
|
| BLAKE2b-256 |
43247fafc94f8511274b776e4463e0d3b7489b5ba9564f979e5f14d224942e67
|
Provenance
The following attestation bundles were made for raygeo-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on barebaric/raygeo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raygeo-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
1a8373c8eaf5f5dd77d92919452c09353952bc1cb204e1f7835fca01547cebd2 - Sigstore transparency entry: 1551604368
- Sigstore integration time:
-
Permalink:
barebaric/raygeo@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/barebaric
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Trigger Event:
release
-
Statement type:
File details
Details for the file raygeo-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: raygeo-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 627.9 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78e48369e0364ab641a81844aa535448ea681e66423bf2f7fd8a2b63d0973845
|
|
| MD5 |
c74c506cfbe7df85c01e6bb7e861cf95
|
|
| BLAKE2b-256 |
3cb23ca58fff09297fe6e8907d15abb1303e499c9af2d1fdafa62ce7a7098241
|
Provenance
The following attestation bundles were made for raygeo-0.1.2-cp313-cp313-macosx_11_0_arm64.whl:
Publisher:
release.yml on barebaric/raygeo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raygeo-0.1.2-cp313-cp313-macosx_11_0_arm64.whl -
Subject digest:
78e48369e0364ab641a81844aa535448ea681e66423bf2f7fd8a2b63d0973845 - Sigstore transparency entry: 1551604594
- Sigstore integration time:
-
Permalink:
barebaric/raygeo@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/barebaric
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Trigger Event:
release
-
Statement type:
File details
Details for the file raygeo-0.1.2-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: raygeo-0.1.2-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 648.9 kB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16a1b0183173fe08868a58c02fc3b5fb665b06f7b734038b978a96b0a6fca98e
|
|
| MD5 |
49533e349eab4b9c6fb3baaddde37baf
|
|
| BLAKE2b-256 |
8610abe177950fab65981b80d9dd7b69cffe1ac59329019c374025e7cb068c75
|
Provenance
The following attestation bundles were made for raygeo-0.1.2-cp313-cp313-macosx_10_12_x86_64.whl:
Publisher:
release.yml on barebaric/raygeo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raygeo-0.1.2-cp313-cp313-macosx_10_12_x86_64.whl -
Subject digest:
16a1b0183173fe08868a58c02fc3b5fb665b06f7b734038b978a96b0a6fca98e - Sigstore transparency entry: 1551604292
- Sigstore integration time:
-
Permalink:
barebaric/raygeo@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/barebaric
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d1b1fb0d7e91542ba431d339d2cf359ca572153c -
Trigger Event:
release
-
Statement type: