@@ -94,7 +94,7 @@ impl Egg {
9494 return false ;
9595 }
9696 let p = p - bounds. top_left ( ) ;
97- frm. mask . test ( p)
97+ frm. mask . test ( p) . unwrap ( )
9898 }
9999}
100100
@@ -235,9 +235,11 @@ impl Object {
235235 }
236236
237237 // obj_bound()
238- pub fn bounds ( & self , frm_db : & FrameDb , tile_grid : & impl TileGridView ) -> Rect {
238+ pub fn bounds ( & self , frm_db : & FrameDb , tile_grid : & impl TileGridView ,
239+ include_outline : bool ,
240+ ) -> Rect {
239241 self . do_with_frame_list ( frm_db, |frml, frm|
240- self . bounds0 ( frml. center , frm. size ( ) , tile_grid) )
242+ self . bounds0 ( frml. center , frm. size ( ) , tile_grid, include_outline ) )
241243 }
242244
243245 // critter_is_dead()
@@ -274,13 +276,15 @@ impl Object {
274276 return None ;
275277 }
276278
277- let bounds = self . bounds ( frm_db, tile_grid) ;
279+ // TODO The test may return None for outlined objects.
280+ // Need to have mask for outlined object.
281+ let bounds = self . bounds ( frm_db, tile_grid, false ) ;
278282 if !bounds. contains ( p) {
279283 return None ;
280284 }
281285
282286 let p = p - bounds. top_left ( ) ;
283- if !self . do_with_frame ( frm_db, |frm| frm. mask . test ( p) ) {
287+ if !self . do_with_frame ( frm_db, |frm| frm. mask . test ( p) . unwrap ( ) ) {
284288 return None ;
285289 }
286290
@@ -303,7 +307,9 @@ impl Object {
303307 Some ( r)
304308 }
305309
306- fn bounds0 ( & self , frame_center : Point , frame_size : Point , tile_grid : & impl TileGridView ) -> Rect {
310+ fn bounds0 ( & self , frame_center : Point , frame_size : Point , tile_grid : & impl TileGridView ,
311+ include_outline : bool ,
312+ ) -> Rect {
307313 let mut r = if let Some ( pos) = self . pos {
308314 let top_left =
309315 tile_grid. center_to_screen ( pos. point )
@@ -316,13 +322,15 @@ impl Object {
316322 Rect :: with_points ( self . screen_pos , self . screen_pos + frame_size)
317323 } ;
318324
319- let has_outline = self . outline . map ( |o| !o. disabled ) . unwrap_or ( false ) ;
320- if has_outline {
321- // Include 1-pixel outline.
322- r. left -= 1 ;
323- r. top -= 1 ;
324- r. right += 1 ;
325- r. bottom += 1 ;
325+ if include_outline {
326+ let has_outline = self . outline . map ( |o| !o. disabled ) . unwrap_or ( false ) ;
327+ if has_outline {
328+ // Include 1-pixel outline.
329+ r. left -= 1 ;
330+ r. top -= 1 ;
331+ r. right += 1 ;
332+ r. bottom += 1 ;
333+ }
326334 }
327335
328336 r
@@ -1021,8 +1029,10 @@ impl Objects {
10211029 r
10221030 }
10231031
1024- pub fn bounds ( & self , obj : Handle , tile_grid : & impl TileGridView ) -> Rect {
1025- self . get ( obj) . bounds ( & self . frm_db , tile_grid)
1032+ pub fn bounds ( & self , obj : Handle , tile_grid : & impl TileGridView ,
1033+ include_outline : bool ,
1034+ ) -> Rect {
1035+ self . get ( obj) . bounds ( & self . frm_db , tile_grid, include_outline)
10261036 }
10271037
10281038 pub fn hit_test ( & self , p : EPoint , screen_rect : Rect , tile_grid : & impl TileGridView ,
@@ -1360,7 +1370,7 @@ mod test {
13601370
13611371 let mut obj = Object :: new ( FrameId :: BLANK , None , Some ( ( 0 , ( 55 , 66 ) ) . into ( ) ) , SubObject :: None ) ;
13621372 obj. screen_shift = screen_shift;
1363- assert_eq ! ( obj. bounds0( Point :: new( -1 , 3 ) , Point :: new( 29 , 63 ) , & View :: default ( ) ) ,
1373+ assert_eq ! ( obj. bounds0( Point :: new( -1 , 3 ) , Point :: new( 29 , 63 ) , & View :: default ( ) , true ) ,
13641374 Rect :: with_points( Point :: new( 1 , -51 ) , Point :: new( 30 , 12 ) )
13651375 . translate( base) ) ;
13661376 }
0 commit comments