/*
The MIT License
Copyright 2024 Tim Ayres
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Curv Library of the Catalog of Triply Periodic Minimal Surfaces (TPMS)
References:
   https://doi.org/10.1016/j.dib.2023.109311
   https://github.com/jwf23/Equation-Based-Lattice-Structure-Dataset

Contains information from Equation-Based-Lattice-Structure-Dataset which is made available
under the ODC Attribution License.
===================================================================================================

This library contains the equations for all 27 of the surfaces described in the dataset above,
as well as the gyroid variants and a parametric equation for the OCTO surface. Shape names
are kept the same as in the Matlab files in the dataset for consistency.

Variables:
    d = unit cell, a vector of three numbers describing the dimensions of the lattice unit cell
        (one period). Default is [1, 1, 1]. The x, y , and sizes of the bounding box do not need
        to be equal.
*/

{ // Start record

/*
Catalog section:    2.1
Catalog name:       Gyroid
Catalog equation:   8
Wikipedia:          https://en.wikipedia.org/wiki/Gyroid
Congruent:          Yes
t_crit =            +/-1.500
t_pinch =           +/-1.414
VF_skel_pinch =     1.638%
*/
tpms_gyroid =
    let tpms_gyroid_func {d} =
        make_shape {
            dist[x,y,z,_] = cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*sin(tau/d.[X]*x)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_gyroid_func {d:[1, 1, 1]},
        call : tpms_gyroid_func,
    };

/*
Catalog section:    2.1
Catalog name:       Gyroid Alternate
Catalog equation:   9
Wikipedia:          https://en.wikipedia.org/wiki/Gyroid
Congruent:          Yes
VF = 0.3325*level + 0.5001
Comments: this one is nice if you want thin skeletal lattices
Intended to be used with offset (level) < or > 1.41
*/
tpms_gyroid2 =
    let 
        func[x, y, z, d, level] = if (abs(level) < 1.41)
                                  (cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)
                                  + cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                                  + cos(tau/d.[Z]*z)*sin(tau/d.[X]*x)
                                  - level)
                                  else
                                  (cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)
                                  + cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                                  + cos(tau/d.[Z]*z)*sin(tau/d.[X]*x)
                                  - (0.45*level-0.58)*(cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                                  + cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                                  + cos(2*tau/d.[Z]*z)*cos(2*tau/d.[X]*x))
                                  - level);
        tpms_gyroid2_func {d, level} =
            make_shape {
                dist[x,y,z,_] = func[x, y, z, d, level];
                is_3d = true;
            };
    in make_shape {
        ... tpms_gyroid2_func {d:[1, 1, 1], level:0},
        call : tpms_gyroid2_func,
    };

/*
Catalog section:    2.1
Catalog name:       Gyroid Alternate
Catalog equation:   11
Wikipedia:          https://en.wikipedia.org/wiki/Gyroid
Congruent:          Yes
Comments: this one is not recommended, but is included for completeness. It pinches of earlier than gyroid2
*/
tpms_gyroid3 =
    let tpms_gyroid2_func {d} =
        make_shape {
            dist[x,y,z,_] = cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*sin(tau/d.[X]*x)
                            + 0.08*(cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(2*tau/d.[Z]*z)*cos(2*tau/d.[X]*x))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_gyroid2_func {d:[1, 1, 1]},
        call : tpms_gyroid2_func,
    };

