Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 47731ae

Browse files
author
Emmanuel Garcia
committed
Add additional rtree unit test
1 parent 7cc254a commit 47731ae

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

third_party/skia/platform_view_rtree_unittests.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,50 @@ TEST_F(PlatformViewRTree, JoinRectsWhenIntersectedCase2) {
141141
ASSERT_EQ(*hits[0], SkRect::MakeLTRB(50, 50, 500, 250));
142142
}
143143

144+
TEST_F(PlatformViewRTree, JoinRectsWhenIntersectedCase3) {
145+
auto r_tree = sk_make_sp<FlutterRTree>();
146+
auto rtree_factory = FlutterRTreeFactory(r_tree);
147+
auto recorder = std::make_unique<SkPictureRecorder>();
148+
auto recording_canvas = recorder->beginRecording(SkRect::MakeIWH(1000, 1000), &rtree_factory);
149+
150+
auto rect_paint = SkPaint();
151+
rect_paint.setColor(SkColors::kCyan);
152+
rect_paint.setStyle(SkPaint::Style::kFill_Style);
153+
154+
// Given the A, B, C and D rects that intersect with the query rect,
155+
// there should be only D in the result vector,
156+
// since A, B, and C are contained in C.
157+
//
158+
// +------------------------------+
159+
// | D |
160+
// | +-----+ +-----+ +-----+ |
161+
// | | A | | B | | C | |
162+
// | +-----+ +-----+ +-----+ |
163+
// +------------------------------+
164+
// +-----+
165+
// | E |
166+
// +-----+
167+
168+
// A
169+
recording_canvas->drawRect(SkRect::MakeLTRB(100, 100, 200, 200), rect_paint);
170+
// B
171+
recording_canvas->drawRect(SkRect::MakeLTRB(300, 100, 400, 200), rect_paint);
172+
// C
173+
recording_canvas->drawRect(SkRect::MakeLTRB(500, 100, 600, 300), rect_paint);
174+
// D
175+
recording_canvas->drawRect(SkRect::MakeLTRB(50, 50, 620, 250), rect_paint);
176+
// E
177+
recording_canvas->drawRect(SkRect::MakeLTRB(280, 100, 280, 320), rect_paint);
178+
179+
recorder->finishRecordingAsPicture();
180+
181+
auto query = SkRect::MakeLTRB(30, 30, 550, 270);
182+
auto hits = std::vector<SkRect*>();
183+
184+
r_tree->searchRects(query, &hits);
185+
ASSERT_EQ(1UL, hits.size());
186+
ASSERT_EQ(*hits[0], SkRect::MakeLTRB(50, 50, 620, 250));
187+
}
188+
144189
} // namespace testing
145190
} // namespace flutter

0 commit comments

Comments
 (0)