Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ea72675
add reverse method like `__radd__`, `__rmul__`, etc.
Jul 27, 2023
4095c99
fix inconsistent indentation
Jul 28, 2023
2d1a680
fix binary arithmetic operators in `math` module
Jul 28, 2023
e9800f3
add `noexcept` to `_edge_compare` function
Jul 28, 2023
245faf7
add ignoring `numpy` deplicated warning
Aug 2, 2023
b993ac6
change to return from raise
Jul 27, 2023
7a12a04
update cython version constraint in pyproject.toml
munechika-koyo Nov 27, 2024
80a6f5f
fix: replace `DEF` statements with `cdef enum`, `cdef const` and use …
munechika-koyo Jul 18, 2025
4bf12d8
refactor: remove redundant DEF constants for R_2_PI and R_4_PI
munechika-koyo Jul 18, 2025
a87eb2d
refactor: remove unused constants and clean up docstring formatting
munechika-koyo Jul 18, 2025
1ad5da5
chore: update cython version constraint to 3.1 in pyproject.toml
munechika-koyo Jul 18, 2025
fb31ca6
Merge remote-tracking branch 'munechika/cython_v3_support' into featu…
CnlPepper Jul 19, 2025
d91e083
Update cython version.
CnlPepper Jul 19, 2025
1df6f31
Update cython version.
CnlPepper Jul 19, 2025
1696d1f
Revised various segments of the code to both modernise it and support…
CnlPepper Jul 20, 2025
e4804b0
Revised various segments of the code to both modernise it and support…
CnlPepper Jul 20, 2025
2359eff
Revised various segments of the code to both modernise it and support…
CnlPepper Jul 20, 2025
e6a3c02
Add python 3.13 to the test matrix.
CnlPepper Jul 20, 2025
3bc16d2
Removed random text that was accidentally added to .gitignore.
CnlPepper Jul 20, 2025
ce4bff9
Renamed all instances of the word "targetted" with "targeted" to fix …
CnlPepper Jul 20, 2025
a5a571b
Merge branch 'refs/heads/development' into feature/cython3
CnlPepper Jul 22, 2025
3d1ee34
Regenerated meson.build files using new generator.
CnlPepper Jul 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: python -m pip install --prefer-binary meson-python meson ninja setuptools "cython>=0.28,<3.0" "matplotlib>=3,<4" ${{ matrix.numpy-version }}
run: python -m pip install --prefer-binary meson-python meson ninja setuptools "cython>=3.1" "matplotlib>=3,<4" ${{ matrix.numpy-version }}
- name: Build and install Raysect
run: dev/install_editable.sh
- name: Run tests
Expand Down
3 changes: 2 additions & 1 deletion dev/root-meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ py = import('python').find_installation(pure: false)
numpy = dependency('numpy', method: 'config-tool')
fs = import('fs')

cython_args = ['--annotate']
# disabling explicit noexcept until pycharm fixes their cython 3 support (causes a large number of build warnings)
cython_args = ['--annotate', '-X legacy_implicit_noexcept=True']
cython_dependencies = [numpy]
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ py = import('python').find_installation(pure: false)
numpy = dependency('numpy', method: 'config-tool')
fs = import('fs')

cython_args = ['--annotate']
# disabling explicit noexcept until pycharm fixes their cython 3 support
cython_args = ['--annotate', '-Xlegacy_implicit_noexcept=True']
cython_dependencies = [numpy]

subdir('raysect')
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Issues = "https://github.com/raysect/source/issues"
Changelog = "https://github.com/raysect/source/blob/master/CHANGELOG.txt"

[build-system]
requires = ["meson-python", "setuptools", "wheel", "numpy", "cython<3.0"]
requires = ["meson-python", "setuptools", "wheel", "numpy", "cython>=3.1"]
build-backend = "mesonpy"
3 changes: 1 addition & 2 deletions raysect/core/acceleration/accelerator.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ from raysect.core.ray cimport Ray
from raysect.core.math cimport Point3D
from raysect.core.intersection cimport Intersection


cdef class Accelerator:

cpdef build(self, list primitives)

cpdef Intersection hit(self, Ray ray)

cpdef list contains(self, Point3D point)
3 changes: 0 additions & 3 deletions raysect/core/acceleration/accelerator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@
cdef class Accelerator:

cpdef build(self, list primitives):

pass

cpdef Intersection hit(self, Ray ray):

raise NotImplementedError("Accelerator virtual method hit() has not been implemented.")

cpdef list contains(self, Point3D point):

raise NotImplementedError("Accelerator virtual method contains() has not been implemented.")
9 changes: 4 additions & 5 deletions raysect/core/acceleration/boundprimitive.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ from raysect.core.intersection cimport Intersection

