Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default point radius to 1.5 ui points #1706

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions crates/re_viewer/src/ui/view_spatial/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,42 +97,17 @@ impl Default for ViewSpatialState {
}

impl ViewSpatialState {
pub fn auto_size_config(
&self,
viewport_size_in_points: egui::Vec2,
) -> re_renderer::AutoSizeConfig {
pub fn auto_size_config(&self) -> re_renderer::AutoSizeConfig {
let mut config = self.auto_size_config;
if config.point_radius.is_auto() {
config.point_radius = self.default_point_radius(viewport_size_in_points);
config.point_radius = re_renderer::Size::new_points(1.5); // default point radius
}
if config.line_radius.is_auto() {
config.line_radius = self.default_line_radius();
config.line_radius = re_renderer::Size::new_points(1.5); // default line radius
}
config
}

#[allow(clippy::unused_self)]
pub fn default_line_radius(&self) -> re_renderer::Size {
re_renderer::Size::new_points(1.5)
}

pub fn default_point_radius(&self, viewport_size_in_points: egui::Vec2) -> re_renderer::Size {
// More points -> smaller points.
let num_points = self.scene_num_primitives; // approximately the same thing when there are many points

// Larger view -> larger points.
let viewport_area = viewport_size_in_points.x * viewport_size_in_points.y;

const RADIUS_MULTIPLIER: f32 = 0.15;
const MIN_POINT_RADIUS: f32 = 0.2;
const MAX_POINT_RADIUS: f32 = 3.0;

let radius = (RADIUS_MULTIPLIER * (viewport_area / (num_points + 1) as f32).sqrt())
.clamp(MIN_POINT_RADIUS, MAX_POINT_RADIUS);

re_renderer::Size::new_points(radius)
}

fn auto_size_world_heuristic(&self) -> f32 {
if self.scene_bbox_accum.is_nothing() || self.scene_bbox_accum.is_nan() {
return 0.01;
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_spatial/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ fn view_2d_scrollable(
space_from_ui,
space_from_pixel,
&space.to_string(),
state.auto_size_config(response.rect.size()),
state.auto_size_config(),
scene
.primitives
.any_outlines,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ pub fn view_3d(
scene,
ctx.render_ctx,
&space.to_string(),
state.auto_size_config(rect.size()),
state.auto_size_config(),
);

// Add egui driven labels on top of re_renderer content.
Expand Down