Skip to content

Commit

Permalink
Remove unnecessary Serde and PartialEq
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed May 24, 2023
1 parent 0a7bf2c commit 1c550e2
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 87 deletions.
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl SpaceViewBlueprint {
// ----------------------------------------------------------------------------

/// Camera position and similar.
#[derive(Clone, Default, PartialEq, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Default)]
pub struct SpaceViewState {
/// Selects in [`Self::state_tensors`].
selected_tensor: Option<InstancePath>,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_bar_chart/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn help_text(re_ui: &re_ui::ReUi) -> egui::WidgetText {
layout.layout_job.into()
}

#[derive(Clone, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Default, PartialEq, Eq)]
pub struct BarChartState;

pub(crate) fn view_bar_chart(
Expand Down
30 changes: 1 addition & 29 deletions crates/re_viewer/src/ui/view_spatial/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,23 @@ impl From<AutoSizeUnit> for WidgetText {
}
}

#[derive(Clone, serde::Deserialize, serde::Serialize)]
#[derive(Clone)]
pub struct ViewSpatialState {
/// How the scene is navigated.
pub nav_mode: EditableAutoValue<SpatialNavigationMode>,

/// Estimated bounding box of all data. Accumulated over every time data is displayed.
///
/// Specify default explicitly, otherwise it will be a box at 0.0 after deserialization.
#[serde(skip, default = "BoundingBox::nothing")]
pub scene_bbox_accum: BoundingBox,

/// Estimated bounding box of all data for the last scene query.
#[serde(skip, default = "BoundingBox::nothing")]
pub scene_bbox: BoundingBox,

/// Estimated number of primitives last frame. Used to inform some heuristics.
#[serde(skip)]
pub scene_num_primitives: usize,

/// Last frame's picking result.
#[serde(skip)]
pub previous_picking_result: Option<PickingResult>,

pub(super) state_2d: View2DState,
Expand All @@ -92,30 +88,6 @@ pub struct ViewSpatialState {
auto_size_config: re_renderer::AutoSizeConfig,
}

// TODO(#2089): This render-related state probably doesn't belong in the blueprint
// in the blueprint in the first place. But since serde skips it we also have to ignore it.
// or else we re-store state on every frame. Either way the fact that we don't get it
// back out of the store is going to cause problems.
impl PartialEq for ViewSpatialState {
fn eq(&self, other: &Self) -> bool {
let Self {
nav_mode,
scene_bbox_accum: _, // serde-skip
scene_bbox: _, // serde-skip
scene_num_primitives: _, // serde-skip
previous_picking_result: _, // serde-skip
state_2d,
state_3d,
auto_size_config,
} = self;

*nav_mode == other.nav_mode
&& *state_2d == other.state_2d
&& *state_3d == other.state_3d
&& *auto_size_config == other.auto_size_config
}
}

impl Default for ViewSpatialState {
fn default() -> Self {
Self {
Expand Down
37 changes: 1 addition & 36 deletions crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ use super::{

// ---

#[derive(Clone, serde::Deserialize, serde::Serialize)]
#[serde(default)]
#[derive(Clone)]
pub struct View3DState {
pub orbit_eye: Option<OrbitEye>,

Expand All @@ -46,57 +45,23 @@ pub struct View3DState {
/// Camera pose just before we took over another camera via [Self::tracked_camera].
camera_before_tracked_camera: Option<Eye>,

#[serde(skip)]
eye_interpolation: Option<EyeInterpolation>,

/// Where in world space the mouse is hovering (from previous frame)
#[serde(skip)]
hovered_point: Option<glam::Vec3>,

// options:
pub spin: bool,
pub show_axes: bool,
pub show_bbox: bool,

#[serde(skip)]
last_eye_interact_time: f64,

/// Filled in at the start of each frame
#[serde(skip)]
pub(crate) space_specs: SpaceSpecs,
#[serde(skip)]
space_camera: Vec<SpaceCamera3D>, // TODO(andreas): remove this once camera meshes are gone
}

// TODO(#2089): This state probably doesn't belong in the blueprint in the
// first place. But since serde skips it we also have to ignore it. or else we
// re-store state on every frame. Either way the fact that we don't get it back
// out of the store is going to cause problems.
impl PartialEq for View3DState {
fn eq(&self, other: &Self) -> bool {
let Self {
orbit_eye,
tracked_camera,
camera_before_tracked_camera,
eye_interpolation: _, // serde-skip
hovered_point: _, // serde-skip
spin,
show_axes,
show_bbox,
last_eye_interact_time: _, // serde-skip
space_specs: _, // serde-skip
space_camera: _, // serde-skip
} = self;

*orbit_eye == other.orbit_eye
&& *tracked_camera == other.tracked_camera
&& *camera_before_tracked_camera == other.camera_before_tracked_camera
&& *spin == other.spin
&& *show_axes == other.show_axes
&& *show_bbox == other.show_bbox
}
}

impl Default for View3DState {
fn default() -> Self {
Self {
Expand Down
19 changes: 1 addition & 18 deletions crates/re_viewer/src/ui/view_tensor/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct SliceSelection {
pub selector_values: BTreeMap<usize, u64>,
}

#[derive(Clone, serde::Deserialize, serde::Serialize)]
#[derive(Clone)]
pub struct ViewTensorState {
/// What slice are we vieiwing?
slice: SliceSelection,
Expand All @@ -40,26 +40,9 @@ pub struct ViewTensorState {

/// Last viewed tensor, copied each frame.
/// Used for the selection view.
#[serde(skip)]
tensor: Option<DecodedTensor>,
}

// TODO(#2089): TManually implement PartialEq so we aren't comparing the serde-skipped tensor
impl PartialEq for ViewTensorState {
fn eq(&self, other: &Self) -> bool {
let Self {
slice,
color_mapping,
texture_settings,
tensor: _, // serde-skip
} = self;

*slice == other.slice
&& *color_mapping == other.color_mapping
&& *texture_settings == other.texture_settings
}
}

impl ViewTensorState {
pub fn create(tensor: &DecodedTensor) -> ViewTensorState {
Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_text_box/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::SceneTextBox;

// --- Main view ---

#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[derive(Clone, PartialEq, Eq)]
pub struct ViewTextBoxState {
monospace: bool,
word_wrap: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_time_series/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn help_text(re_ui: &re_ui::ReUi) -> egui::WidgetText {
layout.layout_job.into()
}

#[derive(Clone, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Default, PartialEq, Eq)]
pub struct ViewTimeSeriesState;

pub(crate) fn view_time_series(
Expand Down

0 comments on commit 1c550e2

Please sign in to comment.