Skip to content

Instantly share code, notes, and snippets.

View SaganRitual's full-sized avatar
:octocat:
Realizing daily I'm not a mathematician

Rob Bishop SaganRitual

:octocat:
Realizing daily I'm not a mathematician
View GitHub Profile
@SaganRitual
SaganRitual / Overload2D.swift
Created March 25, 2019 19:44
Arithmetic and conversions for CGPoint, CGSize, and CGVector. These make the code much more readable and writable, at least for me.
import CoreGraphics
/// Arithmetic extensions for CGPoint, CGSize, and CGVector.
/// All of the operators +, -, *, /, and unary minus are supported. Where
/// applicable, operators can be applied to point/size/vector + point/size/vector,
/// as well as point/size/vector + CGFloat and CGFloat + point/size/vector.
protocol Overload2D {
/// Really for internal use, but publicly available so the unit tests can use them.
var a: CGFloat { get set }
var b: CGFloat { get set }
@SaganRitual
SaganRitual / ContentView.swift
Created December 15, 2021 22:43
One way of passing state from parent to child
// We are a way for the cosmos to know itself. -- C. Sagan
import SwiftUI
class ChildState: ObservableObject {
@Published var childData = 0
}
struct Parent: View {
@State var parentData = 0