cdef class BoundPrimitive:

cdef readonly Primitive primitive
cdef readonly BoundingBox3D box
cdef bint _primitive_tested
cdef:
readonly Primitive primitive
readonly BoundingBox3D box
bint _primitive_tested

cdef Intersection hit(self, Ray ray)

cdef Intersection next_intersection(self)

cdef bint contains(self, Point3D point)
3 changes: 3 additions & 0 deletions raysect/core/acceleration/kdtree.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ from raysect.core.acceleration.accelerator cimport Accelerator as _Accelerator
from raysect.core.math.spatial.kdtree3d cimport KDTree3DCore as _KDTreeCore
from raysect.core.intersection cimport Intersection


cdef class _PrimitiveKDTree(_KDTreeCore):

cdef:
list primitives
Intersection hit_intersection


cdef class KDTree(_Accelerator):

cdef _PrimitiveKDTree _kdtree

1 change: 0 additions & 1 deletion raysect/core/acceleration/kdtree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ cdef class _PrimitiveKDTree(_KDTreeCore):
# dereference the primitives and check if they contain the point
enclosing_primitives = []
for item in range(count):

index = self._nodes[id].items[item]
primitive = <BoundPrimitive> self.primitives[index]
if primitive.contains(point):
Expand Down
5 changes: 3 additions & 2 deletions raysect/core/acceleration/unaccelerated.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ from raysect.core.boundingbox cimport BoundingBox3D

cdef class Unaccelerated(Accelerator):

cdef list primitives
cdef BoundingBox3D world_box
cdef:
list primitives
BoundingBox3D world_box
13 changes: 2 additions & 11 deletions raysect/core/acceleration/unaccelerated.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ from raysect.core.math cimport Point3D
from raysect.core.intersection cimport Intersection
from raysect.core.acceleration.boundprimitive cimport BoundPrimitive


cdef class Unaccelerated(Accelerator):

def __init__(self):
Expand All @@ -54,7 +55,6 @@ cdef class Unaccelerated(Accelerator):
self.world_box = BoundingBox3D()

for primitive in primitives:

accel_primitive = BoundPrimitive(primitive)
self.primitives.append(accel_primitive)
self.world_box.union(accel_primitive.box)
Expand All @@ -70,23 +70,17 @@ cdef class Unaccelerated(Accelerator):

# does the ray intersect the space containing the primitives
if not self.world_box.hit(ray):

return None

# find the closest primitive-ray intersection
closest_intersection = None

# intial search distance is maximum possible ray extent
# initial search distance is maximum possible ray extent
distance = ray.max_distance

for primitive in self.primitives:

intersection = primitive.hit(ray)

if intersection is not None:

if intersection.ray_distance < distance:

distance = intersection.ray_distance
closest_intersection = intersection

Expand All @@ -101,15 +95,12 @@ cdef class Unaccelerated(Accelerator):
BoundPrimitive primitive

if not self.world_box.contains(point):

return []

enclosing_primitives = []

for primitive in self.primitives:

if primitive.contains(point):

enclosing_primitives.append(primitive.primitive)

return enclosing_primitives
25 changes: 0 additions & 25 deletions raysect/core/boundingbox.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,21 @@ cdef class BoundingBox3D:
cdef Point3D upper

cdef Point3D get_centre(self)

cpdef bint hit(self, Ray ray)

cpdef tuple full_intersection(self, Ray ray)

cdef bint intersect(self, Ray ray, double *front_intersection, double *back_intersection)

cdef void _slab(self, double origin, double direction, double lower, double upper, double *front_intersection, double *back_intersection) nogil

cpdef bint contains(self, Point3D point)

cpdef object union(self, BoundingBox3D box)

cpdef object extend(self, Point3D point, double padding=*)

cpdef double surface_area(self)

cpdef double volume(self)

cpdef list vertices(self)

cpdef double extent(self, int axis) except -1

cpdef int largest_axis(self)

cpdef double largest_extent(self)

cpdef object pad(self, double padding)

cpdef object pad_axis(self, int axis, double padding)

cpdef BoundingSphere3D enclosing_sphere(self)


Expand All @@ -95,23 +79,14 @@ cdef class BoundingBox2D:
cdef Point2D upper

cpdef bint contains(self, Point2D point)

cpdef object union(self, BoundingBox2D box)

cpdef object extend(self, Point2D point, double padding=*)

cpdef double surface_area(self)

cpdef list vertices(self)

cpdef double extent(self, int axis) except -1

cpdef int largest_axis(self)

cpdef double largest_extent(self)

cpdef object pad(self, double padding)

