From 1dc17851e05df60252528bc36da0b568d88aabed Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Sat, 7 Dec 2024 22:24:57 +0000 Subject: [PATCH] Fixed insert bug --- .../spatial-grid-map/src-rust/bucket.rs | 5 +++++ workspaces/spatial-grid-map/src-rust/grid.rs | 20 +++++++++++++------ .../src-rust/tiling/src/build/plane.rs | 2 +- .../Presentation/Renderer/defaultOptions.ts | 2 +- workspaces/tilings/src/Presentation/index.tsx | 4 +++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/workspaces/spatial-grid-map/src-rust/bucket.rs b/workspaces/spatial-grid-map/src-rust/bucket.rs index 29559f2..022fa05 100644 --- a/workspaces/spatial-grid-map/src-rust/bucket.rs +++ b/workspaces/spatial-grid-map/src-rust/bucket.rs @@ -151,6 +151,11 @@ impl BucketEntry { 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 Eq for BucketEntry {} diff --git a/workspaces/spatial-grid-map/src-rust/grid.rs b/workspaces/spatial-grid-map/src-rust/grid.rs index bce7568..d6c0002 100644 --- a/workspaces/spatial-grid-map/src-rust/grid.rs +++ b/workspaces/spatial-grid-map/src-rust/grid.rs @@ -157,28 +157,36 @@ impl SpatialGridMap self.get_value(point).is_some() } - fn insert_entry(&mut self, entry: BucketEntry) -> &mut Self { + fn insert_entry(&mut self, entry: BucketEntry) -> MutBucketEntry { 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 { self.insert_entry( BucketEntry::default() .with_point(point) diff --git a/workspaces/tilings/src-rust/tiling/src/build/plane.rs b/workspaces/tilings/src-rust/tiling/src/build/plane.rs index 778b894..fdc2f47 100644 --- a/workspaces/tilings/src-rust/tiling/src/build/plane.rs +++ b/workspaces/tilings/src-rust/tiling/src/build/plane.rs @@ -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 diff --git a/workspaces/tilings/src/Presentation/Renderer/defaultOptions.ts b/workspaces/tilings/src/Presentation/Renderer/defaultOptions.ts index e47733b..32889b0 100644 --- a/workspaces/tilings/src/Presentation/Renderer/defaultOptions.ts +++ b/workspaces/tilings/src/Presentation/Renderer/defaultOptions.ts @@ -11,7 +11,7 @@ export const defaultOptions: Pick< NoUndefinedField, 'autoRotate' | 'colorMode' | 'scaleMode' | 'showLayers' > = { - autoRotate: false, + autoRotate: true, colorMode: ColorMode.VaporWave, scaleMode: ScaleMode.Cover, showLayers: { diff --git a/workspaces/tilings/src/Presentation/index.tsx b/workspaces/tilings/src/Presentation/index.tsx index 7297899..789ab08 100644 --- a/workspaces/tilings/src/Presentation/index.tsx +++ b/workspaces/tilings/src/Presentation/index.tsx @@ -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 {