Skip to content

Commit 1d1acde

Browse files
authored
fix backwards compatibility of fix_object API (#36)
1 parent 5bd105b commit 1d1acde

5 files changed

Lines changed: 55 additions & 26 deletions

File tree

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Libctl Release Notes
22

3+
## libctl 4.2.0
4+
5+
* Better handling of `center` parameter of prisms, allowing this
6+
to be optionally specified (#35). Deprecates old `geom_fix_object`
7+
and `geom_fix_objects0` functions in favor of `geom_fix_object_ptr`
8+
and `geom_fix_object_list`. (In particular, the old `geom_fix_object` routine will not work properly for prisms in
9+
which the center was not computed.)
10+
311
## libctl 4.1.4
412

513
11/16/18

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Process this file with autoconf to produce a configure script.
2-
AC_INIT(libctl, 4.1.4, stevenj@alum.mit.edu)
2+
AC_INIT(libctl, 4.2.0, stevenj@alum.mit.edu)
33
AC_CONFIG_SRCDIR([src/ctl.c])
44
AC_CONFIG_HEADERS([config.h src/ctl.h])
55
AC_CONFIG_MACRO_DIR([m4])
@@ -8,7 +8,7 @@ AM_MAINTAINER_MODE
88
# Shared-library version number; indicates api compatibility, and is
99
# not the same as the "public" version number. (Don't worry about this
1010
# except for public releases.)
11-
SHARED_VERSION_INFO="7:2:0" # CURRENT:REVISION:AGE
11+
SHARED_VERSION_INFO="7:3:0" # CURRENT:REVISION:AGE
1212

1313
AM_INIT_AUTOMAKE([foreign])
1414
AC_SUBST(SHARED_VERSION_INFO)

utils/ctlgeom.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
# define MATERIAL_TYPE void*
4040
#endif
4141

42+
/* Where possible (e.g. for gcc >= 3.1), enable a compiler warning
43+
for code that uses a deprecated function */
44+
#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__==3 && __GNUC_MINOR__ > 0))
45+
# define CTLGEOM_DEPRECATED __attribute__((deprecated))
46+
#else
47+
# define CTLGEOM_DEPRECATED
48+
#endif
49+
4250
#ifdef __cplusplus
4351
extern "C" {
4452
#endif /* __cplusplus */
@@ -51,9 +59,11 @@ extern void display_geometric_object_info(int indentby, geometric_object o);
5159
#endif
5260

5361
extern void geom_initialize(void);
54-
extern void geom_fix_object(GEOMETRIC_OBJECT *o);
62+
extern void geom_fix_object_ptr(GEOMETRIC_OBJECT *o);
63+
extern void geom_fix_object(GEOMETRIC_OBJECT o) CTLGEOM_DEPRECATED;
5564
extern void geom_fix_objects(void);
56-
extern void geom_fix_objects0(GEOMETRIC_OBJECT_LIST geometry);
65+
extern void geom_fix_objects0(GEOMETRIC_OBJECT_LIST geometry) CTLGEOM_DEPRECATED;
66+
extern void geom_fix_object_list(GEOMETRIC_OBJECT_LIST geometry);
5767
extern void geom_fix_lattice(void);
5868
extern void geom_fix_lattice0(LATTICE *L);
5969
extern void geom_cartesian_lattice(void);

utils/geom.c

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ static vector3 cartesian_to_lattice(vector3 v)
9898
v);
9999
}
100100

101-
/* geom_fix_object is called after an object's externally-configurable parameters
101+
/* geom_fix_object_ptr is called after an object's externally-configurable parameters
102102
have been initialized, but before any actual geometry calculations are done;
103103
it is an opportunity to (re)compute internal data fields (such as cached
104104
rotation matrices) that depend on externally-configurable parameters.
105-
105+
106106
One example: "Fix" the parameters of the given object to account for the
107107
geometry_lattice basis, which may be non-orthogonal. In particular,
108108
this means that the normalization of several unit vectors, such
@@ -111,7 +111,7 @@ static vector3 cartesian_to_lattice(vector3 v)
111111
Unfortunately, we can't do this stuff at object-creation time
112112
in Guile, because the geometry_lattice variable may not have
113113
been assigned to its final value at that point. */
114-
void geom_fix_object(geometric_object *o)
114+
void geom_fix_object_ptr(geometric_object *o)
115115
{
116116
switch(o->which_subclass) {
117117
case GEOM CYLINDER:
@@ -142,7 +142,7 @@ void geom_fix_object(geometric_object *o)
142142
break;
143143
}
144144
case GEOM PRISM:
145-
{
145+
{
146146
init_prism(o);
147147
break;
148148
}
@@ -156,7 +156,7 @@ void geom_fix_object(geometric_object *o)
156156
if (os[i].material.which_subclass == MAT MATERIAL_TYPE_SELF)
157157
material_type_copy(&o->material, &os[i].material);
158158
#endif
159-
geom_fix_object(os + i);
159+
geom_fix_object_ptr(os + i);
160160
}
161161
break;
162162
}
@@ -165,14 +165,25 @@ void geom_fix_object(geometric_object *o)
165165
}
166166
}
167167

