<commit_before>use super::{join_meshes, ArgsRing, Block, Constraint2D, Mesh};
use crate::shapes::GeoKind;
use crate::util::{PI, SQRT_2};
use crate::StrError;

/// Groups generators of structured meshes (Qua and Hex -- sometimes Tri)
pub struct Structured {}

/// TODO Groups generators of unstructured meshes (Tri and Tet only)
pub struct Unstructured {}

impl Structured {
    /// Generates a mesh representing a quarter of a ring in 2D
    ///
    /// ```text
    /// y ^
    ///   |
    ///   ***=---__
    ///   |        '*._
    ///   |            *._
    ///   |               *.
    ///   ***=-__           *.
    ///   |      '-.          *
    ///   |         *.         *
    ///   |           *         *
    ///   |            *         *
    ///   |             *         *
    ///   |             #         #
    ///   o ----------- # ------- # --> x
    ///               rmin       rmax
    /// ```
    ///
    /// # Input
    ///
    /// * `rmin` -- inner radius
    /// * `rmax` -- outer radius
    /// * `nr` -- number of divisions along the radius (must be > 0)
    /// * `na` -- number of divisions along alpha (must be > 0)
    /// * `target` -- Qua shapes only
    pub fn quarter_ring_2d(rmin: f64, rmax: f64, nr: usize, na: usize, target: GeoKind) -> Result<Mesh, StrError> {
        let mut block = Block::new_square(1.0);
        block.set_ndiv(&[nr, na])?;
        block.set_transform_into_ring(Some(ArgsRing {
            amin: 0.0,
            amax: PI / 2.0,
            rmin,
            rmax,
            zmin: 0.0,
            zmax: 1.0,
        }))?;
        block.subdivide(target)
    }

    /// Generates a mesh representing a quarter of a ring in 3D (extruded along the z-direction)
    ///
    /// ```text
    /// y ^
    ///   |
    ///   ***=---__
    ///   |        '*._
    ///   |            *._
    ///   |               *.
    ///   ***=-__           *.
    ///   |      '-.          *
    ///   |         *.         *
    ///   |           *         *
    ///   |            *         *
    ///   |             *         *
    ///   |             #         #
    /// z o ----------- # ------- # --> x
    ///               rmin       rmax
    /// ```
    ///
    /// # Input
    ///
    /// * `rmin` -- inner radius
    /// * `rmax` -- outer radius
    /// * `zmin` -- min z
    /// * `zmax` -- max z
    /// * `nr` -- number of divisions along the radius (must be > 0)
    /// * `na` -- number of divisions along alpha (must be > 0)
    /// * `nz` -- number of divisions along z (must be > 0)
    /// * `target` -- Qua shapes only
    pub fn quarter_ring_3d(
        rmin: f64,
        rmax: f64,
        zmin: f64,
        zmax: f64,
        nr: usize,
        na: usize,
        nz: usize,
        target: GeoKind,
    ) -> Result<Mesh, StrError> {
        let mut block = Block::new_cube(1.0);
        block.set_ndiv(&[nr, na, nz])?;
        block.set_transform_into_ring(Some(ArgsRing {
            amin: 0.0,
            amax: PI / 2.0,
            rmin,
            rmax,
            zmin,
            zmax,
        }))?;
        block.subdivide(target)
    }

