Skip to content

Commit

Permalink
Fixed insert bug
Browse files Browse the repository at this point in the history
  • Loading branch information
HHogg committed Dec 7, 2024
1 parent c6ff286 commit 1dc1785
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions workspaces/spatial-grid-map/src-rust/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ impl<TEntryValue: Default> BucketEntry<TEntryValue> {
let (x, y) = self.point;
normalize_radian(y.atan2(x))
}

pub fn increment_counter(&mut self, key: &str) {
let counter = self.counters.entry(key.to_string()).or_insert(0);
*counter += 1;
}
}

impl<TEntryValue: Clone + Default> Eq for BucketEntry<TEntryValue> {}
Expand Down
20 changes: 14 additions & 6 deletions workspaces/spatial-grid-map/src-rust/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,36 @@ impl<TEntryValue: Clone + std::fmt::Debug + Default> SpatialGridMap<TEntryValue>
self.get_value(point).is_some()
}

fn insert_entry(&mut self, entry: BucketEntry<TEntryValue>) -> &mut Self {
fn insert_entry(&mut self, entry: BucketEntry<TEntryValue>) -> MutBucketEntry<TEntryValue> {
match self.get_location(&entry.point) {
None => {
self.increase_size();
self.insert_entry(entry);
self.insert_entry(entry)
}
Some(location) => {
let point = entry.point;
let size = entry.size;

if self.store.entry(location.key).or_default().insert(entry) {
self.locations.insert(location);
self.update_spacing(size);
}
}
};

self
self
.get_value_mut(&point)
.expect("Value not found after insert")
}
}
}

/// Inserts a point into the grid, returning false if it's already present.
/// If the grid is too small, it will be increased to fit the new centroid.
pub fn insert(&mut self, point: (f64, f64), size: f64, value: TEntryValue) -> &mut Self {
pub fn insert(
&mut self,
point: (f64, f64),
size: f64,
value: TEntryValue,
) -> MutBucketEntry<TEntryValue> {
self.insert_entry(
BucketEntry::default()
.with_point(point)
Expand Down
2 changes: 1 addition & 1 deletion workspaces/tilings/src-rust/tiling/src/build/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl Plane {
self
.line_segments
.insert(mid_point_f64, line_segment.length(), *line_segment)
.increment_counter(&mid_point_f64, "count");
.increment_counter("count");

// Check that the line segment is not intersecting with any
// other line segments around it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const defaultOptions: Pick<
NoUndefinedField<Options>,
'autoRotate' | 'colorMode' | 'scaleMode' | 'showLayers'
> = {
autoRotate: false,
autoRotate: true,
colorMode: ColorMode.VaporWave,
scaleMode: ScaleMode.Cover,
showLayers: {
Expand Down
4 changes: 3 additions & 1 deletion workspaces/tilings/src/Presentation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import Settings from './Settings/Settings';
import SettingsProvider from './Settings/SettingsProvider';
import { useSettingsContext } from './Settings/useSettingsContext';

const DEFAULT_NOTATION = '3-4,3-3,3,3/m60/m(c3)';
// const DEFAULT_NOTATION = '3-4,3-3,3,3/m60/m(c3)';
// const DEFAULT_NOTATION = '3-4,3-3,3,3/r60/r(h3)';
const DEFAULT_NOTATION = '6/m90/r(h6)';

function PresentationInner(props: RendererProps) {
const {
Expand Down

0 comments on commit 1dc1785

Please sign in to comment.