cpdef object pad_axis(self, int axis, double padding)


Expand Down
14 changes: 8 additions & 6 deletions raysect/core/boundingbox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@
# TODO: add docstrings

cimport cython
from libc.math cimport INFINITY
from raysect.core.math cimport new_point3d, new_point2d

# cython doesn't have a built-in infinity constant, this compiles to +infinity
DEF INFINITY = 1e999

# axis defines
DEF X_AXIS = 0
DEF Y_AXIS = 1
DEF Z_AXIS = 2
cdef enum:
X_AXIS = 0
Y_AXIS = 1
Z_AXIS = 2


# defines the padding on the sphere which encloses the BoundingBox3D.
DEF SPHERE_PADDING = 1.000001
cdef const double SPHERE_PADDING = 1.000001


@cython.freelist(256)
Expand Down Expand Up @@ -258,6 +259,7 @@ cdef class BoundingBox3D:
return False
if (point.z < self.lower.z) or (point.z > self.upper.z):
return False

return True

cpdef object union(self, BoundingBox3D box):
Expand Down
8 changes: 0 additions & 8 deletions raysect/core/boundingsphere.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,11 @@ cdef class BoundingSphere3D:
Point3D centre

cpdef bint hit(self, Ray ray)

cpdef tuple full_intersection(self, Ray ray)

cdef bint intersect(self, Ray ray, double *front_intersection, double *back_intersection)

cpdef bint contains(self, Point3D point)

cpdef object union(self, BoundingSphere3D sphere)

cpdef object extend(self, Point3D point, double padding=*)

cpdef double surface_area(self)

cpdef double volume(self)

cpdef object pad(self, double padding)
6 changes: 0 additions & 6 deletions raysect/core/containers.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,16 @@ cdef class LinkedList:
_Item last

cpdef bint is_empty(self)

cpdef add(self, object value)

cpdef add_items(self, object iterable)

cpdef object get_index(self, int index)

cpdef insert(self, object value, int index)

cpdef object remove(self, int index)


cdef class Stack(LinkedList):

cpdef push(self, object value)

cpdef object pop(self)


Expand Down
1 change: 1 addition & 0 deletions raysect/core/intersection.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

cimport cython


@cython.freelist(256)
cdef class Intersection:
"""
Expand Down
3 changes: 0 additions & 3 deletions raysect/core/math/_mat4.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ cdef class _Mat4:
cdef double m[4][4]

cdef double get_element(self, int row, int column)

cdef void set_element(self, int row, int column, double v)

cpdef bint is_identity(self, double tolerance=*)

cpdef bint is_close(self, _Mat4 other, double tolerance=*)

2 changes: 0 additions & 2 deletions raysect/core/math/_mat4.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ cdef class _Mat4:

# special handling for _Mat4
if isinstance(v, _Mat4):

m = <_Mat4>v
for i in range(0, 4):
for j in range(0, 4):
Expand Down Expand Up @@ -95,7 +94,6 @@ cdef class _Mat4:
Expects a tuple (row, column) as the index.

e.g. v = matrix[1, 2]

"""

cdef int row, column
Expand Down
6 changes: 0 additions & 6 deletions raysect/core/math/_vec3.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
cdef class _Vec3:

cdef public double x, y, z

cpdef double dot(self, _Vec3 v)

cpdef double angle(self, _Vec3 v)

cdef double get_length(self) nogil

cdef object set_length(self, double v)

cdef double get_index(self, int index) nogil

cdef void set_index(self, int index, double value) nogil

9 changes: 5 additions & 4 deletions raysect/core/math/_vec3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ cdef class _Vec3:
return self.y
elif i == 2:
return self.z
else:
raise IndexError("Index out of range [0, 2].")

raise IndexError("Index out of range [0, 2].")

def __setitem__(self, int i, double value):
"""Sets the vector coordinates by index ([0,1,2] -> [x,y,z])."""
Expand All @@ -74,6 +74,7 @@ cdef class _Vec3:
raise IndexError("Index out of range [0, 2].")

def __iter__(self):

yield self.x
yield self.y
yield self.z
Expand Down Expand Up @@ -189,8 +190,8 @@ cdef class _Vec3:
return self.y
elif index == 2:
return self.z
else:
return NAN

return NAN

cdef void set_index(self, int index, double value) nogil:
"""
Expand Down
1 change: 0 additions & 1 deletion raysect/core/math/affinematrix.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ from raysect.core.math._mat4 cimport _Mat4
cdef class AffineMatrix3D(_Mat4):

cpdef AffineMatrix3D inverse(self)

cdef AffineMatrix3D mul(self, AffineMatrix3D m)


Expand Down
Loading