Skip to content

Commit 10a9e5d

Browse files
authored
Add ORBPathIsEmpty and Equal function API (#14)
1 parent 23af17b commit 10a9e5d

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ void ORBPathRetain(ORBPath path) ORB_SWIFT_NAME(ORBPath.retain(self:));
6363
ORB_EXPORT
6464
void ORBPathRelease(ORBPath path) ORB_SWIFT_NAME(ORBPath.release(self:));
6565

66-
#if ORB_TARGET_OS_DARWIN
67-
6866
// MARK: - Path Creation
6967

68+
#if ORB_TARGET_OS_DARWIN
7069
ORB_EXPORT
7170
ORBPath ORBPathMakeWithCGPath(CGPathRef cgPath) ORB_SWIFT_NAME(ORBPath.init(cgPath:));
7271

@@ -81,26 +80,35 @@ ORBPath ORBPathMakeRoundedRect(CGRect rect, CGFloat cornerWidth, CGFloat cornerH
8180

8281
ORB_EXPORT
8382
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:));
83+
#endif
84+
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:));
8495

8596
// MARK: - CGPath Interoperability
8697

98+
#if ORB_TARGET_OS_DARWIN
8799
ORB_EXPORT
88100
CGPathRef ORBPathCopyCGPath(ORBPath path) ORB_SWIFT_NAME(getter:ORBPath.cgPath(self:));
101+
#endif
89102

90103
// MARK: - Point Containment
91-
104+
#if ORB_TARGET_OS_DARWIN
92105
ORB_EXPORT
93106
bool ORBPathContainsPoint(ORBPath path, CGPoint point, bool eoFill) ORB_SWIFT_NAME(ORBPath.contains(self:point:eoFill:));
94107

95108
ORB_EXPORT
96109
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:));
97110
#endif
98111

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-
104112
ORB_EXTERN_C_END
105113

106114
ORB_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)