File tree Expand file tree Collapse file tree
Sources/OpenSwiftUICore/Layout
Tests/OpenSwiftUICoreTests/Layout/Geometry Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -308,10 +308,11 @@ extension CGRect {
308308 s. size. width -= insets. horizontal
309309 s. size. height -= insets. vertical
310310
311- guard s. size. width >= 0 ,
312- s. size. height >= 0
313- else { return . null }
314- return s
311+ if s. size. width < 0 || s. size. height < 0 {
312+ return . null
313+ } else {
314+ return s
315+ }
315316 }
316317
317318 package func inset( by insets: EdgeInsets ) -> CGRect {
@@ -340,15 +341,15 @@ extension CGRect {
340341extension CGSize {
341342 package func inset( by insets: EdgeInsets ) -> CGSize {
342343 CGSize (
343- width: max ( width - insets. horizontal, 0 ) ,
344- height: max ( height - insets. vertical, 0 )
344+ width: max ( 0 , width - insets. horizontal) ,
345+ height: max ( 0 , height - insets. vertical)
345346 )
346347 }
347348
348349 package func outset( by insets: EdgeInsets ) -> CGSize {
349350 CGSize (
350- width: max ( width + insets. horizontal, 0 ) ,
351- height: max ( height + insets. vertical, 0 )
351+ width: max ( 0 , width + insets. horizontal) ,
352+ height: max ( 0 , height + insets. vertical)
352353 )
353354 }
354355}
Original file line number Diff line number Diff line change @@ -102,8 +102,8 @@ extension _ProposedSize {
102102 /// - Returns: A new proposed size with insets applied.
103103 package func inset( by insets: EdgeInsets ) -> _ProposedSize {
104104 _ProposedSize (
105- width: width. map { max ( $0 - insets. leading - insets. trailing, . zero ) } ,
106- height: height. map { max ( $0 - insets. top - insets. bottom, . zero ) }
105+ width: width. map { max ( . zero , $0 - insets. leading - insets. trailing) } ,
106+ height: height. map { max ( . zero , $0 - insets. top - insets. bottom) }
107107 )
108108 }
109109
Original file line number Diff line number Diff line change @@ -124,8 +124,8 @@ extension ViewSize {
124124 /// - Parameter insets: The edge insets to apply.
125125 /// - Returns: A new view size that has been inset by the specified amounts.
126126 package func inset( by insets: EdgeInsets ) -> ViewSize {
127- let newWidth = max ( value. width - ( insets. leading + insets. trailing) , 0 )
128- let newHeight = max ( value. height - ( insets. top + insets. bottom) , 0 )
127+ let newWidth = max ( 0 , value. width - ( insets. leading + insets. trailing) )
128+ let newHeight = max ( 0 , value. height - ( insets. top + insets. bottom) )
129129 return ViewSize (
130130 value: CGSize ( width: newWidth, height: newHeight) ,
131131 proposal: CGSize (
Original file line number Diff line number Diff line change @@ -114,6 +114,12 @@ struct ProposedSizeTests {
114114 let partialInset = partialSize. inset ( by: insets)
115115 #expect( partialInset. width == nil )
116116 #expect( partialInset. height == 180 )
117+
118+ // Test with nan dimensions
119+ let nanSize = _ProposedSize ( width: . nan, height: 200 )
120+ let nanInset = nanSize. inset ( by: insets)
121+ #expect( nanInset. width == 0 )
122+ #expect( nanInset. height == 180 )
117123 }
118124
119125 // MARK: - Axis Access Tests
You can’t perform that action at this time.
0 commit comments