Skip to content

Instantly share code, notes, and snippets.

View heestand-xyz's full-sized avatar

Anton Heestand heestand-xyz

View GitHub Profile
@heestand-xyz
heestand-xyz / CircleCenter.swift
Last active November 6, 2024 12:12
Circle Center from 3 Points
func circleCenter(_ a: CGPoint, _ b: CGPoint, _ c: CGPoint) -> CGPoint {
let dya = b.y - a.y
let dxa = b.x - a.x
let dyb = c.y - b.y
let dxb = c.x - b.x
let sa = dya / dxa
let sb = dyb / dxb
let x = (sa * sb * (a.y - c.y) + sb * (a.x + b.x) - sa * (b.x + c.x)) / (2 * (sb - sa))
let y = -1 * (x - (a.x + b.x) / 2) / sa + (a.y + b.y) / 2
return CGPoint(x: x, y: y)
@heestand-xyz
heestand-xyz / CancellableDragGesture.swift
Last active September 2, 2024 07:37
Cancellable Drag Gesture
import SwiftUI
struct ContentView: View {
@State private var isDragging: Bool = false
@GestureState private var isDraggingActive: Bool = false
var body: some View {
ZStack {
if isDragging {
@heestand-xyz
heestand-xyz / ContentModeAnimation.swift
Created March 15, 2024 22:00
SwiftUI Content Mode Animation
import SwiftUI
struct ContentView: View {
@State private var contentMode: ContentMode = .fit
var body: some View {
ZStack {
@heestand-xyz
heestand-xyz / FrameLayout.swift
Created January 22, 2024 02:46
Frame Layout
struct FrameLayout: Layout {
let frame: CGRect
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
CGSize(
width: proposal.width ?? 0.0,
height: proposal.height ?? 0.0
)
}
@heestand-xyz
heestand-xyz / highlight-js_xcode-dark-mode.css
Last active December 23, 2023 05:13
Highlight.js - Style Sheet - Xcode Dark Mode
/*
//
// xcode-dark-mode.css
// Xcode Dark Mode
//
// Created by Hexagons on 2020-06-11.
// http://hexagons.net/
//
*/
@heestand-xyz
heestand-xyz / allocation_test.swift
Created December 18, 2023 12:42
Swift Allocation Test
func allocationViewModel<T: AnyObject>(_ viewModel: inout T?, as name: String) {
weak var _viewModel: T?
autoreleasepool {
_viewModel = viewModel
viewModel = nil
}
@heestand-xyz
heestand-xyz / Animator.swift
Last active November 30, 2023 01:09
Animator with Easing
import Foundation
import CoreGraphics
#if os(iOS)
import UIKit
#endif
struct Animator {
enum AnimationEase {
case linear
extension XCTestCase {
func isDeallocated<T: AnyObject>(_ object: inout T?) -> Bool {
weak var _object: T?
autoreleasepool {
_object = object
object = nil
@heestand-xyz
heestand-xyz / video-stabilization.swift
Last active April 28, 2023 08:53
Video Stabilization in Swift with AsyncGraphics
// Created by Anton Heestand with the help of GPT-4
// AsyncGraphics: https://github.com/heestand-xyz/AsyncGraphics
import SwiftUI
import AsyncGraphics
import Vision
struct ContentView: View {
@State var graphic: Graphic?
@heestand-xyz
heestand-xyz / SplineDemo.swift
Last active August 27, 2022 17:20
Spline Demo in SwiftUI
//
// ContentView.swift
// Spline Demo
//
// Created by Anton Heestand on 2022-08-27.
//
import SwiftUI
struct ContentView: View {