File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,23 +161,20 @@ impl Rectangle<f32> {
161161 /// Computes the offset that must be applied to the [`Rectangle`] to be placed
162162 /// inside the given `container`.
163163 pub fn offset ( & self , container : & Rectangle ) -> Vector {
164- let Some ( intersection) = self . intersection ( container) else {
165- return Vector :: ZERO ;
166- } ;
167-
168- let left = intersection. x - self . x ;
169- let top = intersection. y - self . y ;
170-
171164 Vector :: new (
172- if left > 0.0 {
173- left
165+ if container. x > self . x {
166+ container. x - self . x
167+ } else if self . x + self . width > container. x + container. width {
168+ container. x + container. width - self . x - self . width
174169 } else {
175- intersection . x + intersection . width - self . x - self . width
170+ 0.0
176171 } ,
177- if top > 0.0 {
178- top
172+ if container. y > self . y {
173+ container. y - self . y
174+ } else if self . y + self . height > container. y + container. height {
175+ container. y + container. height - self . y - self . height
179176 } else {
180- intersection . y + intersection . height - self . y - self . height
177+ 0.0
181178 } ,
182179 )
183180 }
You can’t perform that action at this time.
0 commit comments