From 5a489f30fd2ed625960a6a2cc6150d53ab7b1927 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 27 Dec 2025 14:41:46 +0800 Subject: [PATCH 1/2] Add ORBPathIsEmpty and Equal function API --- Sources/OpenRenderBox/Path/ORBPath.cpp | 70 +++++++++++++++---- .../include/OpenRenderBox/ORBPath.h | 24 ++++--- 2 files changed, 72 insertions(+), 22 deletions(-) diff --git a/Sources/OpenRenderBox/Path/ORBPath.cpp b/Sources/OpenRenderBox/Path/ORBPath.cpp index eee22f7..2132037 100644 --- a/Sources/OpenRenderBox/Path/ORBPath.cpp +++ b/Sources/OpenRenderBox/Path/ORBPath.cpp @@ -142,23 +142,25 @@ ORBPath ORBPathMakeUnevenRoundedRect(CGRect rect, CGFloat topLeftRadius, CGFloat }; return path; } +#endif /* ORB_TARGET_OS_DARWIN */ -CGPathRef ORBPathCopyCGPath(ORBPath path) { - // TODO: Return a retained copy of the CGPath - return nullptr; -} - -bool ORBPathContainsPoint(ORBPath path, CGPoint point, bool eoFill) { - return ORBPathContainsPoints(path, 1, &point, eoFill, nullptr); -} - -bool ORBPathContainsPoints(ORBPath path, uint64_t count, const CGPoint *points, bool eoFill, const CGAffineTransform *transform) { - // TODO: Implement point containment testing with winding rule - return false; +bool ORBPathIsEmpty(ORBPath path) { + if (path.callbacks == &empty_path_callbacks) { + return true; + } else { + auto isEmptyCallback = path.callbacks->isEmpty; + if (isEmptyCallback) { + return isEmptyCallback(path.storage); + } else { + bool isEmpty = true; + return ORBPathApplyElements(path, &isEmpty, +[](void * info, ORBPathElement element, const CGFloat *points, const void * _Nullable userInfo) -> bool { + *((bool *)info) = false; + return false; + }); + } + } } -#endif /* ORB_TARGET_OS_DARWIN */ - bool ORBPathApplyElements(ORBPath path, void *info, ORBPathApplyCallback callback) { auto apply = path.callbacks->apply; bool flag = false; // TODO: calllbacks's flag to indicate whether it supports extra features @@ -174,3 +176,43 @@ bool ORBPathApplyElements(ORBPath path, void *info, ORBPathApplyCallback callbac return apply(path.storage, info, callback); } } + +bool ORBPathEqualToPath(ORBPath lhs, ORBPath rhs) { + if (lhs.callbacks == rhs.callbacks) { + if (lhs.storage == rhs.storage) { + return true; + } + // TODO + return false; + } else { + if (lhs.callbacks == &empty_path_callbacks) { + if (lhs.storage == ORBPathNull.storage) { + return rhs.callbacks == &empty_path_callbacks && rhs.storage == ORBPathNull.storage; + } else { + return ORBPathIsEmpty(rhs); + } + } else if (rhs.callbacks == &empty_path_callbacks) { + if (rhs.storage == ORBPathNull.storage) { + return false; + } else { + return ORBPathIsEmpty(lhs); + } + } + } +} + +#if ORB_TARGET_OS_DARWIN +CGPathRef ORBPathCopyCGPath(ORBPath path) { + // TODO: Return a retained copy of the CGPath + return nullptr; +} + +bool ORBPathContainsPoint(ORBPath path, CGPoint point, bool eoFill) { + return ORBPathContainsPoints(path, 1, &point, eoFill, nullptr); +} + +bool ORBPathContainsPoints(ORBPath path, uint64_t count, const CGPoint *points, bool eoFill, const CGAffineTransform *transform) { + // TODO: Implement point containment testing with winding rule + return false; +} +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBox/include/OpenRenderBox/ORBPath.h b/Sources/OpenRenderBox/include/OpenRenderBox/ORBPath.h index 2b7361d..67c385e 100644 --- a/Sources/OpenRenderBox/include/OpenRenderBox/ORBPath.h +++ b/Sources/OpenRenderBox/include/OpenRenderBox/ORBPath.h @@ -63,10 +63,9 @@ void ORBPathRetain(ORBPath path) ORB_SWIFT_NAME(ORBPath.retain(self:)); ORB_EXPORT void ORBPathRelease(ORBPath path) ORB_SWIFT_NAME(ORBPath.release(self:)); -#if ORB_TARGET_OS_DARWIN - // MARK: - Path Creation +#if ORB_TARGET_OS_DARWIN ORB_EXPORT ORBPath ORBPathMakeWithCGPath(CGPathRef cgPath) ORB_SWIFT_NAME(ORBPath.init(cgPath:)); @@ -81,14 +80,28 @@ ORBPath ORBPathMakeRoundedRect(CGRect rect, CGFloat cornerWidth, CGFloat cornerH ORB_EXPORT ORBPath ORBPathMakeUnevenRoundedRect(CGRect rect, CGFloat topLeftRadius, CGFloat bottomLeftRadius, CGFloat bottomRightRadius, CGFloat topRightRadius, ORBPathRoundedCornerStyle style, const CGAffineTransform * _Nullable transform) ORB_SWIFT_NAME(ORBPath.init(roundedRect:topLeftRadius:bottomLeftRadius:bottomRightRadius:topRightRadius:style:transform:)); +#endif + +// MARK: - Path Operation + +ORB_EXPORT +bool ORBPathIsEmpty(ORBPath path) ORB_SWIFT_NAME(getter:ORBPath.isEmpty(self:)); + +ORB_EXPORT +bool ORBPathApplyElements(ORBPath path, void * info, _Nullable ORBPathApplyCallback callback) ORB_SWIFT_NAME(ORBPath.apply(self:info:callback:)); + +ORB_EXPORT +bool ORBPathEqualToPath(ORBPath lhs, ORBPath rhs) ORB_SWIFT_NAME(ORBPath.isEqual(self:to:)); // MARK: - CGPath Interoperability +#if ORB_TARGET_OS_DARWIN ORB_EXPORT CGPathRef ORBPathCopyCGPath(ORBPath path) ORB_SWIFT_NAME(getter:ORBPath.cgPath(self:)); +#endif // MARK: - Point Containment - +#if ORB_TARGET_OS_DARWIN ORB_EXPORT bool ORBPathContainsPoint(ORBPath path, CGPoint point, bool eoFill) ORB_SWIFT_NAME(ORBPath.contains(self:point:eoFill:)); @@ -96,11 +109,6 @@ ORB_EXPORT bool ORBPathContainsPoints(ORBPath path, uint64_t count, const CGPoint *points, bool eoFill, const CGAffineTransform * _Nullable transform) ORB_SWIFT_NAME(ORBPath.containsPoints(self:count:points:eoFill:transform:)); #endif -// MARK: - Apply Callback - -ORB_EXPORT -bool ORBPathApplyElements(ORBPath path, void * info, _Nullable ORBPathApplyCallback callback) ORB_SWIFT_NAME(ORBPath.apply(self:info:callback:)); - ORB_EXTERN_C_END ORB_ASSUME_NONNULL_END From e0ce48cc42a211f557c74c8a3f1607df102f6108 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 27 Dec 2025 15:45:54 +0800 Subject: [PATCH 2/2] Update dependency version --- Package.resolved | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.resolved b/Package.resolved index bcbf67b..8e57171 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "e8090a2f05b2bba73e7772cde4427b3cd1bf1f0a" + "revision" : "13c32a737bf2c440d45224a3b2dc4bb7017c5038" } }, { @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-numerics", "state" : { - "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", - "version" : "1.0.2" + "revision" : "0c0290ff6b24942dadb83a929ffaaa1481df04a2", + "version" : "1.1.1" } } ],