168+
// deprecated API — doesn't work for prisms
169+
void geom_fix_object(geometric_object o)
170+
{
171+
geom_fix_object_ptr(&o);
172+
}
173+
168174
/* fix all objects in the geometry list as described in
169175
geom_fix_object, above */
170-
void geom_fix_objects0(geometric_object_list geometry)
176+
void geom_fix_object_list(geometric_object_list geometry)
171177
{
172178
int index;
173179

174180
for (index = 0; index < geometry.num_items; ++index)
175-
geom_fix_object(geometry.items + index);
181+
geom_fix_object_ptr(geometry.items + index);
182+
}
183+
184+
void geom_fix_objects0(geometric_object_list geometry)
185+
{
186+
geom_fix_object_list(geometry);
176187
}
177188

178189
void geom_fix_objects(void)
@@ -239,7 +250,7 @@ void geom_initialize(void)
239250

240251
boolean CTLIO point_in_objectp(vector3 p, geometric_object o)
241252
{
242-
geom_fix_object(&o);
253+
geom_fix_object_ptr(&o);
243254
return point_in_fixed_objectp(p, o);
244255
}
245256

@@ -420,7 +431,7 @@ vector3 from_geom_object_coords(vector3 p, geometric_object o)
420431

421432
vector3 CTLIO normal_to_object(vector3 p, geometric_object o)
422433
{
423-
geom_fix_object(&o);
434+
geom_fix_object_ptr(&o);
424435
return normal_to_fixed_object(p, o);
425436
}
426437

@@ -484,7 +495,7 @@ vector3 normal_to_fixed_object(vector3 p, geometric_object o)
484495
} // case BLK ELLIPSOID
485496

486497
} // switch (o.subclass.block_data->which_subclass)
487-
498+
488499
} // case GEOM BLOCK
489500

490501
case GEOM PRISM:
@@ -557,7 +568,7 @@ vector3 normal_to_fixed_object(vector3 p, geometric_object o)
557568

558569
boolean CTLIO point_in_periodic_objectp(vector3 p, geometric_object o)
559570
{
560-
geom_fix_object(&o);
571+
geom_fix_object_ptr(&o);
561572
return point_in_periodic_fixed_objectp(p, o);
562573
}
563574

@@ -654,7 +665,7 @@ material_type material_of_point(vector3 p)
654665