/*
Catalog section:    2.2
Catalog name:       D
Catalog equation:   12
Wikipedia:          https://en.wikipedia.org/wiki/Schwarz_minimal_surface#Schwarz_D_(%22Diamond%22)
Congruent:          Yes
t_crit =            +/-1.414
t_pinch =           +/-0.999
VF_skel_pinch =     8.101%
*/
tpms_d =
    let tpms_d_func {d} =
        make_shape {
            dist[x,y,z,_] = sin(tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_d_func {d:[1, 1, 1]},
        call : tpms_d_func,
    };

/*
Catalog section:    2.3
Catalog name:       P
Catalog equation:   13
Wikipedia:          https://en.wikipedia.org/wiki/Schwarz_minimal_surface#Schwarz_P_(%22Primitive%22)
Congruent:          Yes
t_crit =            +/-3.000
t_pinch =           +/-1.000
VF_skel_pinch =     21.36%
*/
tpms_p =
    let tpms_p_func {d} =
        make_shape {
            dist[x,y,z,_] = cos(tau/d.[X]*x) + cos(tau/d.[Y]*y) + cos(tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_p_func {d:[1, 1, 1]},
        call : tpms_p_func,
    };

/*
Catalog section:    2.4
Catalog name:       IWP
Catalog equation:   14
Congruent:          No
t_endo_crit =       -4.998
t_exo_crit =        3.000
t_endo_pinch =      -2.999
t_exo_pinch =       3.000
VF_endo_pinch =     10.06%
VF_exo_pinch =      0.000%
*/
tpms_iwp =
    let tpms_iwp_func {d} =
        make_shape {
            dist[x,y,z,_] = 2*(cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*cos(tau/d.[X]*x))
                            - (cos(2*tau/d.[X]*x) + cos(2*tau/d.[Y]*y) + cos(2*tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_iwp_func {d:[1, 1, 1]},
        call : tpms_iwp_func,
    };

/*
Catalog section:    2.5
Catalog name:       Neovius
Catalog equation:   15
Wikipedia:          https://en.wikipedia.org/wiki/Neovius_surface
Congruent:          Yes
t_crit =            +/-13.000
t_pinch =           +/-0.749
VF_skel_pinch =     33.57%
*/
tpms_neovius =
    let tpms_neovius_func {d} =
        make_shape {
            dist[x,y,z,_] = 3*(cos(tau/d.[X]*x) + cos(tau/d.[Y]*y) + cos(tau/d.[Z]*z))
                            + 4*cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_neovius_func {d:[1, 1, 1]},
        call : tpms_neovius_func,
    };

/*
Catalog section:    2.6
Catalog name:       C(Y)
Catalog equation:   16
Congruent:          Yes
t_crit =            +/-3.535
t_pinch =           +/-1.835
t_pinch2 =          +/-1.957
VF_skel_pinch =     7.637%
VF_skel_pinch2 =    1.189
*/
tpms_c_y =
    let tpms_c_y_func {d} =
        make_shape {
            dist[x,y,z,_] = -sin(tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(2*tau/d.[X]*x)*sin(tau/d.[Y]*y)
                            + sin(2*tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Z]*z)
                            - cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + sin(2*tau/d.[X]*x)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(2*tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*sin(2*tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_c_y_func {d:[1, 1, 1]},
        call : tpms_c_y_func,
    };

/*
Catalog section:    2.7
Catalog name:       Lidinoid
Catalog equation:   17
Wikipedia:          https://en.wikipedia.org/wiki/Lidinoid
Congruent:          No
t_endo_crit =       -2.700
t_exo_crit =        2.300
t_endo_pinch =      -0.347
t_exo_pinch =       0.299
t_exo_pinch2 =      1.873
VF_endo_pinch =     25.42
VF_exo_pinch =      49.55
VF_exo_pinch2 =     5.540
*/
tpms_lidinoid =
    let tpms_lidinoid_func {d} =
        make_shape {
            dist[x,y,z,_] = (sin(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)*sin(tau/d.[X]*x)
                            + sin(2*tau/d.[Z]*z)*cos(tau/d.[X]*x)*sin(tau/d.[Y]*y))
                            - (cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(2*tau/d.[Z]*z)*cos(2*tau/d.[X]*x))
                            + 0.3
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_lidinoid_func {d:[1, 1, 1]},
        call : tpms_lidinoid_func,
    };

/*
Catalog section:    2.8
Catalog name:       OCTO
Catalog equation:   19
Congruent:          No
t_endo_crit =       -0.750
t_exo_crit =        3.249
t_endo_pinch =      -0.216
t_exo_pinch =       0.049
VF_endo_pinch =     22.75
VF_exo_pinch =      47.49
*/
tpms_octo =
    let tpms_octo_func {d} =
        make_shape {
            dist[x,y,z,_] = 0.6*(cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*cos(tau/d.[X]*x))
                            - 0.4*(cos(tau/d.[X]*x) + cos(tau/d.[Y]*y) + cos(tau/d.[Z]*z))
                            + 0.25
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_octo_func {d:[1, 1, 1]},
        call : tpms_octo_func,
    };

/*
Catalog section:    2.8
Catalog name:       OCTO
Catalog equation:   20, Table 10
Congruent:          No
Comments: fully parametric version
*/
tpms_octo_para =
    let tpms_octo_para_func {d, a, b, c, t0} =
        make_shape {
            dist[x,y,z,_] = a*(cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*cos(tau/d.[X]*x))
                            + b*(cos(tau/d.[X]*x) + cos(tau/d.[Y]*y) + cos(tau/d.[Z]*z))
                            + c*cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + t0
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_octo_para_func {d:[1, 1, 1], a:4, b:1, c:-2.8, t0:1.5},
        call : tpms_octo_para_func,
    };

/*
Catalog section:    2.9
Catalog name:       FRD
Catalog equation:   21
Congruent:          No
t_endo_crit =       -10.00
t_exo_crit =        6.000
t_endo_pinch =      -1.851
t_exo_pinch =       1.999
VF_endo_pinch =     23.27
VF_exo_pinch =      25.84
*/
tpms_frd =
    let tpms_frd_func {d} =
        make_shape {
            dist[x,y,z,_] = 8*cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            - (cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(2*tau/d.[Z]*z)*cos(2*tau/d.[X]*x))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_frd_func {d:[1, 1, 1]},
        call : tpms_frd_func,
    };

/*
Catalog section:    2.10
Catalog name:       S
Catalog equation:   23
Congruent:          Yes
t_crit =            +/-1.414
t_pinch =           +/-0.794
VF_skel_pinch =     11.48%
*/
tpms_s =
    let tpms_s_func {d} =
        make_shape {
            dist[x,y,z,_] = cos(2*tau/d.[X]*x)*sin(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*cos(2*tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_s_func {d:[1, 1, 1]},
        call : tpms_s_func,
    };

/*
Catalog section:    2.11
Catalog name:       P+C(P)
Catalog equation:   24
Congruent:          No
t_endo_crit =       -0.415
t_exo_crit =        1.750
t_endo_pinch =      -0.134
t_exo_pinch =       0.174
VF_endo_pinch =     41.29
VF_exo_pinch =      21.74
*/
tpms_p_plus_c_p =
    let tpms_p_plus_c_p_func {d} =
        make_shape {
            dist[x,y,z,_] = 0.3*cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + 0.2*(cos(tau/d.[X]*x) + cos(tau/d.[Y]*y) + cos(tau/d.[Z]*z))
                            + 0.1*cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + 0.1*(cos(2*tau/d.[X]*x) + cos(2*tau/d.[Y]*y) + cos(2*tau/d.[Z]*z))
                            + 0.05*cos(3*tau/d.[X]*x)*cos(3*tau/d.[Y]*y)*cos(3*tau/d.[Z]*z)
                            + 0.1*(cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*cos(tau/d.[X]*x))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_p_plus_c_p_func {d:[1, 1, 1]},
        call : tpms_p_plus_c_p_func,
    };

/*
Catalog section:    2.12
Catalog name:       Split-P
Catalog equation:   25
Congruent:          No
t_endo_crit =       -1.800
t_exo_crit =        1.810
t_endo_pinch =      -0.969
t_exo_pinch =       0.599
t_exo_pinch2 =      1.370
VF_endo_pinch =     14.15
VF_exo_pinch =      27.58
VF_exo_pinch2 =     5.367
*/
tpms_split_p =
    let tpms_split_p_func {d} =
        make_shape {
            dist[x,y,z,_] = 1.1*(sin(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)*sin(tau/d.[X]*x)
                            + sin(2*tau/d.[Z]*z)*cos(tau/d.[X]*x)*sin(tau/d.[Y]*y))
                            - 0.2*(cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(2*tau/d.[Z]*z)*cos(2*tau/d.[X]*x))
                            - 0.4*(cos(2*tau/d.[X]*x) + cos(2*tau/d.[Y]*y) + cos(2*tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_split_p_func {d:[1, 1, 1]},
        call : tpms_split_p_func,
    };

/*
Catalog section:    2.13
Catalog name:       F
Catalog equation:   26
Congruent:          Yes
t_crit =            +/-1.000
t_pinch =           +/-0.000
VF_skel_pinch =     50.00%
*/
tpms_f =
    let tpms_f_func {d} =
        make_shape {
            dist[x,y,z,_] = cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_f_func {d:[1, 1, 1]},
        call : tpms_f_func,
    };

/*
Catalog section:    2.14
Catalog name:       C(D)
Catalog equation:   27
Congruent:          Yes
t_crit =            +/-4.250
t_pinch =           +/-0.158
t_pinch2 =          +/-0.272
VF_skel_pinch =     41.22%
VF_skel_pinch2 =    24.45
*/
tpms_c_d =
    let tpms_c_d_func {d} =
        make_shape {
            dist[x,y,z,_] = cos(3*tau/d.[X]*x+tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            - sin(3*tau/d.[X]*x-tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x+3*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x-3*tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x-tau/d.[Y]*y)*cos(3*tau/d.[Z]*z)
                            - sin(tau/d.[X]*x+tau/d.[Y]*y)*sin(3*tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_c_d_func {d:[1, 1, 1]},
        call : tpms_c_d_func,
    };

// Catalog Section: 2.15 G'
/*
Catalog section:    2.15
Catalog name:       G'
Catalog equation:   29
Congruent:          No
t_endo_crit =       -0.680
t_exo_crit =        1.820
t_endo_pinch =      -0.494
t_exo_pinch =       0.319
t_exo_pinch2 =      1.319
VF_endo_pinch =     5.896
VF_exo_pinch =      45.03
VF_exo_pinch2 =     7.213
*/
tpms_g_prime =
    let tpms_g_prime_func {d} =
        make_shape {
            dist[x,y,z,_] = sin(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(2*tau/d.[Z]*z)
                            + 0.32
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_g_prime_func {d:[1, 1, 1]},
        call : tpms_g_prime_func,
    };

/*
Catalog section:    2.16
Catalog name:       G'2
Catalog equation:   30
Congruent:          No
t_endo_crit =       -5.999
t_exo_crit =        7.499
t_endo_pinch =      -4.429
t_exo_pinch =       2.999
t_exo_pinch2 =      3.999
VF_endo_pinch =     7.400
VF_exo_pinch =      20.55
VF_exo_pinch2 =     12.18
*/
tpms_g_prime_2 =
    let tpms_g_prime_2_func {d} =
        make_shape {
            dist[x,y,z,_] = 5*(sin(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(2*tau/d.[Z]*z))
                            + (cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(2*tau/d.[Z]*z)*cos(2*tau/d.[X]*x))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_g_prime_2_func {d:[1, 1, 1]},
        call : tpms_g_prime_2_func,
    };

/*
Catalog section:    2.17
Catalog name:       D'
Catalog equation:   31
Congruent:          No
t_endo_crit =       -2.406
t_exo_crit =        0.425
t_endo_pinch2 =     -0.699
t_endo_pinch =      -0.106
t_exo_pinch =       0.362
VF_endo_pinch2 =    15.43
VF_endo_pinch =     44.52
VF_exo_pinch =      7.739
*/
tpms_d_prime =
    let tpms_d_prime_func {d} =
        make_shape {
            dist[x,y,z,_] = 0.5*(cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(tau/d.[Y]*y)*cos(tau/d.[Z]*z))
                            - 0.5*(sin(2*tau/d.[X]*x)*sin(2*tau/d.[Y]*y)
                            + sin(2*tau/d.[Y]*y)*sin(2*tau/d.[Z]*z)
                            + sin(2*tau/d.[Z]*z)*sin(2*tau/d.[X]*x))
                            - 0.2
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_d_prime_func {d:[1, 1, 1]},
        call : tpms_d_prime_func,
    };

/*
Catalog section:    2.18
Catalog name:       K
Catalog equation:   32
Congruent:          No
t_endo_crit =       -1.600
t_exo_crit =        1.535
t_endo_pinch =      -0.471
t_exo_pinch =       0.299
VF_endo_pinch =     16.39
VF_exo_pinch =      43.14
*/
tpms_k =
    let tpms_k_func {d} =
        make_shape {
            dist[x,y,z,_] = 0.3*(cos(tau/d.[X]*x) + cos(tau/d.[Y]*y) + cos(tau/d.[Z]*z))
                            + 0.3*(cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*cos(tau/d.[X]*x))
                            -0.4*(cos(2*tau/d.[X]*x)
                            + cos(2*tau/d.[Y]*y) + cos(2*tau/d.[Z]*z))
                            + 0.2
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_k_func {d:[1, 1, 1]},
        call : tpms_k_func,
    };

/*
Catalog section:    2.19
Catalog name:       C(S)
Catalog equation:   34
Congruent:          Yes
t_crit =            +/-6.455
t_pinch =           +/-1.407
VF_skel_pinch =     23.34%
*/
tpms_c_s =
    let tpms_c_s_func {d} =
        make_shape {
            dist[x,y,z,_] = (cos(2*tau/d.[X]*x) + cos(2*tau/d.[Y]*y) + cos(2*tau/d.[Z]*z))
                            + 2*(sin(3*tau/d.[X]*x)*sin(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(3*tau/d.[Y]*y)*sin(2*tau/d.[Z]*z)
                            + sin(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(3*tau/d.[Z]*z))
                            + 2*(sin(2*tau/d.[X]*x)*cos(3*tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Y]*y)*cos(3*tau/d.[Z]*z)
                            + cos(3*tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(2*tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_c_s_func {d:[1, 1, 1]},
        call : tpms_c_s_func,
    };

/*
Catalog section:    2.20
Catalog name:       Y
Catalog equation:   35
Congruent:          Yes
t_crit =            +/-4.950
t_pinch =           +/-0.451
VF_skel_pinch =     25.80%
*/
tpms_y =
    let tpms_y_func {d} =
        make_shape {
            dist[x,y,z,_] = cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + (sin(2*tau/d.[X]*x)*sin(tau/d.[Y]*y)
                            + sin(2*tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Z]*z))
                            + (cos(tau/d.[X]*x)*sin(2*tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*sin(2*tau/d.[Z]*z)
                            + sin(2*tau/d.[X]*x)*cos(tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_y_func {d:[1, 1, 1]},
        call : tpms_y_func,
    };

/*
Catalog section:    2.21
Catalog name:       +/-Y
Catalog equation:   36
Congruent:          Yes
t_crit =            +/-2.828
t_pinch =           +/-0.378
VF_skel_pinch =     34.38%
*/
tpms_pm_y =
    let tpms_pm_y_func {d} =
        make_shape {
            dist[x,y,z,_] = 2*cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + (sin(2*tau/d.[X]*x)*sin(tau/d.[Y]*y)
                            + sin(2*tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_pm_y_func {d:[1, 1, 1]},
        call : tpms_pm_y_func,
    };

/*
Catalog section:    2.22
Catalog name:       C(+/-Y)
Catalog equation:   37
Congruent:          Yes
t_crit =            +/-2.000
t_pinch =           +/-1.653
VF_skel_pinch =     6.342%
*/
tpms_c_pm_y =
    let tpms_c_pm_y_func {d} =
        make_shape {
            dist[x,y,z,_] = -2*cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + (sin(2*tau/d.[X]*x)*sin(tau/d.[Y]*y)
                            + sin(2*tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_c_pm_y_func {d:[1, 1, 1]},
        call : tpms_c_pm_y_func,
    };

/*
Catalog section:    2.23
Catalog name:       C(I2-Y**)
Catalog equation:   38
Congruent:          No
t_endo_crit =       -3.000
t_exo_crit =        3.000
t_endo_pinch =      -2.062
t_exo_pinch =       0.999
VF_endo_pinch =     8.384
VF_exo_pinch =      27.79
*/
tpms_c_i2_ystarstar =
    let tpms_c_i2_ystarstar_func {d} =
        make_shape {
            dist[x,y,z,_] = 2*(sin(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)*sin(tau/d.[Z]*z)
                            + sin(tau/d.[X]*x)*sin(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(tau/d.[Y]*y)*sin(2*tau/d.[Z]*z))
                            + (cos(2*tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(2*tau/d.[X]*x)*cos(2*tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_c_i2_ystarstar_func {d:[1, 1, 1]},
        call : tpms_c_i2_ystarstar_func,
    };

/*
Catalog section:    2.24
Catalog name:       W
Catalog equation:   39
Congruent:          Yes
t_crit =            +/-4.000
t_pinch =           +/-0.000
VF_skel_pinch =     50.00%
Comments: lots of trapped volumes
*/
tpms_w =
    let tpms_w_func {d} =
        make_shape {
            dist[x,y,z,_] = (cos(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*cos(2*tau/d.[Z]*z))
                            - (cos(tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(2*tau/d.[X]*x)*cos(tau/d.[Z]*z))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_w_func {d:[1, 1, 1]},
        call : tpms_w_func,
    };

/*
Catalog section:    2.25
Catalog name:       Q*
Catalog equation:   40
Congruent:          Yes
t_crit =            +/-4.000
t_pinch =           +/-2.249
VF_skel_pinch =     10.79%
*/
tpms_qstar =
    let tpms_qstar_func {d} =
        make_shape {
            dist[x,y,z,_] = (cos(tau/d.[X]*x)-2*cos(tau/d.[Y]*y))*cos(tau/d.[Z]*z)
                            - sqrt(3)*sin(tau/d.[Z]*z)*(cos(tau/d.[X]*x-tau/d.[Y]*y)
                            - cos(tau/d.[X]*x))
                            + cos(tau/d.[X]*x-tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_qstar_func {d:[1, 1, 1]},
        call : tpms_qstar_func,
    };

/*
Catalog section:    2.26
Catalog name:       C(G)
Catalog equation:   41
Congruent:          Yes
t_crit =            +/-10.500
t_pinch =           +/-3.419
t_pinch2 =          +/-4.242
VF_skel_pinch =     15.84%
VF_skel_pinch2 =    9.979
*/
tpms_c_g =
    let tpms_c_g_func {d} =
        make_shape {
            dist[x,y,z,_] = 3*(sin(tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + sin(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*sin(tau/d.[Z]*z))
                            + 2*(sin(3*tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + sin(3*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + sin(3*tau/d.[Z]*z)*cos(tau/d.[X]*x))
                            - 2*(sin(tau/d.[X]*x)*cos(3*tau/d.[Y]*y)
                            + sin(tau/d.[Y]*y)*cos(3*tau/d.[Z]*z)
                            + sin(tau/d.[Z]*z)*cos(3*tau/d.[X]*x))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_c_g_func {d:[1, 1, 1]},
        call : tpms_c_g_func,
    };

/*
Catalog section:    2.27
Catalog name:       Slotted-P
Catalog equation:   42
Congruent:          No
t_endo_crit =       -12.00
t_exo_crit =        6.000
t_endo_pinch =      -2.999
t_exo_pinch =       3.999
VF_endo_pinch =     16.82
VF_exo_pinch =      8.209
*/
tpms_slotted_p =
    let tpms_slotted_p_func {d} =
        make_shape {
            dist[x,y,z,_] = -2*(cos(tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(tau/d.[X]*x)*cos(tau/d.[Z]*z))
                            - 2*(cos(2*tau/d.[X]*x) + cos(2*tau/d.[Y]*y) + cos(2*tau/d.[Z]*z))
                            + (cos(2*tau/d.[X]*x)*cos(tau/d.[Y]*y)
                            + cos(2*tau/d.[Y]*y)*cos(tau/d.[Z]*z)
                            + cos(2*tau/d.[Z]*z)*cos(tau/d.[X]*x))
                            - (cos(tau/d.[X]*x)*cos(2*tau/d.[Y]*y)
                            + cos(tau/d.[Y]*y)*cos(2*tau/d.[Z]*z)
                            + cos(tau/d.[Z]*z)*cos(2*tau/d.[X]*x))
                            ;
            is_3d = true;
        };
    in make_shape {
        ... tpms_slotted_p_func {d:[1, 1, 1]},
        call : tpms_slotted_p_func,
    };


/*
sin(tau/d.[X]*x) sin(2*tau/d.[X]*x)
sin(tau/d.[Y]*y) sin(2*tau/d.[Y]*y)
sin(tau/d.[Z]*z) sin(2*tau/d.[Z]*z)
cos(tau/d.[X]*x) cos(2*tau/d.[X]*x)
cos(tau/d.[Y]*y) cos(2*tau/d.[Y]*y)
cos(tau/d.[Z]*z) cos(2*tau/d.[Z]*z)
*/

} // End record
