Flutter Engine
The Flutter Engine
EventQueue.h
Go to the documentation of this file.
1// Copyright 2023 Google LLC
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
4#ifndef EventQueue_DEFINED
5#define EventQueue_DEFINED
6
11
12#include <optional>
13#include <set>
14#include <tuple>
15#include <variant>
16#include <vector>
17
18namespace bentleyottmann {
19
20struct Lower {
21 // All Lowers are equal.
22 friend bool operator< (const Lower&, const Lower&) {
23 return false;
24 }
25};
26
27struct Upper {
29
30 // Arbitrary comparison for queue uniqueness.
31 friend bool operator< (const Upper& u0, const Upper& u1) {
32 return std::tie(u0.s.p0, u0.s.p1) < std::tie(u1.s.p0, u1.s.p1);
33 }
34};
35
36struct Cross {
39
40 // Arbitrary comparison for queue uniqueness.
41 friend bool operator< (const Cross& c0, const Cross& c1) {
42 return std::tie(c0.s0.p0, c0.s0.p1, c0.s1.p0, c0.s1.p1) <
43 std::tie(c1.s0.p0, c1.s0.p1, c1.s1.p0, c1.s1.p1);
44 }
45};
46
47using EventType = std::variant<Lower, Cross, Upper>;
48
49struct Event {
52
53 friend bool operator< (const Event& e0, const Event& e1) {
54 return std::tie(e0.where, e0.type) < std::tie(e1.where, e1.type);
55 }
56};
57
59public:
60 // Queue ordered by Event where the point is the most important followed by type and then
61 // contents of the event. The ordering of the contents of the event is arbitrary but need to
62 // enforce uniqueness of the events in the queue.
63 using Queue = std::set<Event>;
64
65 static std::optional<EventQueue> Make(SkSpan<const Segment> segments);
66
68 EventQueue() = default;
69
70 void addCrossing(Point crossingPoint, const Segment& s0, const Segment& s1) override;
71
72 bool hasMoreEvents() const;
74 std::vector<Crossing> crossings();
75
76private:
78 Point fLastEventPoint = Point::Smallest();
79
80 void add(const Event& e);
81
82 DeletionSegmentSet fDeletionSet;
83 InsertionSegmentSet fInsertionSet;
84 Queue fQueue;
85 std::vector<Crossing> fCrossings;
86};
87} // namespace bentleyottmann
88#endif // EventQueue_DEFINED
float e1
float e0
std::vector< Crossing > crossings()
Definition: EventQueue.cpp:125
void addCrossing(Point crossingPoint, const Segment &s0, const Segment &s1) override
Definition: EventQueue.cpp:49
std::set< Event > Queue
Definition: EventQueue.h:63
void handleNextEventPoint(SweepLineInterface *handler)
Definition: EventQueue.cpp:63
static std::optional< EventQueue > Make(SkSpan< const Segment > segments)
Definition: EventQueue.cpp:14
VkQueue queue
Definition: main.cc:55
std::set< Segment, OrderBySlope > InsertionSegmentSet
std::set< Segment > DeletionSegmentSet
std::variant< Lower, Cross, Upper > EventType
Definition: EventQueue.h:47
friend bool operator<(const Cross &c0, const Cross &c1)
Definition: EventQueue.h:41
friend bool operator<(const Event &e0, const Event &e1)
Definition: EventQueue.h:53
friend bool operator<(const Lower &, const Lower &)
Definition: EventQueue.h:22
static Point Smallest()
Definition: Point.cpp:36
friend bool operator<(const Upper &u0, const Upper &u1)
Definition: EventQueue.h:31