fn element_types(&self) -> Vec<Vec<ElementType>> {
        use std::collections::hash_map::Entry;

        let rank = self.rank();
        let mut output;
        if let Some(rank_usize) = rank.try_usize() {
            output = Vec::with_capacity(rank_usize);
        } else {
            return Vec::new();
        }

        // There's only one point type, for now.
        output.push(vec![ElementType {
            indices: (0..self.vertex_count()).collect(),
            data: ElementData::Point,
        }]);

        if rank == Rank::new(0) {
            return output;
        }

        // Gets the edge lengths of all edges in the polytope.
        let mut edge_lengths: BTreeMap<FloatOrd, Vec<usize>> = BTreeMap::new();
        let edge_count = self.el_count(Rank::new(1));

        for edge_idx in 0..edge_count {
            let len = FloatOrd::from(self.edge_len(edge_idx).unwrap());

            // Searches for the greatest length smaller than the current one.
            if let Some((prev_len, indices)) = edge_lengths.range_mut(..len).next_back() {
                if abs_diff_eq!(prev_len.0, len.0, epsilon = Float::EPS) {
                    indices.push(edge_idx);
                    continue;
                }
            }

            // Searches for the smallest length greater than the current one.
            if let Some((next_len, indices)) = edge_lengths.range_mut(len..).next() {
                if abs_diff_eq!(next_len.0, len.0, epsilon = Float::EPS) {
                    indices.push(edge_idx);
                    continue;
                }
            }

            edge_lengths.insert(len, vec![edge_idx]);
        }

        // Creates a map from edge indices to indices of types.
        let mut prev_types = Vec::new();
        let mut edge_types = Vec::new();
        prev_types.resize(edge_count, 0);
        for (type_index, (len, indices)) in edge_lengths.into_iter().enumerate() {
            for &idx in &indices {
                prev_types[idx] = type_index;
            }
            edge_types.push(ElementType {
                indices,
                data: ElementData::Edge(len),
            })
        }
        output.push(edge_types);

        for elements in self.iter().take(self.rank()).skip(3) {
            // A map from element data to the indices of the elements with such data.
            let mut types = HashMap::new();

            // We build the map.
            for (idx, el) in elements.iter().enumerate() {
                let mut element_count_builder = ElementCountBuilder::new();
                for &sub in &el.subs {
                    element_count_builder.insert(prev_types[sub]);
                }
                let data = element_count_builder.build();

                match types.entry(data) {
                    Entry::Vacant(entry) => {
                        entry.insert(vec![idx]);
                    }
                    Entry::Occupied(mut entry) => {
                        entry.get_mut().push(idx);
                    }
                }
            }

            // We create the element types from the map.
            let mut element_types = Vec::with_capacity(types.len());
            prev_types = Vec::new(); // This can probably be taken out.
            prev_types.resize(elements.len(), 0);
            for (type_index, (data, indices)) in types.into_iter().enumerate() {
                for &idx in &indices {
                    prev_types[idx] = type_index;
                }
                element_types.push(ElementType { indices, data });
            }

            output.push(element_types);
        }

        output
    }
/// Gets the element "types" of a polytope.
Gets the element "types" of a polytope.
Gets the element " types " of a polytope .
fn element_types(&self) -> Vec<Vec<ElementType>> {
        use std::collections::hash_map::Entry;
        let rank = self.rank();
        let mut output;
        if let Some(rank_usize) = rank.try_usize() {
            output = Vec::with_capacity(rank_usize);
        } else {
            return Vec::new();
        }
        // There's only one point type, for now.
        output.push(vec![ElementType {
            indices: (0..self.vertex_count()).collect(),
            data: ElementData::Point,
        }]);
        if rank == Rank::new(0) {
            return output;
        }
        // Gets the edge lengths of all edges in the polytope.
        let mut edge_lengths: BTreeMap<FloatOrd, Vec<usize>> = BTreeMap::new();
        let edge_count = self.el_count(Rank::new(1));
        for edge_idx in 0..edge_count {
            let len = FloatOrd::from(self.edge_len(edge_idx).unwrap());
            // Searches for the greatest length smaller than the current one.
            if let Some((prev_len, indices)) = edge_lengths.range_mut(..len).next_back() {
                if abs_diff_eq!(prev_len.0, len.0, epsilon = Float::EPS) {
                    indices.push(edge_idx);
                    continue;
                }
            }
            // Searches for the smallest length greater than the current one.
            if let Some((next_len, indices)) = edge_lengths.range_mut(len..).next() {
                if abs_diff_eq!(next_len.0, len.0, epsilon = Float::EPS) {
                    indices.push(edge_idx);
                    continue;
                }
            }
            edge_lengths.insert(len, vec![edge_idx]);
        }
        // Creates a map from edge indices to indices of types.
        let mut prev_types = Vec::new();
        let mut edge_types = Vec::new();
        prev_types.resize(edge_count, 0);
        for (type_index, (len, indices)) in edge_lengths.into_iter().enumerate() {
            for &idx in &indices {
                prev_types[idx] = type_index;
            }
            edge_types.push(ElementType {
                indices,
                data: ElementData::Edge(len),
            })
        }
        output.push(edge_types);
        for elements in self.iter().take(self.rank()).skip(3) {
            // A map from element data to the indices of the elements with such data.
            let mut types = HashMap::new();
            // We build the map.
            for (idx, el) in elements.iter().enumerate() {
                let mut element_count_builder = ElementCountBuilder::new();
                for &sub in &el.subs {
                    element_count_builder.insert(prev_types[sub]);
                }
                let data = element_count_builder.build();
                match types.entry(data) {
                    Entry::Vacant(entry) => {
                        entry.insert(vec![idx]);
                    }
                    Entry::Occupied(mut entry) => {
                        entry.get_mut().push(idx);
                    }
                }
            }
            // We create the element types from the map.
            let mut element_types = Vec::with_capacity(types.len());
            prev_types = Vec::new(); // This can probably be taken out.
            prev_types.resize(elements.len(), 0);
            for (type_index, (data, indices)) in types.into_iter().enumerate() {
                for &idx in &indices {
                    prev_types[idx] = type_index;
                }
                element_types.push(ElementType { indices, data });
            }
            output.push(element_types);
        }
        output
    }
