fn show_views(
    ui: &mut Ui,
    mut query: Query<'_, '_, &mut Concrete>,
    mut section_state: ResMut<'_, SectionState>,
    mut section_direction: ResMut<'_, SectionDirection>,
) {
    // The cross-section settings.
    if let SectionState::Active {
        minmax,
        hyperplane_pos,
        flatten,
        lock,
        ..
    } = *section_state
    {
        ui.label("Cross section settings:");
        ui.spacing_mut().slider_width = ui.available_width() / 3.0;

        // Sets the slider range to the range of x coordinates in the polytope.
        let mut new_hyperplane_pos = hyperplane_pos;
        ui.add(
            egui::Slider::new(
                &mut new_hyperplane_pos,
                (minmax.0 + 0.0000001)..=(minmax.1 - 0.0000001), // We do this to avoid nullitopes.
            )
            .text("Slice depth")
            .prefix("pos: "),
        );

        // Updates the slicing depth.
        #[allow(clippy::float_cmp)]
        if hyperplane_pos != new_hyperplane_pos {
            if let SectionState::Active { hyperplane_pos, .. } = section_state.as_mut() {
                *hyperplane_pos = new_hyperplane_pos;
            } else {
                unreachable!()
            }
        }

        let mut new_direction = section_direction.0.clone();
        ui.add(UnitPointWidget::new(
            &mut new_direction,
            "Cross-section depth",
        ));

        // Updates the slicing direction.
        #[allow(clippy::float_cmp)]
        if section_direction.0 != new_direction {
            section_direction.0 = new_direction;
        }

        ui.horizontal(|ui| {
            // Makes the current cross-section into the main polytope.
            if ui.button("Make main").clicked() {
                section_state.close();
            }

            let mut new_flatten = flatten;
            ui.add(egui::Checkbox::new(&mut new_flatten, "Flatten"));

            // Updates the flattening setting.
            if flatten != new_flatten {
                if let SectionState::Active { flatten, .. } = section_state.as_mut() {
                    *flatten = new_flatten;
                } else {
                    unreachable!()
                }
            }

            let mut new_lock = lock;
            ui.add(egui::Checkbox::new(&mut new_lock, "Lock"));

            // Updates the flattening setting.
            if lock != new_lock {
                if let SectionState::Active { lock, .. } = section_state.as_mut() {
                    *lock = new_lock;
                } else {
                    unreachable!()
                }
            }
        });
    }

    if section_direction.is_changed() {
        if let SectionState::Active {
            original_polytope,
            minmax,
            ..
        } = section_state.as_mut()
        {
            *minmax = original_polytope
                .minmax(section_direction.0.clone())
                .unwrap_or((-1.0, 1.0));
        }
    }

    if section_state.is_changed() {
        if let SectionState::Active {
            original_polytope,
            hyperplane_pos,
            minmax,
            flatten,
            lock,
        } = section_state.as_mut()
        {
            // We don't update the view if it's locked.
            if *lock {
                return;
            }

            if let Some(mut p) = query.iter_mut().next() {
                let r = original_polytope.clone();
                let hyp_pos = *hyperplane_pos;

                if let Some(dim) = r.dim() {
                    let hyperplane = Hyperplane::new(section_direction.0.clone(), hyp_pos);
                    *minmax = original_polytope
                        .minmax(section_direction.0.clone())
                        .unwrap_or((-1.0, 1.0));

                    let mut slice = r.cross_section(&hyperplane);

                    if *flatten {
                        slice.flatten_into(&hyperplane.subspace);
                        slice.recenter_with(
                            &hyperplane.flatten(&hyperplane.project(&Point::zeros(dim))),
                        );
                    }

                    *p = slice;
                }
            }
        }
    }
}
/// Shows any secondary views that are active. Currently, just shows the
/// cross-section view.
Shows any secondary views that are active. Currently, just shows the
cross-section view.
Shows any secondary views that are active . Currently just shows the cross - section view .
fn show_views(
    ui: &mut Ui,
    mut query: Query<'_, '_, &mut Concrete>,
    mut section_state: ResMut<'_, SectionState>,
    mut section_direction: ResMut<'_, SectionDirection>,
) {
    // The cross-section settings.
    if let SectionState::Active {
        minmax,
        hyperplane_pos,
        flatten,
        lock,
        ..
    } = *section_state
    {
        ui.label("Cross section settings:");
        ui.spacing_mut().slider_width = ui.available_width() / 3.0;
        // Sets the slider range to the range of x coordinates in the polytope.
        let mut new_hyperplane_pos = hyperplane_pos;
        ui.add(
            egui::Slider::new(
                &mut new_hyperplane_pos,
                (minmax.0 + 0.0000001)..=(minmax.1 - 0.0000001), // We do this to avoid nullitopes.
            )
            .text("Slice depth")
            .prefix("pos: "),
        );
        // Updates the slicing depth.
        #[allow(clippy::float_cmp)]
        if hyperplane_pos != new_hyperplane_pos {
            if let SectionState::Active { hyperplane_pos, .. } = section_state.as_mut() {
                *hyperplane_pos = new_hyperplane_pos;
            } else {
                unreachable!()
            }
        }
        let mut new_direction = section_direction.0.clone();
        ui.add(UnitPointWidget::new(
            &mut new_direction,
            "Cross-section depth",
        ));
        // Updates the slicing direction.
        #[allow(clippy::float_cmp)]
        if section_direction.0 != new_direction {
            section_direction.0 = new_direction;
        }
        ui.horizontal(|ui| {
            // Makes the current cross-section into the main polytope.
            if ui.button("Make main").clicked() {
                section_state.close();
            }
            let mut new_flatten = flatten;
            ui.add(egui::Checkbox::new(&mut new_flatten, "Flatten"));
            // Updates the flattening setting.
            if flatten != new_flatten {
                if let SectionState::Active { flatten, .. } = section_state.as_mut() {
                    *flatten = new_flatten;
                } else {
                    unreachable!()
                }
            }
            let mut new_lock = lock;
            ui.add(egui::Checkbox::new(&mut new_lock, "Lock"));
            // Updates the flattening setting.
            if lock != new_lock {
                if let SectionState::Active { lock, .. } = section_state.as_mut() {
                    *lock = new_lock;
                } else {
                    unreachable!()
                }
            }
        });
    }
    if section_direction.is_changed() {
        if let SectionState::Active {
            original_polytope,
            minmax,
            ..
        } = section_state.as_mut()
        {
            *minmax = original_polytope
                .minmax(section_direction.0.clone())
                .unwrap_or((-1.0, 1.0));
        }
    }
    if section_state.is_changed() {
        if let SectionState::Active {
            original_polytope,
            hyperplane_pos,
            minmax,
            flatten,
            lock,
        } = section_state.as_mut()
        {
            // We don't update the view if it's locked.
            if *lock {
                return;
            }
            if let Some(mut p) = query.iter_mut().next() {
                let r = original_polytope.clone();
                let hyp_pos = *hyperplane_pos;
                if let Some(dim) = r.dim() {
                    let hyperplane = Hyperplane::new(section_direction.0.clone(), hyp_pos);
                    *minmax = original_polytope
                        .minmax(section_direction.0.clone())
                        .unwrap_or((-1.0, 1.0));
                    let mut slice = r.cross_section(&hyperplane);
                    if *flatten {
                        slice.flatten_into(&hyperplane.subspace);
                        slice.recenter_with(
                            &hyperplane.flatten(&hyperplane.project(&Point::zeros(dim))),
                        );
                    }
                    *p = slice;
                }
            }
        }
    }
}
fn show_views ( ui : & mut Ui , mut query : Query < ' _ , ' _ , & mut Concrete > , mut section_state : ResMut < ' _ , SectionState > , mut section_direction : ResMut < ' _ , SectionDirection > , ) { // The cross-section settings. if let SectionState :: Active { minmax , hyperplane_pos , flatten , lock , .. } = * section_state { ui . label ( " " ) ; ui . spacing_mut ( ) . slider_width = ui . available_width ( ) / 3.0 ; // Sets the slider range to the range of x coordinates in the polytope. let mut new_hyperplane_pos = hyperplane_pos ; ui . add ( egui :: Slider :: new ( & mut new_hyperplane_pos , ( minmax . 0 + 0.0000001 ) ..= ( minmax . 1 - 0.0000001 ) , // We do this to avoid nullitopes. ) . text ( " " ) . prefix ( " " ) , ) ; // Updates the slicing depth. # [ allow ( clippy float_cmp ) ] if hyperplane_pos != new_hyperplane_pos { if let SectionState :: Active { hyperplane_pos , .. } = section_state . as_mut ( ) { * hyperplane_pos = new_hyperplane_pos ; } else { unreachable ! ( ) } } let mut new_direction = section_direction . 0 . clone ( ) ; ui . add ( UnitPointWidget :: new ( & mut new_direction , " " , ) ) ; // Updates the slicing direction. # [ allow ( clippy float_cmp ) ] if section_direction . 0 != new_direction { section_direction . 0 = new_direction ; } ui . horizontal ( | ui | { // Makes the current cross-section into the main polytope. if ui . button ( " " ) . clicked ( ) { section_state . close ( ) ; } let mut new_flatten = flatten ; ui . add ( egui :: Checkbox :: new ( & mut new_flatten , " " ) ) ; // Updates the flattening setting. if flatten != new_flatten { if let SectionState :: Active { flatten , .. } = section_state . as_mut ( ) { * flatten = new_flatten ; } else { unreachable ! ( ) } } let mut new_lock = lock ; ui . add ( egui :: Checkbox :: new ( & mut new_lock , " " ) ) ; // Updates the flattening setting. if lock != new_lock { if let SectionState :: Active { lock , .. } = section_state . as_mut ( ) { * lock = new_lock ; } else { unreachable ! ( ) } } } ) ; } if section_direction . is_changed ( ) { if let SectionState :: Active { original_polytope , minmax , .. } = section_state . as_mut ( ) { * minmax = original_polytope . minmax ( section_direction . 0 . clone ( ) ) . unwrap_or ( ( - 1.0 , 1.0 ) ) ; } } if section_state . is_changed ( ) { if let SectionState :: Active { original_polytope , hyperplane_pos , minmax , flatten , lock , } = section_state . as_mut ( ) { // We don't update the view if it's locked. if * lock { return ; } if let Some ( mut p ) = query . iter_mut ( ) . next ( ) { let r = original_polytope . clone ( ) ; let hyp_pos = * hyperplane_pos ; if let Some ( dim ) = r . dim ( ) { let hyperplane = Hyperplane :: new ( section_direction . 0 . clone ( ) , hyp_pos ) ; * minmax = original_polytope . minmax ( section_direction . 0 . clone ( ) ) . unwrap_or ( ( - 1.0 , 1.0 ) ) ; let mut slice = r . cross_section ( & hyperplane ) ; if * flatten { slice . flatten_into ( & hyperplane . subspace ) ; slice . recenter_with ( & hyperplane . flatten ( & hyperplane . project ( & Point :: zeros ( dim ) ) ) , ) ; } * p = slice ; } } } } }
Shows any secondary views that are active.
Shows any secondary views that are active .
ui
&mut Ui
query
Query<'_, '_, &mut Concrete>
section_state
ResMut<'_, SectionState>
section_direction
ResMut<'_, SectionDirection>
ui
&mut Ui
query
Query<'_, '_, &mut Concrete>
section_state
ResMut<'_, SectionState>
section_direction
ResMut<'_, SectionDirection>