Skip to main content

polyscope_rs/
transform.rs

1use crate::{Mat4, with_context, with_context_mut};
2
3/// Generates `set_<name>_transform` and `get_<name>_transform` functions for a structure type.
4macro_rules! impl_transform_accessors {
5    ($set_fn:ident, $get_fn:ident, $type_name:expr, $doc_name:expr) => {
6        #[doc = concat!("Sets the transform of a ", $doc_name, " by name.")]
7        pub fn $set_fn(name: &str, transform: Mat4) {
8            with_context_mut(|ctx| {
9                if let Some(s) = ctx.registry.get_mut($type_name, name) {
10                    s.set_transform(transform);
11                }
12            });
13        }
14
15        #[doc = concat!("Gets the transform of a ", $doc_name, " by name.")]
16        #[must_use]
17        pub fn $get_fn(name: &str) -> Option<Mat4> {
18            with_context(|ctx| {
19                ctx.registry
20                    .get($type_name, name)
21                    .map(polyscope_core::Structure::transform)
22            })
23        }
24    };
25}
26
27impl_transform_accessors!(
28    set_point_cloud_transform,
29    get_point_cloud_transform,
30    "PointCloud",
31    "point cloud"
32);
33impl_transform_accessors!(
34    set_surface_mesh_transform,
35    get_surface_mesh_transform,
36    "SurfaceMesh",
37    "surface mesh"
38);
39impl_transform_accessors!(
40    set_curve_network_transform,
41    get_curve_network_transform,
42    "CurveNetwork",
43    "curve network"
44);
45impl_transform_accessors!(
46    set_volume_mesh_transform,
47    get_volume_mesh_transform,
48    "VolumeMesh",
49    "volume mesh"
50);