Created
October 17, 2023 10:51
-
-
Save Feuermurmel/d3bcbe3e67070550e55abe64aa3e8219 to your computer and use it in GitHub Desktop.
Swift Named Parameter Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct Point { | |
var x: Float64 | |
var y: Float64 | |
init(_ x: Float64, _ y: Float64) { | |
self.x = x | |
self.y = y | |
} | |
} | |
struct Line { | |
var point1: Point | |
var point2: Point | |
init(_ point1: Point, _ point2: Point) { | |
self.point1 = point1 | |
self.point2 = point2 | |
} | |
} | |
struct Circle { | |
var center: Point | |
var radius: Float64 | |
} | |
struct Hexagon { | |
// ... | |
} | |
func line(though point1: Point, atAngle angle: Float64) -> Line { | |
return Line(point1, Point(point1.x + cos(angle), point1.y + sin(angle))) | |
} | |
func line(though point1: Point, _ point2: Point) -> Line { | |
return Line(point1, point2) | |
} | |
func line(though point1: Point, inDirection direction: Point) -> Line { | |
return Line(point1, Point(point1.x + direction.x, point1.y + direction.y)) | |
} | |
func circle(center: Point, radius: Float64) -> Circle { | |
fatalError("insert maths") | |
} | |
func circle(throughPoints point1: Point, _ point2: Point, _ point3: Point) -> Circle { | |
fatalError("insert maths") | |
} | |
func circle(center: Point, tangentTo tangent: Line) -> Circle { | |
fatalError("insert maths") | |
} | |
func hexagon(center: Point, outerRadius: Float64) -> Hexagon { | |
fatalError("insert maths") | |
} | |
func hexagon(center: Point, innerRadius: Float64) -> Hexagon { | |
fatalError("insert maths") | |
} | |
func hexagon(center: Point, edgeLength: Float64) -> Hexagon { | |
fatalError("insert maths") | |
} | |
func hexagon(inscribing circle: Circle, atAngle angle: Float64) -> Hexagon { | |
fatalError("insert maths") | |
} | |
func hexagon(circumscribing circle: Circle, atAngle angle: Float64) -> Hexagon { | |
fatalError("insert maths") | |
} | |
let p1 = Point(1, 1) | |
let p2 = Point(2, 3) | |
let p3 = Point(0, 4) | |
let l1 = line(though: p1, atAngle: .pi) | |
_ = line(though: p1, p2) | |
_ = line(though: p1, inDirection: p2) | |
let c1 = circle(center: p1, radius: 15) | |
_ = circle(throughPoints: p1, p2, p3) | |
_ = circle(center: p1, tangentTo: l1) | |
_ = hexagon(center: p1, outerRadius: 15) | |
_ = hexagon(center: p1, innerRadius: 13) | |
_ = hexagon(center: p1, edgeLength: 3) | |
_ = hexagon(inscribing: c1, atAngle: .pi) | |
_ = hexagon(circumscribing: c1, atAngle: .pi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment