diff --git a/src/lib/hooks.tsx b/src/lib/hooks.tsx
index 8810f14..306955d 100644
--- a/src/lib/hooks.tsx
+++ b/src/lib/hooks.tsx
@@ -1,5 +1,5 @@
import { useSyncExternalStore } from "react";
-import { globalStore } from "../visualizers/bubble-sort";
+import { globalStore } from "../visualizers/convolution2d";
export const useVisualizer = () => {
return useSyncExternalStore(globalStore.subscribe, globalStore.getCurSnapshot);
diff --git a/src/visualizers/convolution2d/matrix.tsx b/src/visualizers/convolution2d/matrix.tsx
index 0427edc..ab36d76 100644
--- a/src/visualizers/convolution2d/matrix.tsx
+++ b/src/visualizers/convolution2d/matrix.tsx
@@ -8,8 +8,8 @@ export interface Matrix {
get: (row: number, column: number) => number;
}
-export const enum PaddingType {
- Reflect, Wrap, Edge, Zero
+export enum PaddingType {
+ Reflect="reflect", Wrap="wrap", Edge="edge", Zero="zero"
}
export class ArrayMatrix implements Matrix {
@@ -75,6 +75,8 @@ const recalculateIndex = (
return edgeIndex(correctedIndex, length);
case PaddingType.Zero:
return 0;
+ default:
+ throw Error("Unknown type: " + paddingType)
}
}
diff --git a/src/visualizers/convolution2d/start.tsx b/src/visualizers/convolution2d/start.tsx
index 392495e..854af5d 100644
--- a/src/visualizers/convolution2d/start.tsx
+++ b/src/visualizers/convolution2d/start.tsx
@@ -1,3 +1,4 @@
+import { useState } from "react"
import { Convolution2DArguments } from "./convolution2d"
import { PaddingType, ArrayMatrix } from "./matrix"
@@ -5,26 +6,36 @@ type Props = {
doStart: (args: Convolution2DArguments, noStop: boolean) => void
}
-const args: Convolution2DArguments = [
- new ArrayMatrix([
- [5, 4, 3, 2, 1],
- [4, 3, 2, 1, 0],
- [3, 2, 1, 0, 1],
- [2, 1, 0, 1, 2],
- [1, 0, 1, 2, 3],
- ]),
- new ArrayMatrix([
- [0, 1, 0],
- [1, 1, 1],
- [0, 1, 0],
- ]),
- 2,
- 3,
- PaddingType.Edge,
-]
-
-export const Convolution2DStarter = ({ doStart}: Props) => {
+export const Convolution2DStarter = ({ doStart }: Props) => {
+ const options = Object.values(PaddingType);
+ const [selectedType, setSelectedType] = useState(PaddingType.Edge);
+ const args: Convolution2DArguments = [
+ new ArrayMatrix([
+ [5, 4, 3, 2, 1],
+ [4, 3, 2, 1, 0],
+ [3, 2, 1, 0, 1],
+ [2, 1, 0, 1, 2],
+ [1, 0, 1, 2, 3],
+ ]),
+ new ArrayMatrix([
+ [0, 1, 0],
+ [1, 1, 1],
+ [0, 1, 0],
+ ]),
+ 2,
+ 3,
+ selectedType,
+ ]
+ console.log(args[4]);
return
+
;