/// Reads the faces from the OFF file and gets the edges and faces from
/// them. Since the OFF file doesn't store edges explicitly, this is harder
/// than reading general elements.
Reads the faces from the OFF file and gets the edges and faces from
them. Since the OFF file doesn't store edges explicitly, this is harder
than reading general elements.
Reads the faces from the OFF file and gets the edges and faces from them . Since the OFF file doesn ' t store edges explicitly this is harder than reading general elements .
fn parse_edges_and_faces(
        &mut self,
        rank: usize,
        num_edges: usize,
        num_faces: usize,
    ) -> OffParseResult<(SubelementList, SubelementList)> {
        let mut edges = SubelementList::with_capacity(num_edges);
        let mut faces = SubelementList::with_capacity(num_faces);
        let mut hash_edges = HashMap::new();
        // Add each face to the element list.
        for _ in 0..num_faces {
            let face_sub_num = self.iter.parse_next()?;
            let mut face = Subelements::new();
            let mut face_verts = Vec::with_capacity(face_sub_num + 1);
            // Reads all vertices of the face.
            for _ in 0..face_sub_num {
                face_verts.push(self.iter.parse_next()?);
            }
            // We add the first vertex to the end for simplicity.
            face_verts.push(face_verts[0]);
            // Gets all edges of the face.
            for i in 0..face_sub_num {
                let mut v0 = face_verts[i];
                let mut v1 = face_verts[i + 1];
                if v0 > v1 {
                    std::mem::swap(&mut v0, &mut v1);
                }
                let edge: Subelements = vec![v0, v1].into();
                if let Some(idx) = hash_edges.get(&edge) {
                    face.push(*idx);
                } else {
                    hash_edges.insert(edge.clone(), edges.len());
                    face.push(edges.len());
                    edges.push(edge);
                }
            }
            // If these are truly faces and not just components, we add them.
            // Hopefully the compiler can optimize this better, I'm lazy.
            if rank != 3 {
                faces.push(face);
            }
        }
        // If this is a polygon, we add a single maximal element as a face.
        if rank == 3 {
            faces = SubelementList::max(edges.len());
        }
        // The number of edges in the file should match the number of read
        // edges, though this isn't obligatory.
        if edges.len() != num_edges {
            println!("WARNING: Edge count doesn't match expected edge count!");
        }
        Ok((edges, faces))
    }
fn parse_edges_and_faces ( & mut self , rank : usize , num_edges : usize , num_faces : usize , ) -> OffParseResult < ( SubelementList , SubelementList ) > { let mut edges = SubelementList :: with_capacity ( num_edges ) ; let mut faces = SubelementList :: with_capacity ( num_faces ) ; let mut hash_edges = HashMap :: new ( ) ; // Add each face to the element list. for _ in 0 .. num_faces { let face_sub_num = self . iter . parse_next ( ) ? ; let mut face = Subelements :: new ( ) ; let mut face_verts = Vec :: with_capacity ( face_sub_num + 1 ) ; // Reads all vertices of the face. for _ in 0 .. face_sub_num { face_verts . push ( self . iter . parse_next ( ) ? ) ; } // We add the first vertex to the end for simplicity. face_verts . push ( face_verts [ 0 ] ) ; // Gets all edges of the face. for i in 0 .. face_sub_num { let mut v0 = face_verts [ i ] ; let mut v1 = face_verts [ i + 1 ] ; if v0 > v1 { std :: mem :: swap ( & mut v0 , & mut v1 ) ; } let edge : Subelements = vec ! [ v0 v1 ] . into ( ) ; if let Some ( idx ) = hash_edges . get ( & edge ) { face . push ( * idx ) ; } else { hash_edges . insert ( edge . clone ( ) , edges . len ( ) ) ; face . push ( edges . len ( ) ) ; edges . push ( edge ) ; } } // If these are truly faces and not just components, we add them. // Hopefully the compiler can optimize this better, I'm lazy. if rank != 3 { faces . push ( face ) ; } } // If this is a polygon, we add a single maximal element as a face. if rank == 3 { faces = SubelementList :: max ( edges . len ( ) ) ; } // The number of edges in the file should match the number of read // edges, though this isn't obligatory. if edges . len ( ) != num_edges { println ! ( " " ) ; } Ok ( ( edges , faces ) ) }
Reads the faces from the OFF file and gets the edges and faces from
them.
Reads the faces from the OFF file and gets the edges and faces from them .
&mut self
rank
usize
num_edges
usize
num_faces
usize