Skip to content

Commit

Permalink
Rename unedited to !has_edits
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Jul 4, 2023
1 parent 9a8f45e commit c224716
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 51 deletions.
10 changes: 5 additions & 5 deletions crates/re_data_store/src/editable_auto_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ where
}

/// Determine whether this `EditableAutoValue` has user-edits relative to another `EditableAutoValue`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
pub fn unedited(&self, other: &Self) -> bool {
/// If both values are `Auto`, then it is not considered edited.
pub fn has_edits(&self, other: &Self) -> bool {
match (self, other) {
(EditableAutoValue::UserEdited(s), EditableAutoValue::UserEdited(o)) => s == o,
(EditableAutoValue::Auto(_), EditableAutoValue::Auto(_)) => true,
_ => false,
(EditableAutoValue::UserEdited(s), EditableAutoValue::UserEdited(o)) => s != o,
(EditableAutoValue::Auto(_), EditableAutoValue::Auto(_)) => false,
_ => true,
}
}
}
28 changes: 13 additions & 15 deletions crates/re_data_store/src/entity_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ impl EntityPropertyMap {
}

/// Determine whether this `EntityPropertyMap` has user-edits relative to another `EntityPropertyMap`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
pub fn unedited(&self, other: &Self) -> bool {
self.props.len() == other.props.len()
&& self
pub fn has_edits(&self, other: &Self) -> bool {
self.props.len() != other.props.len()
|| self
.props
.iter()
.zip(other.props.iter())
.all(|(x, y)| x.0 == y.0 && x.1.unedited(y.1))
.any(|(x, y)| x.0 != y.0 || x.1.has_edits(y.1))
}
}

Expand Down Expand Up @@ -129,8 +128,7 @@ impl EntityProperties {
}

/// Determine whether this `EntityProperty` has user-edits relative to another `EntityProperty`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
pub fn unedited(&self, other: &Self) -> bool {
pub fn has_edits(&self, other: &Self) -> bool {
let Self {
visible,
visible_history,
Expand All @@ -142,14 +140,14 @@ impl EntityProperties {
backproject_radius_scale,
} = self;

visible == &other.visible
&& visible_history == &other.visible_history
&& interactive == &other.interactive
&& color_mapper.unedited(&other.color_mapper)
&& pinhole_image_plane_distance.unedited(&other.pinhole_image_plane_distance)
&& backproject_depth.unedited(&other.backproject_depth)
&& depth_from_world_scale.unedited(&other.depth_from_world_scale)
&& backproject_radius_scale.unedited(&other.backproject_radius_scale)
visible != &other.visible
|| visible_history != &other.visible_history
|| interactive != &other.interactive
|| color_mapper.has_edits(&other.color_mapper)
|| pinhole_image_plane_distance.has_edits(&other.pinhole_image_plane_distance)
|| backproject_depth.has_edits(&other.backproject_depth)
|| depth_from_world_scale.has_edits(&other.depth_from_world_scale)
|| backproject_radius_scale.has_edits(&other.backproject_radius_scale)
}
}

Expand Down
38 changes: 18 additions & 20 deletions crates/re_space_view/src/data_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ pub struct DataBlueprintGroup {

impl DataBlueprintGroup {
/// Determine whether this `DataBlueprints` has user-edits relative to another `DataBlueprints`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
fn unedited(&self, other: &Self) -> bool {
fn has_edits(&self, other: &Self) -> bool {
let Self {
display_name,
properties_individual,
Expand All @@ -44,11 +43,11 @@ impl DataBlueprintGroup {
entities,
} = self;

display_name == &other.display_name
&& properties_individual.unedited(&other.properties_individual)
&& parent == &other.parent
&& children == &other.children
&& entities == &other.entities
display_name != &other.display_name
|| properties_individual.has_edits(&other.properties_individual)
|| parent != &other.parent
|| children != &other.children
|| entities != &other.entities
}
}

Expand All @@ -68,14 +67,13 @@ pub struct DataBlueprints {
// Manually implement `PartialEq` since projected is serde skip
impl DataBlueprints {
/// Determine whether this `DataBlueprints` has user-edits relative to another `DataBlueprints`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
fn unedited(&self, other: &Self) -> bool {
fn has_edits(&self, other: &Self) -> bool {
let Self {
individual,
projected: _,
} = self;

individual.unedited(&other.individual)
individual.has_edits(&other.individual)
}
}

Expand Down Expand Up @@ -107,9 +105,8 @@ pub struct DataBlueprintTree {
}

/// Determine whether this `DataBlueprintTree` has user-edits relative to another `DataBlueprintTree`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
impl DataBlueprintTree {
pub fn unedited(&self, other: &Self) -> bool {
pub fn has_edits(&self, other: &Self) -> bool {
let Self {
groups,
path_to_group,
Expand All @@ -119,14 +116,15 @@ impl DataBlueprintTree {
} = self;

// Note: this could fail unexpectedly if slotmap iteration order is unstable.
groups
.iter()
.zip(other.groups.iter())
.all(|(x, y)| x.0 == y.0 && x.1.unedited(y.1))
&& *path_to_group == other.path_to_group
&& *entity_paths == other.entity_paths
&& *root_group_handle == other.root_group_handle
&& data_blueprints.unedited(&other.data_blueprints)
groups.len() != other.groups.len()
|| groups
.iter()
.zip(other.groups.iter())
.any(|(x, y)| x.0 != y.0 || x.1.has_edits(y.1))
|| *path_to_group != other.path_to_group
|| *entity_paths != other.entity_paths
|| *root_group_handle != other.root_group_handle
|| data_blueprints.has_edits(&other.data_blueprints)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewport/src/blueprint_components/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ fn test_spaceview() {
assert!(data
.iter()
.zip(ret)
.all(|(l, r)| l.space_view.unedited(&r.space_view)));
.all(|(l, r)| !l.space_view.has_edits(&r.space_view)));
}
17 changes: 8 additions & 9 deletions crates/re_viewport/src/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ pub struct SpaceViewBlueprint {
}

/// Determine whether this `SpaceViewBlueprint` has user-edits relative to another `SpaceViewBlueprint`
/// This is similar in concept to `PartialEq`, but more forgiving of Auto taking on different values.
impl SpaceViewBlueprint {
pub fn unedited(&self, other: &Self) -> bool {
pub fn has_edits(&self, other: &Self) -> bool {
let Self {
id,
display_name,
Expand All @@ -54,13 +53,13 @@ impl SpaceViewBlueprint {
entities_determined_by_user,
} = self;

id == &other.id
&& display_name == &other.display_name
&& class_name == &other.class_name
&& space_origin == &other.space_origin
&& data_blueprint.unedited(&other.data_blueprint)
&& category == &other.category
&& entities_determined_by_user == &other.entities_determined_by_user
id != &other.id
|| display_name != &other.display_name
|| class_name != &other.class_name
|| space_origin != &other.space_origin
|| data_blueprint.has_edits(&other.data_blueprint)
|| category != &other.category
|| entities_determined_by_user != &other.entities_determined_by_user
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewport/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn sync_space_view(
space_view: &SpaceViewBlueprint,
snapshot: Option<&SpaceViewBlueprint>,
) {
if snapshot.map_or(true, |snapshot| space_view.unedited(snapshot)) {
if snapshot.map_or(true, |snapshot| space_view.has_edits(snapshot)) {
let entity_path = EntityPath::from(format!(
"{}/{}",
SpaceViewComponent::SPACEVIEW_PREFIX,
Expand Down

0 comments on commit c224716

Please sign in to comment.