273 {
276
278 kBegin = 0,
281 };
282
283
284
285 struct SetupTuple {
286
287 int32_t yOrdering;
288
289
291
292
293 int32_t xTieBreaker;
294
295
296 Segment originalSegment;
297
299 return
300 std::tie(this->yOrdering, this->type, this->xTieBreaker, this->originalSegment)
301 == std::tie(r.yOrdering, r.type, r.xTieBreaker, r.originalSegment);
302 }
303 };
304
305 std::vector<SetupTuple> eventOrdering;
306 for (
const auto&
s : segments) {
307
308
309 if (
s.upper() ==
s.lower()) {
310 continue;
311 }
312
313 if (
s.isHorizontal()) {
314
315 eventOrdering.push_back(SetupTuple{
s.upper().
y, kHorizontal, -
s.upper().
x,
s});
316 } else {
317
318 eventOrdering.push_back(SetupTuple{
s.upper().
y, kBegin, -
s.upper().
x,
s});
319 eventOrdering.push_back(SetupTuple{
s.lower().
y, kEnd, -
s.lower().
x,
s});
320 }
321 }
322
323
324 auto eventLess = [](const SetupTuple& l, const SetupTuple& r) {
325 return std::tie(l.yOrdering, l.type, l.xTieBreaker) <
326 std::tie(r.yOrdering, r.type, r.xTieBreaker);
327 };
328
329
330 std::sort(eventOrdering.begin(), eventOrdering.end(), eventLess);
331
332
333 auto eraseFrom = std::unique(eventOrdering.begin(), eventOrdering.end());
334 eventOrdering.erase(eraseFrom, eventOrdering.end());
335
336 std::vector<CompactEvent> events;
337 std::vector<Segment> segmentStorage;
338 segmentStorage.reserve(eventOrdering.size());
339
340 int32_t currentY = eventOrdering.front().yOrdering;
342 endOfBegin = 0,
343 endOfHorizontal = 0,
344 endOfEnd = 0;
345 for (
const auto& [
y,
type, _,
s] : eventOrdering) {
346
348 events.push_back(CompactEvent{currentY,
350 endOfBegin,
351 endOfHorizontal,
352 endOfEnd});
353 start = endOfBegin = endOfHorizontal = endOfEnd = segmentStorage.size();
355 }
356
357 segmentStorage.push_back(
s);
358
359
360 const size_t segmentCount = segmentStorage.size();
362 case kBegin: endOfBegin = segmentCount;
363 [[fallthrough]];
365 [[fallthrough]];
366 case kEnd: endOfEnd = segmentCount;
367 }
368 }
369
370
371 events.push_back(CompactEvent{currentY,
373 endOfBegin,
374 endOfHorizontal,
375 endOfEnd});
376
377 return EventQueue{std::move(events), std::move(segmentStorage)};
378 }
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
constexpr bool empty() const
constexpr size_t size() const
std::variant< Lower, Cross, Upper > EventType
constexpr bool operator==(const Point &p0, const Point &p1)