Skip to content

Commit 384b0f5

Browse files
committed
Added noexcept flags to primitives package functions and methods.
1 parent e6e9998 commit 384b0f5

9 files changed

Lines changed: 41 additions & 41 deletions

File tree

raysect/primitive/box.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ cdef class Box(Primitive):
4343
cdef int _cached_face
4444
cdef int _cached_axis
4545

46-
cdef void _slab(self, int axis, double origin, double direction, double lower, double upper, double *near_intersection, double *far_intersection, int *near_face, int *far_face, int *near_axis, int *far_axis) nogil
46+
cdef void _slab(self, int axis, double origin, double direction, double lower, double upper, double *near_intersection, double *far_intersection, int *near_face, int *far_face, int *near_axis, int *far_axis) noexcept nogil
4747

4848
cdef Intersection _generate_intersection(self, Ray ray, Point3D origin, Vector3D direction, double ray_distance, int face, int axis)
4949

50-
cdef double _interior_offset(self, double hit_point, double lower, double upper) nogil
50+
cdef double _interior_offset(self, double hit_point, double lower, double upper) noexcept nogil

raysect/primitive/box.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ cdef class Box(Primitive):
231231

232232
return self._generate_intersection(self._cached_ray, self._cached_origin, self._cached_direction, self._next_t, self._cached_face, self._cached_axis)
233233

234-
cdef void _slab(self, int axis, double origin, double direction, double lower, double upper, double *near_intersection, double *far_intersection, int *near_face, int *far_face, int *near_axis, int *far_axis) nogil:
234+
cdef void _slab(self, int axis, double origin, double direction, double lower, double upper, double *near_intersection, double *far_intersection, int *near_face, int *far_face, int *near_axis, int *far_axis) noexcept nogil:
235235

236236
cdef:
237237
double reciprocal, tmin, tmax
@@ -327,7 +327,7 @@ cdef class Box(Primitive):
327327
return new_intersection(ray, ray_distance, self, hit_point, inside_point, outside_point,
328328
normal, exiting, self.to_local(), self.to_root())
329329

330-
cdef double _interior_offset(self, double hit_point, double lower, double upper) nogil:
330+
cdef double _interior_offset(self, double hit_point, double lower, double upper) noexcept nogil:
331331
"""
332332
Calculates an interior offset that ensures the inside_point is away from the primitive surface.
333333

raysect/primitive/csg.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ cdef class CSGPrimitive(Primitive):
4444
cdef Intersection _cache_last_intersection
4545
cdef bint _cache_invalid
4646

47-
cdef bint terminate_early(self, Intersection intersection)
47+
cdef bint terminate_early(self, Intersection intersection) noexcept
4848

4949
cdef Intersection _identify_intersection(self, Ray ray, Intersection intersection_a, Intersection intersection_b, Intersection closest_intersection)
5050

5151
cdef Intersection _closest_intersection(self, Intersection a, Intersection b)
5252

53-
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest)
53+
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest) noexcept
5454

5555
cdef Intersection _modify_intersection(self, Intersection closest, Intersection a, Intersection b)
5656

57-
cdef void rebuild(self)
57+
cdef void rebuild(self) noexcept
5858

5959

6060
cdef class CSGRoot(Node):

raysect/primitive/csg.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ cdef class CSGPrimitive(Primitive):
154154
# identify first valid intersection
155155
return self._identify_intersection(ray, intersection_a, intersection_b, closest_intersection)
156156

157-
cdef bint terminate_early(self, Intersection intersection):
157+
cdef bint terminate_early(self, Intersection intersection) noexcept:
158158
return False
159159

160160
cpdef Intersection next_intersection(self):
@@ -233,14 +233,14 @@ cdef class CSGPrimitive(Primitive):
233233
else:
234234
return b
235235

236-
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest):
236+
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest) noexcept:
237237
raise NotImplementedError("Warning: CSG operator not implemented")
238238

239239
cdef Intersection _modify_intersection(self, Intersection closest, Intersection a, Intersection b):
240240
# by default, do nothing
241241
return closest
242242

243-
cdef void rebuild(self):
243+
cdef void rebuild(self) noexcept:
244244
"""
245245
Triggers a rebuild of the CSG primitive's acceleration structures.
246246
"""
@@ -323,7 +323,7 @@ cdef class Union(CSGPrimitive):
323323
324324
"""
325325

326-
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest):
326+
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest) noexcept:
327327

328328
cdef bint inside_a, inside_b
329329

@@ -418,10 +418,10 @@ cdef class Intersect(CSGPrimitive):
418418
419419
"""
420420

421-
cdef bint terminate_early(self, Intersection intersection):
421+
cdef bint terminate_early(self, Intersection intersection) noexcept:
422422
return intersection is None
423423

424-
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest):
424+
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest) noexcept:
425425

426426
cdef bint inside_a, inside_b
427427

@@ -520,10 +520,10 @@ cdef class Subtract(CSGPrimitive):
520520
521521
"""
522522

