Skip to content
Open
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
9 changes: 8 additions & 1 deletion packages/skia/cpp/api/JsiSkRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ class JsiSkRect : public JsiSkWrappingSharedPtrHostObject<SkRect> {
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(intersects) {
auto otherRect = JsiSkRect::fromValue(runtime, arguments[0]);
bool result = getObject()->intersects(*otherRect);
return jsi::Value(result);
}

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRect, setXYWH),
JSI_EXPORT_FUNC(JsiSkRect, setLTRB),
JSI_EXPORT_FUNC(JsiSkRect, dispose))
JSI_EXPORT_FUNC(JsiSkRect, dispose),
JSI_EXPORT_FUNC(JsiSkRect, intersects))

/**
Constructor
Expand Down
6 changes: 6 additions & 0 deletions packages/skia/src/skia/types/Rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface SkRect {

export interface SkHostRect extends SkRect, SkJSIInstance<"Rect"> {
setXYWH(x: number, y: number, width: number, height: number): void;
intersects(other: SkRect): boolean;
}

export const isRect = (def: unknown): def is SkRect => {
Expand All @@ -24,3 +25,8 @@ export const isRect = (def: unknown): def is SkRect => {
}
return false;
};

export const intersects = (rectA: SkRect, rectB: SkRect): boolean =>{
'worklet';
return (rectA as SkHostRect).intersects(rectB);
}
10 changes: 10 additions & 0 deletions packages/skia/src/skia/web/JsiSkRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export class JsiSkRect
this.ref[3] = y + height;
}


intersects(other: SkRect): boolean {
return (
this.x < other.x + other.width &&
this.x + this.width > other.x &&
this.y < other.y + other.height &&
this.y + this.height > other.y
);
}

get x() {
return this.ref[0];
}
Expand Down
Loading