Swift library for working in two-dimensional coordinate systems.
This library provides structs for Point, Size, and Rect based on the swift standard library. No Foundation or CoreGraphics imports are required.
Most of this work is taken from the swift-corelibs-foundation implementation.
struct Point {
let x: Double
let y: Double
}Point also has accessors for:
extension Point {
var description: String
var isZero: Bool
var isNaN: Bool
func x(_:) -> Point
func y(_:) -> Point
func reflecting(around:) -> Point
}struct Size {
let width: Double
let height: Double
}Additional computed properties and functions of Size:
extension Size {
var description: String
var isZero: Bool
var isNaN: Bool
var widthRadius: Double
var heightRadius: Double
var maxRadius: Double
var minRadius: Double
var center: Point
func width(_:) -> Size
func height(_:) -> Size
}struct Rect {
let origin: Point
let size: Size
}The Rect type has many additional properties:
extension Rect {
var description: String
var isZero: Bool
var isNaN: Bool
var isInfinite: Bool
var isNull: Bool
var isEmpty: Bool
var x: Double
var y: Double
var width: Double
var height: Double
var center: Point
var minX: Double
var midX: Double
var maxX: Double
var minY: Double
var midY: Double
var maxY: Double
var standardized: Rect
func origin(_:) -> Rect
func size(_:) -> Rect
func contains(_: Point) -> Bool
func contains(_: Rect) -> Bool
func intersects(_: Rect) -> Bool
func intersection(_: Rect) -> Rect
func union(_: Rect) -> Rect
func offsetBy(dx:dy:) -> Rect
func insetBy(dx:dy:) -> Rect
func expandedBy(dx:dy:) -> Rect
}