@@ -21,8 +21,6 @@ pub(crate) struct DijkstraGraph
2121 end : Option < usize >
2222}
2323
24-
25-
2624impl Default for DijkstraGraph
2725{
2826 fn default ( ) -> Self
@@ -123,8 +121,8 @@ impl DijkstraGraph
123121 }
124122 }
125123
126- pub fn get ( & self , id : usize ) -> Option < DijkstraNode >
127- { return self . graph [ id] ; }
124+ pub fn get ( & self , id : usize ) -> & Option < DijkstraNode >
125+ { return & self . graph [ id] ; }
128126
129127 pub fn start ( & self ) -> Option < usize >
130128 { return self . start ; }
@@ -171,9 +169,9 @@ impl DijkstraGraph
171169 for _ in 0 ..self . graph . len ( )
172170 {
173171 if self . graph [ current_node] . is_none ( ) { return None ; }
174- if self . graph [ current_node] . unwrap ( ) . parent . is_none ( ) { return None ; }
172+ if self . graph [ current_node] . as_ref ( ) . unwrap ( ) . parent . is_none ( ) { return None ; }
175173
176- current_node = self . graph [ current_node] . unwrap ( ) . parent . unwrap ( ) ;
174+ current_node = self . graph [ current_node] . as_ref ( ) . unwrap ( ) . parent . unwrap ( ) ;
177175
178176 path. push ( current_node) ;
179177
@@ -183,33 +181,26 @@ impl DijkstraGraph
183181 return Some ( path) ;
184182 }
185183
186- pub fn points_iter ( & self ) -> Iter < Option < DijkstraNode > >
187- { return self . graph . iter ( ) ; }
184+ pub fn points ( & self ) -> & [ Option < DijkstraNode > ; 100 ]
185+ { return & self . graph ; }
188186
189- pub fn lines_iter ( & self ) -> Iter < & ( DijkstraNode , u16 , DijkstraNode ) >
187+ pub fn lines ( & self ) -> Vec < ( usize , & DijkstraNode , u16 , usize , & DijkstraNode ) >
190188 {
191- self . graph . iter ( )
192- . filter_map ( |node| * node)
193- . map ( |node| ( node, node. edges ) )
194- . map ( |( node, edges) | edges. iter ( )
195- . map ( |edge| ( edge. distance , edge. destination ) )
196- . map ( |( distance, id) | ( distance, self . graph . get ( id) ) )
197- . filter ( |( distance, option) | option. is_some ( ) )
198- . map ( |( distance, option) | ( distance, option. unwrap ( ) ) )
199- . filter ( |( distance, option) | option. is_some ( ) )
200- . map ( |( distance, option) | ( distance, option. unwrap ( ) ) )
201- . map ( |( distance, destination) | ( node, distance, destination) )
202- . collect :: < Vec < _ > > ( )
203- . iter ( )
204- )
205- . flatten ( )
206- . collect :: < Vec < _ > > ( )
207- . iter ( )
208- }
189+ let mut lines_iter = vec ! [ ] ;
209190
210- pub fn get_lines ( & self )
211- {
212- todo ! ( ) ;
191+ for ( from_id, point_option) in self . graph . iter ( ) . enumerate ( )
192+ {
193+ let Some ( from_point) = point_option else { continue ; } ;
194+
195+ for edge in & from_point. edges
196+ {
197+ let Some ( Some ( to_point) ) = self . graph . get ( edge. destination ) else { continue ; } ;
198+
199+ lines_iter. push ( ( from_id, from_point, edge. distance , edge. destination , to_point) ) ;
200+ }
201+ }
202+
203+ return lines_iter;
213204 }
214205
215206 pub fn find_hovered_point ( & mut self , mouse_x : f32 , mouse_y : f32 , radius : f32 ) -> Option < usize >
@@ -391,7 +382,8 @@ impl DijkstraGraph
391382 }
392383}
393384
394- struct DijkstraNode
385+ #[ derive( Clone ) ]
386+ pub ( crate ) struct DijkstraNode
395387{
396388 pub position : Position ,
397389 parent : Option < usize > ,
@@ -435,12 +427,12 @@ impl DijkstraNode
435427 pub fn set_visited ( & mut self , visited : bool )
436428 { self . visited = visited; }
437429
438- pub fn edges ( & self ) -> Vec < Edge >
439- { return self . edges ; }
430+ pub fn edges ( & self ) -> & Vec < Edge >
431+ { return & self . edges ; }
440432}
441433
442- // TODO: consider making these fields pub
443- struct Position
434+ # [ derive ( Clone , Copy ) ]
435+ pub ( crate ) struct Position
444436{
445437 pub x : f32 ,
446438 pub y : f32 ,
@@ -455,7 +447,8 @@ impl Position
455447 { self . x = x; self . y = y; }
456448}
457449
458- struct Edge
450+ #[ derive( Clone , Copy ) ]
451+ pub ( crate ) struct Edge
459452{
460453 destination : usize ,
461454 distance : u16 ,
0 commit comments