Skip to content

Commit

Permalink
Add basic path support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Aug 28, 2024
1 parent 45abd02 commit 66522dc
Show file tree
Hide file tree
Showing 9 changed files with 534 additions and 61 deletions.
12 changes: 12 additions & 0 deletions Sources/COpenSwiftUI/Overlay/CoreGraphics/__CGPathParseString.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// __CGPathParseString.m
// COpenSwiftUI

#include "__CGPathParseString.h"

#if OPENSWIFTUI_TARGET_OS_DARWIN
BOOL __CGPathParseString(CGMutablePathRef path, const char *utf8CString) {
// TODO
return NO;
}
#endif
4 changes: 1 addition & 3 deletions Sources/COpenSwiftUI/dyld_Private.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//
// dyld_Private.c
//
//
//
// COpenSwiftUI

#include "dyld_Private.h"

Expand Down
24 changes: 24 additions & 0 deletions Sources/COpenSwiftUI/include/__CGPathParseString.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// __CGPathParseString.m
// COpenSwiftUI

#ifndef __CGPathParseString_h
#define __CGPathParseString_h

#include "OpenSwiftUIBase.h"

#if OPENSWIFTUI_TARGET_OS_DARWIN

#include <Foundation/Foundation.h>
#include <CoreGraphics/CoreGraphics.h>

OPENSWIFTUI_ASSUME_NONNULL_BEGIN

OPENSWIFTUI_EXPORT
BOOL __CGPathParseString(CGMutablePathRef path, const char *utf8CString);

OPENSWIFTUI_ASSUME_NONNULL_END

#endif

#endif /* __CGPathParseString_h */
19 changes: 19 additions & 0 deletions Sources/OpenSwiftUI/Core/Data/UnsafeAtomicLazy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// UnsafeAtomicLazy.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

struct UnsafeAtomicLazy<Data>: Destroyable {
@UnsafeLockedPointer
var cache: Data?

func read(_ block: () -> Data) -> Data {
fatalError("TODO") // StrokedPath.boundingRect
}

func destroy() {
_cache.destroy()
}
}
58 changes: 0 additions & 58 deletions Sources/OpenSwiftUI/View/Shape/Path.swift

This file was deleted.

31 changes: 31 additions & 0 deletions Sources/OpenSwiftUI/View/Shape/Path/FixedRoundedRect.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// FixedRoundedRect.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

import Foundation

@usableFromInline
struct FixedRoundedRect: Equatable {
var rect: CGRect
var cornerSize: CGSize
var style: RoundedCornerStyle

func contains(_ roundedRect: FixedRoundedRect) -> Bool {
guard rect.insetBy(dx: -0.001, dy: -0.001).contains(roundedRect.rect) else {
return false
}
guard !(cornerSize.width <= roundedRect.cornerSize.width && cornerSize.height <= roundedRect.cornerSize.height) else {
return true
}
let minCornerWidth = min(abs(rect.size.width) / 2, cornerSize.width)
let minCornerHeight = min(abs(rect.size.height) / 2, cornerSize.height)
let factor = 0.292893 // 1 - cos(45 * Double.pi / 180)
return rect.insetBy(dx: minCornerWidth * factor, dy: minCornerHeight * factor).contains(roundedRect.rect)
}

func distance(to point: CGPoint) -> CGFloat {
fatalError("TODO")
}
}
Loading

0 comments on commit 66522dc

Please sign in to comment.