523-
cdef bint terminate_early(self, Intersection intersection):
523+
cdef bint terminate_early(self, Intersection intersection) noexcept:
524524
return intersection is None
525525

526-
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest):
526+
cdef bint _valid_intersection(self, Intersection a, Intersection b, Intersection closest) noexcept:
527527

528528
cdef bint inside_a, inside_b
529529

raysect/primitive/cylinder.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ cdef class Cylinder(Primitive):
4747

4848
cdef Vector3D _interior_offset(self, Point3D hit_point, Normal3D normal, int type)
4949

50-
cdef bint _inside_cylinder(self, Point3D point)
50+
cdef bint _inside_cylinder(self, Point3D point) noexcept
5151

52-
cdef bint _inside_slab(self, Point3D point)
52+
cdef bint _inside_slab(self, Point3D point) noexcept

raysect/primitive/cylinder.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,12 @@ cdef class Cylinder(Primitive):
359359
point = point.transform(self.to_local())
360360
return self._inside_slab(point) and self._inside_cylinder(point)
361361

362-
cdef bint _inside_cylinder(self, Point3D point):
362+
cdef bint _inside_cylinder(self, Point3D point) noexcept:
363363

364364
# is the point inside the cylinder radius
365365
return (point.x * point.x + point.y * point.y) <= (self._radius * self._radius)
366366

367-
cdef bint _inside_slab(self, Point3D point):
367+
cdef bint _inside_slab(self, Point3D point) noexcept:
368368

369369
# first check point is within the cylinder upper and lower bounds
370370
return 0.0 <= point.z <= self._height

raysect/primitive/lens/spherical.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ cdef class BiConvex(EncapsulatedPrimitive):
111111
# attach to local root (performed in EncapsulatedPrimitive init)
112112
super().__init__(lens, parent, transform, material, name)
113113

114-
cdef void _calc_geometry(self):
114+
cdef void _calc_geometry(self) noexcept:
115115

116116
cdef double radius, radius_sqr
117117

@@ -126,7 +126,7 @@ cdef class BiConvex(EncapsulatedPrimitive):
126126
# edge thickness is the length of the barrel without the curved surfaces
127127
self.edge_thickness = self.center_thickness - (self.front_thickness + self.back_thickness)
128128

129-
cdef bint _is_short(self):
129+
cdef bint _is_short(self) noexcept:
130130
"""
131131
Do the facing spheres overlap sufficiently to build a lens using just their intersection?
132132
"""
@@ -245,7 +245,7 @@ cdef class BiConcave(EncapsulatedPrimitive):
245245
# attach to local root (performed in EncapsulatedPrimitive init)
246246
super().__init__(lens, parent, transform, material, name)
247247

248-
cdef void _calc_geometry(self):
248+
cdef void _calc_geometry(self) noexcept:
249249

250250
cdef double radius, radius_sqr
251251

@@ -327,7 +327,7 @@ cdef class PlanoConvex(EncapsulatedPrimitive):
327327
# attach to local root (performed in EncapsulatedPrimitive init)
328328
super().__init__(lens, parent, transform, material, name)
329329

330-
cdef void _calc_geometry(self):
330+
cdef void _calc_geometry(self) noexcept:
331331

332332
cdef double radius, radius_sqr
333333

@@ -341,7 +341,7 @@ cdef class PlanoConvex(EncapsulatedPrimitive):
341341
# edge thickness is the length of the barrel without the curved surfaces
342342
self.edge_thickness = self.center_thickness - self.curve_thickness
343343

344-
cdef bint _is_short(self):
344+
cdef bint _is_short(self) noexcept:
345345
"""
346346
Does the front sphere have sufficient radius to build the lens with just an intersection?
347347
"""
@@ -445,7 +445,7 @@ cdef class PlanoConcave(EncapsulatedPrimitive):
445445
# attach to local root (performed in EncapsulatedPrimitive init)
446446
super().__init__(lens, parent, transform, material, name)
447447

448-
cdef void _calc_geometry(self):
448+
cdef void _calc_geometry(self) noexcept:
449449

450450
cdef double radius, radius_sqr
451451

@@ -531,7 +531,7 @@ cdef class Meniscus(EncapsulatedPrimitive):
531531
# attach to local root (performed in EncapsulatedPrimitive init)
532532
super().__init__(lens, parent, transform, material, name)
533533

534-
cdef void _calc_geometry(self):
534+
cdef void _calc_geometry(self) noexcept:
535535

536536
cdef double radius, radius_sqr
537537

