Skip to content

Commit be93d3f

Browse files
committed
Add ORBPathIsEmpty and Equal function API
1 parent 23af17b commit be93d3f

File tree

2 files changed

+67
-19
lines changed

2 files changed

+67
-19
lines changed

Sources/OpenRenderBox/Path/ORBPath.cpp

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,25 @@ ORBPath ORBPathMakeUnevenRoundedRect(CGRect rect, CGFloat topLeftRadius, CGFloat
142142
};
143143
return path;
144144
}
145+
#endif /* ORB_TARGET_OS_DARWIN */
145146

146-
CGPathRef ORBPathCopyCGPath(ORBPath path) {
147-
// TODO: Return a retained copy of the CGPath
148-
return nullptr;
149-
}
150-
151-
bool ORBPathContainsPoint(ORBPath path, CGPoint point, bool eoFill) {
152-
return ORBPathContainsPoints(path, 1, &point, eoFill, nullptr);
153-
}
154-
155-
bool ORBPathContainsPoints(ORBPath path, uint64_t count, const CGPoint *points, bool eoFill, const CGAffineTransform *transform) {
156-
// TODO: Implement point containment testing with winding rule
157-
return false;
147+
bool ORBPathIsEmpty(ORBPath path) {
148+
if (path.callbacks == &empty_path_callbacks) {
149+
return true;
150+
} else {
151+
auto isEmptyCallback = path.callbacks->isEmpty;
152+
if (isEmptyCallback) {
153+
return isEmptyCallback(path.storage);
154+
} else {
155+
bool isEmpty = true;
156+
return ORBPathApplyElements(path, &isEmpty, +[](void * info, ORBPathElement element, const CGFloat *points, const void * _Nullable userInfo) -> bool {
157+
*((bool *)info) = false;
158+
return false;
159+
});
160+
}
161+
}
158162
}
159163

160-
#endif /* ORB_TARGET_OS_DARWIN */
161-
162164
bool ORBPathApplyElements(ORBPath path, void *info, ORBPathApplyCallback callback) {
163165
auto apply = path.callbacks->apply;
164166
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
174176
return apply(path.storage, info, callback);
175177
}
176178
}
179+
180+
bool ORBPathEqualToPath(ORBPath lhs, ORBPath rhs) {
181+
if (lhs.callbacks == rhs.callbacks) {
182+
if (lhs.storage == rhs.storage) {
183+
return true;
184+
}
185+
// TODO
186+
return false;
187+
} else {
188+
if (lhs.callbacks == &empty_path_callbacks) {
189+
if (lhs.storage == ORBPathNull.storage) {
190+
return rhs.callbacks == &empty_path_callbacks && rhs.storage == ORBPathNull.storage;
191+
} else {
192+
return ORBPathIsEmpty(rhs);
193+
}
194+
} else if (rhs.callbacks == &empty_path_callbacks) {
195+
if (rhs.storage == ORBPathNull.storage) {
196+
return false;
197+
} else {
198+
return ORBPathIsEmpty(lhs);
199+
}
200+
}
201+
}
202+
}
203+
204+
#if ORB_TARGET_OS_DARWIN
205+
CGPathRef ORBPathCopyCGPath(ORBPath path) {
206+
// TODO: Return a retained copy of the CGPath
207+
return nullptr;
208+
}
209+
210+
bool ORBPathContainsPoint(ORBPath path, CGPoint point, bool eoFill) {
211+
return ORBPathContainsPoints(path, 1, &point, eoFill, nullptr);
212+
}
213+
214+
bool ORBPathContainsPoints(ORBPath path, uint64_t count, const CGPoint *points, bool eoFill, const CGAffineTransform *transform) {
215+
// TODO: Implement point containment testing with winding rule
216+
return false;
217+
}
218+
#endif /* ORB_TARGET_OS_DARWIN */

Sources/OpenRenderBox/include/OpenRenderBox/ORBPath.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ ORBPath ORBPathMakeRoundedRect(CGRect rect, CGFloat cornerWidth, CGFloat cornerH
8282
ORB_EXPORT
8383
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:));
8484

85+
// MARK: - Path Operation
86+
87+
ORB_EXPORT
88+
bool ORBPathIsEmpty(ORBPath path) ORB_SWIFT_NAME(getter:ORBPath.isEmpty(self:));
89+
90+
ORB_EXPORT
91+
bool ORBPathApplyElements(ORBPath path, void * info, _Nullable ORBPathApplyCallback callback) ORB_SWIFT_NAME(ORBPath.apply(self:info:callback:));
92+
93+
ORB_EXPORT
94+
bool ORBPathEqualToPath(ORBPath lhs, ORBPath rhs) ORB_SWIFT_NAME(ORBPath.isEqual(self:to:));
95+
8596
// MARK: - CGPath Interoperability
8697

8798
ORB_EXPORT
@@ -96,11 +107,6 @@ ORB_EXPORT
96107
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:));
97108
#endif
98109

99-
// MARK: - Apply Callback
100-
101-
ORB_EXPORT
102-
bool ORBPathApplyElements(ORBPath path, void * info, _Nullable ORBPathApplyCallback callback) ORB_SWIFT_NAME(ORBPath.apply(self:info:callback:));
103-
104110
ORB_EXTERN_C_END
105111

106112
ORB_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)