@@ -80,10 +80,9 @@ fn main() {
8080 height: window_height // window height
8181 create_window: true // this will create a different window
8282 window_title: 'A* Path finding algorithm visusalizer' // title of the window
83- frame_fn: frame // this is frame function update the frame
84- event_fn: on_event // it calls on every event
85- init_fn: init_images // run at start of application
86- user_data: app // store user data
83+ frame_fn: frame // this is frame function update the frame
84+ event_fn: on_event // it calls on every event
85+ user_data: app // store user data
8786 )
8887 mut grid := initialise_grid () // initialize the grid variable and populate the matrix with each cell as empty
8988 app.grid = grid // set grid to app attribute so you can access it by just passing app variable or with method of app
@@ -102,17 +101,11 @@ fn main() {
102101// this function will run for every frame actually in a loop
103102fn frame (mut app App) {
104103 app.gg.begin ()
105- draw_grid (mut app, mut app.grid )
104+ draw_grid (mut app)
106105 draw_gridlines (mut app)
107106 app.gg.end ()
108107}
109108
110- // this will run at start of app
111- fn init_images (mut app App) {
112- // app.resize()
113- return
114- }
115-
116109// this will handle user event which is stored in gg.event variable
117110fn on_event (event & gg.Event, mut app App) {
118111 match event.typ {
@@ -192,7 +185,7 @@ fn (mut app App) on_key_down(key gg.KeyCode) {
192185 app.gg.quit ()
193186 }
194187 .c {
195- draw_grid (mut app, mut app.grid )
188+ draw_grid (mut app)
196189 draw_gridlines (mut app)
197190 mut grid := initialise_grid ()
198191 app.grid = grid // set grid to app attribute so you can access it by just passing app variable or with method of app
@@ -227,15 +220,6 @@ fn hf(p1 Point, p2 Point) int {
227220 return math.abs (p1 .x - p2 .x) + math.abs (p1 .y - p2 .y)
228221}
229222
230- // get the position of mouse in terms of which cells' row and column
231- fn get_clicked_pos (pos Point, rows int , width int ) (int , int ) {
232- x := pos.x
233- y := pos.y
234- row := y / rows
235- col := x / rows
236- return row, col
237- }
238-
239223// initialize grid attribute of app
240224fn initialise_grid () [][]Cell {
241225 mut grid := [][]Cell{len: nrows, init: []Cell{len: nrows}}
@@ -259,7 +243,7 @@ fn initialise_grid() [][]Cell {
259243}
260244
261245// draw the cells of grid
262- fn draw_grid (mut app App, mut grid [][]Cell ) {
246+ fn draw_grid (mut app App) {
263247 for i := 0 ; i < nrows; i++ {
264248 for j := 0 ; j < nrows; j++ {
265249 pos := app.grid[i][j].pos
@@ -299,7 +283,7 @@ fn update_neighbors(mut grid [][]Cell, row int, col int) {
299283}
300284
301285// construct the path after finding it shows as pink color
302- fn reconstruct_path (mut grid [][]Cell, mut came_from [][]Point, start Point, end Point) {
286+ fn reconstruct_path (mut grid [][]Cell, mut came_from [][]Point, _start Point, end Point) {
303287 mut x := end.x
304288 mut y := end.y
305289 for ! (x == - 1 && y == - 1 ) {
@@ -310,7 +294,7 @@ fn reconstruct_path(mut grid [][]Cell, mut came_from [][]Point, start Point, end
310294}
311295
312296// a* path finding algorithm
313- fn astar_path_finding (mut app App, mut grid [][]Cell, start Point, end Point) {
297+ fn astar_path_finding (mut _app App, mut grid [][]Cell, start Point, end Point) {
314298 mut priority_queue := & MinHeap{}
315299 mut g_score := [][]int {len: nrows, init: []int {len: nrows}}
316300 mut f_score := [][]int {len: nrows, init: []int {len: nrows}}
0 commit comments