@@ -34,40 +34,10 @@ static void material_type_copy(void **src, void **dest) { *dest = *src; }
3434#endif
3535#include "ctlgeom.h"
3636
37- /**************************************************************************/
38-
39- /* Private mesh internals.
40-
41- Inlined here rather than placed in a separate header because MPB/meep
42- and the libctl examples/ directory build by copying this geom.c file
43- out of the libctl tree, so any companion header would not travel with
44- it. Keep this section in sync with any future split if/when those
45- downstreams are taught to link against libctlgeom directly. */
46-
47- typedef struct mesh_bvh_node {
48- vector3 bbox_low ;
49- vector3 bbox_high ;
50- int left_child ;
51- int right_child ;
52- int face_start ;
53- int face_count ;
54- } mesh_bvh_node ;
55-
56- typedef struct mesh_internal {
57- int num_faces ;
58- int * face_indices ; /* unpacked flat: 3 ints per triangle */
59- vector3 * face_normals ;
60- number * face_areas ;
61- int num_bvh_nodes ;
62- mesh_bvh_node * bvh ;
63- int * bvh_face_ids ;
64- vector3 centroid ;
65- number lengthscale ;
66- } mesh_internal ;
37+ #ifndef CTL_H /* nusing scheme interface */
38+ #define SCM void*
39+ #endif
6740
68- static inline mesh_internal * mesh_priv (const mesh * m ) {
69- return (mesh_internal * )m -> internal ;
70- }
7141
7242#ifdef CXX_CTL_IO
7343using namespace ctlio ;
@@ -106,6 +76,43 @@ using namespace ctlio;
10676#define MAX (a , b ) ((a) > (b) ? (a) : (b))
10777#define MIN (a , b ) ((a) < (b) ? (a) : (b))
10878
79+ /**************************************************************************/
80+
81+ /* Private mesh internals.
82+
83+ Inlined here rather than placed in a separate header because MPB/meep
84+ and the libctl examples/ directory build by copying this geom.c file
85+ out of the libctl tree, so any companion header would not travel with
86+ it. Keep this section in sync with any future split if/when those
87+ downstreams are taught to link against libctlgeom directly. */
88+
89+ typedef struct mesh_bvh_node {
90+ vector3 bbox_low ;
91+ vector3 bbox_high ;
92+ int left_child ;
93+ int right_child ;
94+ int face_start ;
95+ int face_count ;
96+ } mesh_bvh_node ;
97+
98+ typedef struct mesh_internal {
99+ int num_faces ;
100+ int * face_indices ; /* unpacked flat: 3 ints per triangle */
101+ vector3 * face_normals ;
102+ number * face_areas ;
103+ int num_bvh_nodes ;
104+ mesh_bvh_node * bvh ;
105+ int * bvh_face_ids ;
106+ vector3 centroid ;
107+ number lengthscale ;
108+ } mesh_internal ;
109+
110+ static inline mesh_internal * mesh_priv (const mesh * m ) {
111+ return (mesh_internal * )m -> internal ;
112+ }
113+
114+ /**************************************************************************/
115+
109116// forward declarations of prism-related routines, at the bottom of this file
110117static boolean node_in_polygon (double qx , double qy , vector3 * nodes , int num_nodes );
111118static boolean point_in_prism (prism * prsm , vector3 pc );
@@ -2717,14 +2724,14 @@ static void mesh_internal_free(void *p) {
27172724/* Lifecycle hooks invoked by gen-ctl-io from the auto-generated mesh_copy
27182725 and mesh_destroy. Declared on the mesh class in geom.scm via
27192726 (after-copy ...) / (after-destroy ...). */
2720- void mesh_after_copy (mesh * m ) {
2727+ void CTLIO mesh_after_copy (mesh * m ) {
27212728 /* The auto-generated mesh_copy shallow-copies internal from the source;
27222729 discard that pointer so this copy gets its own cache, then build it. */
27232730 m -> internal = NULL ;
27242731 mesh_init_internal (m );
27252732}
27262733
2727- void mesh_after_destroy (mesh * m ) {
2734+ void CTLIO mesh_after_destroy (mesh * m ) {
27282735 mesh_internal_free (m -> internal );
27292736}
27302737
@@ -2746,7 +2753,7 @@ static void init_mesh(geometric_object *o) {
27462753 (either the mesh was just constructed, or reinit_mesh cleared it). */
27472754 mesh_internal * p = (mesh_internal * )calloc (1 , sizeof (mesh_internal ));
27482755 CHECK (p , "out of memory" );
2749- m -> internal = p ;
2756+ m -> internal = ( SCM ) p ;
27502757
27512758 /* Unpack face_indices: the public vector3_list stores 3 ints per
27522759 triangle packed into a vector3 (x, y, z are the indices as doubles,
@@ -3397,14 +3404,16 @@ double intersect_line_segment_with_prism(prism *prsm, vector3 pc, vector3 dc, do
33973404
33983405 if (na == -1 ) goto done ;
33993406
3400- int inside = ((na % 2 ) == 0 ? 0 : 1 );
3401- double last_s = a ;
3402- for (ns = na ; ns < num_intersections ; ns ++ ) {
3403- double this_s = fmin (b , slist [ns ]);
3404- if (inside ) ds += (this_s - last_s );
3405- if (b < slist [ns ]) break ;
3406- inside = (1 - inside );
3407- last_s = this_s ;
3407+ {
3408+ int inside = ((na % 2 ) == 0 ? 0 : 1 );
3409+ double last_s = a ;
3410+ for (ns = na ; ns < num_intersections ; ns ++ ) {
3411+ double this_s = fmin (b , slist [ns ]);
3412+ if (inside ) ds += (this_s - last_s );
3413+ if (b < slist [ns ]) break ;
3414+ inside = (1 - inside );
3415+ last_s = this_s ;
3416+ }
34083417 }
34093418
34103419done :
0 commit comments