| 26 | } |
| 27 | |
| 28 | pub fn contains_rounded(self, point: Vector2, corner_radius: f32) -> bool { |
| 29 | if !self.contains(point) { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | let ratio = if corner_radius.is_finite() { |
| 34 | corner_radius.clamp(0.0, 1.0) |
| 35 | } else { |
| 36 | 0.0 |
| 37 | }; |
| 38 | let radius = self.size.x.min(self.size.y).max(0.0) * 0.5 * ratio; |
| 39 | if radius <= 0.0 { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | let half = self.size * 0.5; |
| 44 | let local = Vector2::new( |
| 45 | (point.x - self.center.x).abs(), |
| 46 | (point.y - self.center.y).abs(), |
| 47 | ); |
| 48 | let inner = Vector2::new((half.x - radius).max(0.0), (half.y - radius).max(0.0)); |
| 49 | let q = Vector2::new((local.x - inner.x).max(0.0), (local.y - inner.y).max(0.0)); |
| 50 | q.x * q.x + q.y * q.y <= radius * radius |
| 51 | } |
| 52 | |
| 53 | pub fn inset(self, inset: UiRect) -> Self { |
| 54 | let min = self.min() + Vector2::new(inset.left, inset.bottom); |