fn element_types ( & self ) -> Vec < Vec < ElementType > > { use std :: collections :: hash_map :: Entry ; let rank = self . rank ( ) ; let mut output ; if let Some ( rank_usize ) = rank . try_usize ( ) { output = Vec :: with_capacity ( rank_usize ) ; } else { return Vec :: new ( ) ; } // There's only one point type, for now. output . push ( vec ! [ ElementType { indices ( 0 self vertex_count ( ) ) collect ( ) data ElementData Point } ] ) ; if rank == Rank :: new ( 0 ) { return output ; } // Gets the edge lengths of all edges in the polytope. let mut edge_lengths : BTreeMap < FloatOrd , Vec < usize > > = BTreeMap :: new ( ) ; let edge_count = self . el_count ( Rank :: new ( 1 ) ) ; for edge_idx in 0 .. edge_count { let len = FloatOrd :: from ( self . edge_len ( edge_idx ) . unwrap ( ) ) ; // Searches for the greatest length smaller than the current one. if let Some ( ( prev_len , indices ) ) = edge_lengths . range_mut ( .. len ) . next_back ( ) { if abs_diff_eq ! ( prev_len 0 len 0 epsilon Float EPS ) { indices . push ( edge_idx ) ; continue ; } } // Searches for the smallest length greater than the current one. if let Some ( ( next_len , indices ) ) = edge_lengths . range_mut ( len .. ) . next ( ) { if abs_diff_eq ! ( next_len 0 len 0 epsilon Float EPS ) { indices . push ( edge_idx ) ; continue ; } } edge_lengths . insert ( len , vec ! [ edge_idx ] ) ; } // Creates a map from edge indices to indices of types. let mut prev_types = Vec :: new ( ) ; let mut edge_types = Vec :: new ( ) ; prev_types . resize ( edge_count , 0 ) ; for ( type_index , ( len , indices ) ) in edge_lengths . into_iter ( ) . enumerate ( ) { for & idx in & indices { prev_types [ idx ] = type_index ; } edge_types . push ( ElementType { indices , data : ElementData :: Edge ( len ) , } ) } output . push ( edge_types ) ; for elements in self . iter ( ) . take ( self . rank ( ) ) . skip ( 3 ) { // A map from element data to the indices of the elements with such data. let mut types = HashMap :: new ( ) ; // We build the map. for ( idx , el ) in elements . iter ( ) . enumerate ( ) { let mut element_count_builder = ElementCountBuilder :: new ( ) ; for & sub in & el . subs { element_count_builder . insert ( prev_types [ sub ] ) ; } let data = element_count_builder . build ( ) ; match types . entry ( data ) { Entry :: Vacant ( entry ) => { entry . insert ( vec ! [ idx ] ) ; } Entry :: Occupied ( mut entry ) => { entry . get_mut ( ) . push ( idx ) ; } } } // We create the element types from the map. let mut element_types = Vec :: with_capacity ( types . len ( ) ) ; prev_types = Vec :: new ( ) ; // This can probably be taken out. prev_types . resize ( elements . len ( ) , 0 ) ; for ( type_index , ( data , indices ) ) in types . into_iter ( ) . enumerate ( ) { for & idx in & indices { prev_types [ idx ] = type_index ; } element_types . push ( ElementType { indices , data } ) ; } output . push ( element_types ) ; } output }
Gets the element "types" of a polytope.
Gets the element " types " of a polytope .
&self
&self