Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 56 additions & 14 deletions Sources/OpenRenderBox/Path/ORBPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
24 changes: 16 additions & 8 deletions Sources/OpenRenderBox/include/OpenRenderBox/ORBPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:));

Expand All @@ -81,26 +80,35 @@ 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:));

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