Skip to content

Commit

Permalink
Merge branch 'main' into zehiko/cvbp
Browse files Browse the repository at this point in the history
  • Loading branch information
zehiko authored Dec 13, 2024
2 parents 6386f87 + 98152a7 commit b98483d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 2 additions & 0 deletions crates/store/re_grpc_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ async fn stream_catalog_async(
re_log::info!("Starting to read...");
while let Some(result) = resp.next().await {
let mut tc = result.map_err(TonicStatusError)?;
// received TransportChunk doesn't have ChunkId, hence we need to add it before converting
// to Chunk
tc.schema.metadata.insert(
TransportChunk::CHUNK_METADATA_KEY_ID.to_owned(),
ChunkId::new().to_string(),
Expand Down
34 changes: 24 additions & 10 deletions crates/viewer/re_time_panel/src/data_density_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl DensityGraph {
pub fn add_range(&mut self, (min_x, max_x): (f32, f32), count: f32) {
debug_assert!(min_x <= max_x);

if max_x < self.min_x || self.max_x < min_x {
return;
}

if min_x == max_x {
let center_x = lerp(min_x..=max_x, 0.5);
self.add_point(center_x, count);
Expand All @@ -162,29 +166,39 @@ impl DensityGraph {
// We then want to add to the buckets [3, 4, 5, 6],
// but not in equal amounts.

let first_bucket_factor = 1.0 - (min_bucket - min_bucket.floor());
let num_full_buckets = 1.0 + max_bucket.floor() - min_bucket.ceil();
let last_bucket_factor = 1.0 - (max_bucket.ceil() - max_bucket);
let min_full_bucket = min_bucket.ceil();
let first_bucket = min_bucket.floor();
let max_full_bucket = max_bucket.floor();
let last_bucket = max_bucket.ceil();
let first_bucket_factor = 1.0 - (min_bucket - first_bucket);
let num_full_buckets = 1.0 + max_full_bucket - min_full_bucket;
let last_bucket_factor = 1.0 - (last_bucket - max_bucket);
let count_per_bucket =
count / (first_bucket_factor + num_full_buckets + last_bucket_factor);

// For filling self.buckets, we need to account for min_bucket/max_bucket being out of range!
// (everything before & beyond can be seen as a "virtual" bucket that we can't fill)

// first bucket, partially filled:
if let Ok(i) = usize::try_from(min_bucket.floor() as i64) {
if let Ok(i) = usize::try_from(first_bucket as i64) {
if let Some(bucket) = self.buckets.get_mut(i) {
*bucket += first_bucket_factor * count_per_bucket;
}
}

// full buckets:
let min_full_bucket_idx = (min_bucket.ceil() as i64).at_least(0) as usize;
let max_full_bucket_idx =
(max_bucket.floor() as i64).at_most(self.buckets.len() as i64 - 1) as usize;
for bucket in &mut self.buckets[min_full_bucket_idx..=max_full_bucket_idx] {
*bucket += count_per_bucket;
if min_full_bucket != max_full_bucket {
let min_full_bucket_idx =
(min_full_bucket as i64).clamp(0, self.buckets.len() as i64 - 1) as usize;
let max_full_bucket_idx =
(max_full_bucket as i64).clamp(0, self.buckets.len() as i64 - 1) as usize;
for bucket in &mut self.buckets[min_full_bucket_idx..=max_full_bucket_idx] {
*bucket += count_per_bucket;
}
}

// last bucket, partially filled:
if let Ok(i) = usize::try_from(max_bucket.ceil() as i64) {
if let Ok(i) = usize::try_from(last_bucket as i64) {
if let Some(bucket) = self.buckets.get_mut(i) {
*bucket += last_bucket_factor * count_per_bucket;
}
Expand Down

0 comments on commit b98483d

Please sign in to comment.