    /// Generates a mesh representing a quarter of a disk in 2D
    ///
    /// ```text
    /// y ^
    ///   |
    ///   ***=---__
    ///   |        '*._
    ///   |            *._
    ///   |               *.
    ///   |                 *.
    ///   |                   *
    ///   |                    *
    ///   |                     *
    ///   |                      *
    ///   |                       *
    ///   |                       #
    ///   o --------------------- # --> x
    ///                        radius
    /// ```
    ///
    /// # Input
    ///
    /// * `radius` -- the radius
    /// * `ndiv` -- number of divisions (must be > 0)
    /// * `target` -- Qua shapes only
    pub fn quarter_disk_2d(radius: f64, ndiv: usize, target: GeoKind) -> Result<Mesh, StrError> {
        let m = radius / 2.0;
        let n = radius / SQRT_2;
        let p = 1.15 * m / SQRT_2;
        let mut block_1 = Block::new(&[[0.0, 0.0], [m, 0.0], [p, p], [0.0, m]])?;
        let mut block_2 = Block::new(&[[m, 0.0], [radius, 0.0], [n, n], [p, p]])?;
        let mut block_3 = Block::new(&[[0.0, m], [p, p], [n, n], [0.0, radius]])?;
        block_1.set_ndiv(&[ndiv, ndiv])?;
        block_2.set_ndiv(&[ndiv, ndiv])?;
        block_3.set_ndiv(&[ndiv, ndiv])?;
        let ct = Constraint2D::Circle(0.0, 0.0, radius);
        block_2.set_edge_constraint(1, Some(ct.clone()))?;
        block_3.set_edge_constraint(2, Some(ct))?;
        let mesh_1 = block_1.subdivide(target)?;
        let mesh_2 = block_2.subdivide(target)?;
        let mesh_3 = block_3.subdivide(target)?;
        let mesh_1_2 = join_meshes(&mesh_1, &mesh_2)?;
        join_meshes(&mesh_1_2, &mesh_3)
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<commit_msg>Improve comments<commit_after>use super::{join_meshes, ArgsRing, Block, Constraint2D, Mesh};
use crate::shapes::GeoKind;
use crate::util::{PI, SQRT_2};
use crate::StrError;

/// Groups generators of structured meshes (Qua and Hex -- sometimes Tri)
pub struct Structured {}

/// TODO Groups generators of unstructured meshes (Tri and Tet only)
pub struct Unstructured {}

impl Structured {
    /// Generates a mesh representing a quarter of a ring in 2D
    ///
    /// ```text
    /// y ^
    ///   |
    ///   ***=---__
    ///   |        '*._
    ///   |            *._
    ///   |               *.
    ///   ***=-__           *.
    ///   |      '-.          *
    ///             *.         *
    ///   |           *         *
    ///                *         *
    ///   |             *         *
    ///                 #         #
    ///   o -   -   -   # ------- # --> x
    ///               rmin       rmax
    /// ```
    ///
    /// # Input
    ///
    /// * `rmin` -- inner radius
    /// * `rmax` -- outer radius
    /// * `nr` -- number of divisions along the radius (must be > 0)
    /// * `na` -- number of divisions along alpha (must be > 0)
    /// * `target` -- Qua shapes only
    pub fn quarter_ring_2d(rmin: f64, rmax: f64, nr: usize, na: usize, target: GeoKind) -> Result<Mesh, StrError> {
        let mut block = Block::new_square(1.0);
        block.set_ndiv(&[nr, na])?;
        block.set_transform_into_ring(Some(ArgsRing {
            amin: 0.0,
            amax: PI / 2.0,
            rmin,
            rmax,
            zmin: 0.0,
            zmax: 1.0,
        }))?;
        block.subdivide(target)
    }

    /// Generates a mesh representing a quarter of a ring in 3D (extruded along the z-direction)
    ///
    /// ```text
    /// y ^
    ///   |
    ///   ***=---__
    ///   |        '*._
    ///   |            *._
    ///   |               *.
    ///   ***=-__           *.
    ///   |      '-.          *
    ///             *.         *
    ///   |           *         *
    ///                *         *
    ///   |             *         *
    ///                 #         #
    /// z o -   -   -   # ------- # --> x
    ///               rmin       rmax
    /// ```
    ///
    /// # Input
    ///
    /// * `rmin` -- inner radius
    /// * `rmax` -- outer radius
    /// * `zmin` -- min z
    /// * `zmax` -- max z
    /// * `nr` -- number of divisions along the radius (must be > 0)
    /// * `na` -- number of divisions along alpha (must be > 0)
    /// * `nz` -- number of divisions along z (must be > 0)
    /// * `target` -- Qua shapes only
    pub fn quarter_ring_3d(
        rmin: f64,
        rmax: f64,
        zmin: f64,
        zmax: f64,
        nr: usize,
        na: usize,
        nz: usize,
        target: GeoKind,
    ) -> Result<Mesh, StrError> {
        let mut block = Block::new_cube(1.0);
        block.set_ndiv(&[nr, na, nz])?;
        block.set_transform_into_ring(Some(ArgsRing {
            amin: 0.0,
            amax: PI / 2.0,
            rmin,
            rmax,
            zmin,
            zmax,
        }))?;
        block.subdivide(target)
    }

    /// Generates a mesh representing a quarter of a disk in 2D
    ///
    /// ```text
    /// y ^
    ///   .
    ///   #**=---__
    ///   |        '*._
    ///   |            *._
    ///   |               *.
    ///   |                 *.
    ///   |                   *
    ///   |                    *
    ///   |                     *
    ///   |                      *
    ///   |                       *
    ///   |                       #
    ///   o-----------------------# --> x
    ///                        radius
    /// ```
    ///
    /// # Input
    ///
    /// * `radius` -- the radius
    /// * `ndiv` -- number of divisions (must be > 0)
    /// * `target` -- Qua shapes only
    pub fn quarter_disk_2d(radius: f64, ndiv: usize, target: GeoKind) -> Result<Mesh, StrError> {
        let m = radius / 2.0;
        let n = radius / SQRT_2;
        let p = 1.15 * m / SQRT_2;
        let mut block_1 = Block::new(&[[0.0, 0.0], [m, 0.0], [p, p], [0.0, m]])?;
        let mut block_2 = Block::new(&[[m, 0.0], [radius, 0.0], [n, n], [p, p]])?;
        let mut block_3 = Block::new(&[[0.0, m], [p, p], [n, n], [0.0, radius]])?;
        block_1.set_ndiv(&[ndiv, ndiv])?;
        block_2.set_ndiv(&[ndiv, ndiv])?;
        block_3.set_ndiv(&[ndiv, ndiv])?;
        let ct = Constraint2D::Circle(0.0, 0.0, radius);
        block_2.set_edge_constraint(1, Some(ct.clone()))?;
        block_3.set_edge_constraint(2, Some(ct))?;
        let mesh_1 = block_1.subdivide(target)?;
        let mesh_2 = block_2.subdivide(target)?;
        let mesh_3 = block_3.subdivide(target)?;
        let mesh_1_2 = join_meshes(&mesh_1, &mesh_2)?;
        join_meshes(&mesh_1_2, &mesh_3)
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{'fraction_non_alphanumeric': 0.21177424257776878, 'fraction_numerical': 0.019252203870706253, 'mean_word_length': 0.9402398270100255, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2322237', 'n_tokens_mistral': 3305, 'n_tokens_neox': 3229, 'n_words': 689}