 public extension CGRect {
 
     /// Returns a copy of `self` centered relative to the given rectangle.
-    @inlinable
-    func centered(in rect: CGRect) -> CGRect {
-        guard !self.isEmpty && !self.isInfinite else { return self }
-        let rectCenter = rect.center
-        let origin = CGPoint(x: rectCenter.x - self.width / 2.0, y: rectCenter.y - self.height / 2.0)
-        return CGRect(origin: origin, size: self.size)
+    @inlinable func centered(in rect: CGRect) -> CGRect {
+        guard !isEmpty && !isInfinite else { return self }
+        return CGRect(center: rect.center, size: size)
     }
 
     /// Centers `self` relative to the given rect.
-    @inlinable
-    mutating func center(in rect: CGRect) {
-        self = self.centered(in: rect)
+    @inlinable mutating func center(in rect: CGRect) {
+        center = rect.center
     }
 
     /// Returns a copy of `self` centered to the given point.
-    @inlinable
-    func centered(at point: CGPoint) -> CGRect {
-        guard !self.isEmpty && !self.isInfinite else { return self }
-        let origin = CGPoint(x: point.x - self.width / 2.0, y: point.y - self.height / 2.0)
-        return CGRect(origin: origin, size: self.size)
+    @inlinable func centered(at point: CGPoint) -> CGRect {
+        .init(center: point, size: size)
     }
     
     /// Returns a copy of `self` centered at `(x,y)`.
-    @inlinable
-    func centered<I: BinaryInteger>(atX x: I, y: I) -> CGRect {
-        self.centered(atX: CGFloat(x), y: CGFloat(y))
+    @inlinable func centered<I: BinaryInteger>(atX x: I, y: I) -> CGRect {
+        .init(center: .init(x, y), size: size)
     }
     
     /// Returns a copy of `self` centered at `(x,y)`.
-    @inlinable
-    func centered<F: BinaryFloatingPoint>(atX x: F, y: F) -> CGRect {
-        self.centered(atX: CGFloat(x), y: CGFloat(y))
+    @inlinable func centered<F: BinaryFloatingPoint>(atX x: F, y: F) -> CGRect {
+        .init(center: .init(x, y), size: size)
     }
     
     /// Returns a copy of `self` centered at `(x,y)`.
     @inlinable
     func centered(atX x: CGFloat, y: CGFloat) -> CGRect {
-        let center = CGPoint(x: x, y: y)
-        return self.centered(at: center)
+        .init(center: .init(x, y), size: size)
     }
     
     /// Centers `self` relative to the given point.
-    @inlinable
-    mutating func center(at point: CGPoint) {
-        self = self.centered(at: point)
+    @inlinable mutating func center(at point: CGPoint) {
+        center = point
     }
 
     /// Centers `self` at `(x,y)`
-    @inlinable
-    mutating func center<I: BinaryInteger>(atX x: I, y: I) {
-        self = self.centered(atX: x, y: y)
+    @inlinable mutating func center<I: BinaryInteger>(atX x: I, y: I) {
+        center = .init(x, y)
     }
     
     /// Centers `self` at `(x,y)`
-    @inlinable
-    mutating func center<F: BinaryFloatingPoint>(atX x: F, y: F) {
-        self = self.centered(atX: x, y: y)
+    @inlinable mutating func center<F: BinaryFloatingPoint>(atX x: F, y: F) {
+        center = .init(x, y)
     }
     
     /// Centers `self` at `(x,y)`
-    @inlinable
-    mutating func center(atX x: CGFloat, y: CGFloat) {
-        self = self.centered(atX: x, y: y)
+    @inlinable mutating func center(atX x: CGFloat, y: CGFloat) {
+        center = .init(x, y)
     }
 }
 

    }
}

// MARK: -
// MARK: Corners
public extension CGRect {
    
    /// A point representing the rectangle's center.
    @inlinable
    var center: CGPoint {
        get {
            CGPoint(x: self.midX, y: self.midY)
        }
        set {
            self.origin = newValue.translated(along: self.center.formVector(with: self.origin))
        }
    }
    
    @inlinable
    subscript(xBound: RectBoundary = .mid, yBound: RectBoundary = .mid) -> CGPoint {
        get {
            let x, y: CGFloat
            switch xBound {
            case .min:
                x = self.minX
            case .mid:
                x = self.midX
            case .max:
                x = self.maxX
            }
            switch yBound {
            case .min:
                y = self.minY
            case .mid:
                y = self.midY
            case .max:
                y = self.maxY
            }
            
            return .init(x: x, y: y)
        }
        set {
            self.origin = newValue.translated(along: self[xBound, yBound].formVector(with: self.origin))
        }
    }
}

public extension CGRect {
    
    /// The biggest square rectangle that `self` can contain.
    @inlinable var maxSquare: CGRect {
        let maxEdge = max(self.width, self.height)
        return CGRect(origin: .zero, size: .init(width: maxEdge, height: maxEdge))
    }
    
    /// The smallest square rectangle that can contain `self`.
    @inlinable var minSquare: CGRect {
        let minEdge = min(self.width, self.height)
        return CGRect(origin: .zero, size: .init(width: minEdge, height: minEdge))
    }
    
    /// The ratio of `self`.
    @inlinable var ratio: CGFloat {
        return width / height
    }
    
    
    /// The diagonal of `self`.
    @inlinable var diagonal: CGFloat {
        length(size.simd2).cgFloat
    }
    
    /// The orientation of `self`.
    @inlinable var orientation: Orientation {
        switch ratio {
        case let x where x < 1.0: return .portrait
        case let x where x > 1.0: return .landscape
        default: return .square
        }
    }
}