655666
void CTLIO display_geometric_object_info(int indentby, geometric_object o)
656667
{
657-
geom_fix_object(&o);
668+
geom_fix_object_ptr(&o);
658669
printf("%*s", indentby, "");
659670
switch (o.which_subclass) {
660671
case GEOM CYLINDER:
@@ -1081,7 +1092,7 @@ static number compute_dot_cross(vector3 a, vector3 b, vector3 c)
10811092
etcetera. */
10821093
void geom_get_bounding_box(geometric_object o, geom_box *box)
10831094
{
1084-
geom_fix_object(&o);
1095+
geom_fix_object_ptr(&o);
10851096

10861097
/* initialize to empty box at the center of the object: */
10871098
box->low = box->high = o.center;
@@ -2007,7 +2018,7 @@ geometric_object make_cylinder(material_type material, vector3 center,
20072018
o.subclass.cylinder_data->height = height;
20082019
o.subclass.cylinder_data->axis = axis;
20092020
o.subclass.cylinder_data->which_subclass = CYL CYLINDER_SELF;
2010-
geom_fix_object(&o);
2021+
geom_fix_object_ptr(&o);
20112022
return o;
20122023
}
20132024

@@ -2033,7 +2044,7 @@ geometric_object make_wedge(material_type material, vector3 center,
20332044
CHECK(o.subclass.cylinder_data->subclass.wedge_data, "out of memory");
20342045
o.subclass.cylinder_data->subclass.wedge_data->wedge_angle = wedge_angle;
20352046
o.subclass.cylinder_data->subclass.wedge_data->wedge_start = wedge_start;
2036-
geom_fix_object(&o);
2047+
geom_fix_object_ptr(&o);
20372048
return o;
20382049
}
20392050

@@ -2061,7 +2072,7 @@ geometric_object make_block(material_type material, vector3 center,
20612072
o.subclass.block_data->e3 = e3;
20622073
o.subclass.block_data->size = size;
20632074
o.subclass.block_data->which_subclass = BLK BLOCK_SELF;
2064-
geom_fix_object(&o);
2075+
geom_fix_object_ptr(&o);
20652076
return o;
20662077
}
20672078

@@ -2090,7 +2101,7 @@ geometric_object make_ellipsoid(material_type material, vector3 center,
20902101
* Most calculations are done in the "prism coordinate system",
20912102
* in which the prism floor lies in the XY plane with centroid
20922103
* at the origin and the prism axis is the positive Z-axis.
2093-
* Some variable naming conventions:
2104+
* Some variable naming conventions:
20942105
* -- Suffix 'p' or '_p' on variable names identifies variables
20952106
* storing coordinates or vector components in the prism system.
20962107
* Suffix 'c' or '_c' (or no suffix) corresponds to coodinates/components
@@ -2209,7 +2220,7 @@ boolean node_in_or_on_polygon(vector3 q0, vector3 *nodes, int num_nodes,
22092220
{ int status = intersect_ray_with_segment(q0, nodes[nn], nodes[(nn+1)%num_nodes], u, 0);
22102221
if (status==IN_SEGMENT)
22112222
return include_boundaries;
2212-
else if (status==INTERSECTING)
2223+
else if (status==INTERSECTING)
22132224
edges_crossed++;
22142225
else if (status==ON_RAY)
22152226
{ vector3 nm1 = nodes[ (nn==0 ? num_nodes-1 : nn-1) ];
@@ -2263,7 +2274,7 @@ boolean point_in_prism(prism *prsm, vector3 pc)
22632274

22642275
// comparator for qsort
22652276
static int dcmp(const void *pd1, const void *pd2)
2266-
{ double d1=*((double *)pd1), d2=*((double *)pd2);
2277+
{ double d1=*((double *)pd1), d2=*((double *)pd2);
22672278
return (d1<d2) ? -1.0 : (d1>d2) ? 1.0 : 0.0;
22682279
}
22692280

@@ -2418,7 +2429,7 @@ double normal_distance_to_plane(vector3 p,
24182429
// the in-plane distance from pPlane to the quadrilateral
24192430
double min_distance_to_quadrilateral(vector3 p,
24202431
vector3 o, vector3 v1, vector3 v2, vector3 v3)
2421-
{
2432+
{
24222433
int inside;
24232434
double s=normal_distance_to_plane(p, o, v1, v2, v3, &inside);
24242435
if(inside==1)
@@ -2511,7 +2522,7 @@ void get_prism_bounding_box(prism *prsm, geom_box *box)
25112522
int nv, fc;
25122523
for(nv=0; nv<num_vertices; nv++)
25132524
for(fc=0; fc<2; fc++) // 'floor,ceiling'
2514-
{
2525+
{
25152526
vector3 v = vertices[nv];
25162527
if (fc==1)
25172528
v = vector3_plus(v, vector3_scale(prsm->height, prsm->axis) );

utils/geomtst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void test_overlap(double tol,
183183
geometry_lattice.basis2 = random_unit_vector3();
184184
geometry_lattice.basis3 = random_unit_vector3();
185185
geom_fix_lattice();
186-
geom_fix_object(&o);
186+
geom_fix_object_ptr(&o);
187187
#endif
188188

189189
b.low = make_vector3(myurand(-1,0), myurand(-1,0), myurand(-1,0));

0 commit comments

Comments
 (0)