pub fn join_meshes(a: &Mesh, b: &Mesh) -> Result<Mesh, StrError> {
    // check
    if a.ndim != b.ndim {
        return Err("meshes must have the same ndim");
    }

    // find the boundary of mesh A
    let (_, _, boundary_a) = Features::new(a, Extract::Boundary);

    // allocate and prepare a GridSearch for mesh A
    let mut grid_a = GridSearch::new(&boundary_a.min, &boundary_a.max, 0.01, GsNdiv::Default, GsTol::Default)?;
    for m in 0..a.points.len() {
        grid_a.insert(a.points[m].id, &a.points[m].coords)?;
    }

    // create a new mesh with all mesh A data
    let mut mesh = a.clone();

    // renumber the points of mesh B and add them to the new mesh (if not present yet)
    let mut new_point_id = a.points.len();
    let mut map_old_to_new_point_id_b = vec![0; b.points.len()];
    for m in 0..b.points.len() {
        let x = &b.points[m].coords;
        let maybe_point_id_a = if grid_a.is_outside(x) { None } else { grid_a.find(x)? };
        let id = match maybe_point_id_a {
            Some(point_id_a) => point_id_a,
            None => {
                mesh.points.push(Point {
                    id: new_point_id,
                    coords: x.clone(),
                });
                new_point_id += 1;
                new_point_id - 1
            }
        };
        map_old_to_new_point_id_b[m] = id;
    }

    // insert cells of mesh B into new mesh
    let mut new_cell_id = a.cells.len();
    for cell in &b.cells {
        mesh.cells.push(Cell {
            id: new_cell_id,
            attribute_id: cell.attribute_id,
            kind: cell.kind,
            points: cell.points.iter().map(|id| map_old_to_new_point_id_b[*id]).collect(),
        });
        new_cell_id += 1;
    }
    Ok(mesh)
}
/// Joins two meshes by comparing the coordinates on the boundary of the first mesh
///
/// **Note:** The meshes must have the same space_ndim.
///
/// **Important:** This function does not guarantee the "mesh compatibility" requirements
/// for finite element analyses.
Joins two meshes by comparing the coordinates on the boundary of the first mesh
Note:** The meshes must have the same space_ndim.

This function does not guarantee the "mesh compatibility" requirements
for finite element analyses.
Joins two meshes by comparing the coordinates on the boundary of the first mesh Note : ** The meshes must have the same space_ndim . This function does not guarantee the " mesh compatibility " requirements for finite element analyses .
pub fn join_meshes(a: &Mesh, b: &Mesh) -> Result<Mesh, StrError> {
    // check
    if a.ndim != b.ndim {
        return Err("meshes must have the same ndim");
    }
    // find the boundary of mesh A
    let (_, _, boundary_a) = Features::new(a, Extract::Boundary);
    // allocate and prepare a GridSearch for mesh A
    let mut grid_a = GridSearch::new(&boundary_a.min, &boundary_a.max, 0.01, GsNdiv::Default, GsTol::Default)?;
    for m in 0..a.points.len() {
        grid_a.insert(a.points[m].id, &a.points[m].coords)?;
    }
    // create a new mesh with all mesh A data
    let mut mesh = a.clone();
    // renumber the points of mesh B and add them to the new mesh (if not present yet)
    let mut new_point_id = a.points.len();
    let mut map_old_to_new_point_id_b = vec![0; b.points.len()];
    for m in 0..b.points.len() {
        let x = &b.points[m].coords;
        let maybe_point_id_a = if grid_a.is_outside(x) { None } else { grid_a.find(x)? };
        let id = match maybe_point_id_a {
            Some(point_id_a) => point_id_a,
            None => {
                mesh.points.push(Point {
                    id: new_point_id,
                    coords: x.clone(),
                });
                new_point_id += 1;
                new_point_id - 1
            }
        };
        map_old_to_new_point_id_b[m] = id;
    }
    // insert cells of mesh B into new mesh
    let mut new_cell_id = a.cells.len();
    for cell in &b.cells {
        mesh.cells.push(Cell {
            id: new_cell_id,
            attribute_id: cell.attribute_id,
            kind: cell.kind,
            points: cell.points.iter().map(|id| map_old_to_new_point_id_b[*id]).collect(),
        });
        new_cell_id += 1;
    }
    Ok(mesh)
}
pub fn join_meshes ( a : & Mesh , b : & Mesh ) -> Result < Mesh , StrError > { // check if a . ndim != b . ndim { return Err ( " " ) ; } // find the boundary of mesh A let ( _ , _ , boundary_a ) = Features :: new ( a , Extract :: Boundary ) ; // allocate and prepare a GridSearch for mesh A let mut grid_a = GridSearch :: new ( & boundary_a . min , & boundary_a . max , 0.01 , GsNdiv :: Default , GsTol :: Default ) ? ; for m in 0 .. a . points . len ( ) { grid_a . insert ( a . points [ m ] . id , & a . points [ m ] . coords ) ? ; } // create a new mesh with all mesh A data let mut mesh = a . clone ( ) ; // renumber the points of mesh B and add them to the new mesh (if not present yet) let mut new_point_id = a . points . len ( ) ; let mut map_old_to_new_point_id_b = vec ! [ 0 b points len ( ) ] ; for m in 0 .. b . points . len ( ) { let x = & b . points [ m ] . coords ; let maybe_point_id_a = if grid_a . is_outside ( x ) { None } else { grid_a . find ( x ) ? } ; let id = match maybe_point_id_a { Some ( point_id_a ) => point_id_a , None => { mesh . points . push ( Point { id : new_point_id , coords : x . clone ( ) , } ) ; new_point_id += 1 ; new_point_id - 1 } } ; map_old_to_new_point_id_b [ m ] = id ; } // insert cells of mesh B into new mesh let mut new_cell_id = a . cells . len ( ) ; for cell in & b . cells { mesh . cells . push ( Cell { id : new_cell_id , attribute_id : cell . attribute_id , kind : cell . kind , points : cell . points . iter ( ) . map ( | id | map_old_to_new_point_id_b [ * id ] ) . collect ( ) , } ) ; new_cell_id += 1 ; } Ok ( mesh ) }
Joins two meshes by comparing the coordinates on the boundary of the first mesh
Note:** The meshes must have the same space_ndim.
Joins two meshes by comparing the coordinates on the boundary of the first mesh Note : ** The meshes must have the same space_ndim .
a
&Mesh
b
&Mesh
a
&Mesh
b
&Mesh