@@ -546,7 +546,7 @@ cdef class Meniscus(EncapsulatedPrimitive):
546546
# edge thickness is the length of the barrel without the front surface
547547
self.edge_thickness = self.center_thickness - self.front_thickness + self.back_thickness
548548

549-
cdef bint _is_short(self):
549+
cdef bint _is_short(self) noexcept:
550550
"""
551551
Does the front sphere have sufficient radius to build the lens with just an intersection?
552552
"""

raysect/primitive/mesh/mesh.pxd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ cdef class MeshData(KDTree3DCore):
6767
cdef object _flip_normals(self)
6868
cdef object _generate_face_normals(self)
6969
cdef BoundingBox3D _generate_bounding_box(self, int32_t i)
70-
cdef void _calc_rayspace_transform(self, Ray ray)
71-
cdef bint _hit_triangle(self, int32_t i, Ray ray, float[4] hit_data)
70+
cdef void _calc_rayspace_transform(self, Ray ray) noexcept
71+
cdef bint _hit_triangle(self, int32_t i, Ray ray, float[4] hit_data) noexcept
7272
cpdef Intersection calc_intersection(self, Ray ray)
7373
cdef Normal3D _intersection_normal(self)
74-
cpdef bint contains(self, Point3D p)
74+
cpdef bint contains(self, Point3D p) noexcept
7575
cpdef BoundingBox3D bounding_box(self, AffineMatrix3D to_world)
76-
cdef uint8_t _read_uint8(self, object file)
77-
cdef bint _read_bool(self, object file)
78-
cdef double _read_float(self, object file)
76+
cdef uint8_t _read_uint8(self, object file) noexcept
77+
cdef bint _read_bool(self, object file) noexcept
78+
cdef double _read_float(self, object file) noexcept
7979

8080

8181
cdef class Mesh(Primitive):

raysect/primitive/mesh/mesh.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ cdef class MeshData(KDTree3DCore):
503503

504504
return bbox
505505

506-
cpdef bint trace(self, Ray ray):
506+
cpdef bint trace(self, Ray ray) noexcept:
507507

508508
# reset hit data
509509
self._u = -1.0
@@ -517,7 +517,7 @@ cdef class MeshData(KDTree3DCore):
517517

518518
@cython.boundscheck(False)
519519
@cython.wraparound(False)
520-
cdef bint _trace_leaf(self, int32_t id, Ray ray, double max_range):
520+
cdef bint _trace_leaf(self, int32_t id, Ray ray, double max_range) noexcept:
521521

522522
cdef:
523523
float hit_data[4]
@@ -563,7 +563,7 @@ cdef class MeshData(KDTree3DCore):
563563
return True
564564

565565
@cython.cdivision(True)
566-
cdef void _calc_rayspace_transform(self, Ray ray):
566+
cdef void _calc_rayspace_transform(self, Ray ray) noexcept:
567567

568568
# This code is a Python port of the code listed in appendix A of
569569
# "Watertight Ray/Triangle Intersection", S.Woop, C.Benthin, I.Wald,
@@ -613,7 +613,7 @@ cdef class MeshData(KDTree3DCore):
613613
@cython.boundscheck(False)
614614
@cython.wraparound(False)
615615
@cython.initializedcheck(False)
616-
cdef bint _hit_triangle(self, int32_t i, Ray ray, float[4] hit_data):
616+
cdef bint _hit_triangle(self, int32_t i, Ray ray, float[4] hit_data) noexcept:
617617

618618
# This code is a Python port of the code listed in appendix A of
619619
# "Watertight Ray/Triangle Intersection", S.Woop, C.Benthin, I.Wald,
@@ -802,7 +802,7 @@ cdef class MeshData(KDTree3DCore):
802802
@cython.boundscheck(False)
803803
@cython.wraparound(False)
804804
@cython.initializedcheck(False)
805-
cpdef bint contains(self, Point3D p):
805+
cpdef bint contains(self, Point3D p) noexcept:
806806
"""
807807
Tests if a point is contained by the mesh.
808808
@@ -1035,13 +1035,13 @@ cdef class MeshData(KDTree3DCore):
10351035
m.load(file)
10361036
return m
10371037

1038-
cdef uint8_t _read_uint8(self, object file):
1038+
cdef uint8_t _read_uint8(self, object file) noexcept:
10391039
return (<uint8_t *> PyBytes_AsString(file.read(sizeof(uint8_t))))[0]
10401040

1041-
cdef bint _read_bool(self, object file):
1041+
cdef bint _read_bool(self, object file) noexcept:
10421042
return self._read_uint8(file) != 0
10431043

1044-
cdef double _read_float(self, object file):
1044+
cdef double _read_float(self, object file) noexcept:
10451045
return (<float *> PyBytes_AsString(file.read(sizeof(float))))[0]
10461046

10471047

0 commit comments

Comments
 (0)