Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
bentleyottmann::EventQueue Class Reference

#include <EventQueue.h>

Inheritance diagram for bentleyottmann::EventQueue:
bentleyottmann::EventQueueInterface

Public Types

using Queue = std::set< Event >
 

Public Member Functions

 EventQueue (Queue &&queue)
 
 EventQueue ()=default
 
void addCrossing (Point crossingPoint, const Segment &s0, const Segment &s1) override
 
bool hasMoreEvents () const
 
void handleNextEventPoint (SweepLineInterface *handler)
 
std::vector< Crossingcrossings ()
 
- Public Member Functions inherited from bentleyottmann::EventQueueInterface
 EventQueueInterface ()=default
 
 EventQueueInterface (const EventQueueInterface &)=default
 
 EventQueueInterface (EventQueueInterface &&)=default
 
EventQueueInterfaceoperator= (const EventQueueInterface &)=default
 
EventQueueInterfaceoperator= (EventQueueInterface &&)=default
 
virtual ~EventQueueInterface ()=default
 

Static Public Member Functions

static std::optional< EventQueueMake (SkSpan< const Segment > segments)
 

Friends

class EventQueueTestingPeer
 

Detailed Description

Definition at line 58 of file EventQueue.h.

Member Typedef Documentation

◆ Queue

Definition at line 63 of file EventQueue.h.

Constructor & Destructor Documentation

◆ EventQueue() [1/2]

bentleyottmann::EventQueue::EventQueue ( EventQueue::Queue &&  queue)

Definition at line 40 of file EventQueue.cpp.

40: fQueue{std::move(queue)} { }

◆ EventQueue() [2/2]

bentleyottmann::EventQueue::EventQueue ( )
default

Member Function Documentation

◆ addCrossing()

void bentleyottmann::EventQueue::addCrossing ( Point  crossingPoint,
const Segment s0,
const Segment s1 
)
overridevirtual

Implements bentleyottmann::EventQueueInterface.

Definition at line 49 of file EventQueue.cpp.

49 {
50 this->add({crossingPoint, Cross{s0, s1}});
51 fCrossings.push_back({s0, s1, crossingPoint});
52}

◆ crossings()

std::vector< Crossing > bentleyottmann::EventQueue::crossings ( )

Definition at line 125 of file EventQueue.cpp.

125 {
126 return std::vector<Crossing>{fCrossings.begin(), fCrossings.end()};
127}

◆ handleNextEventPoint()

void bentleyottmann::EventQueue::handleNextEventPoint ( SweepLineInterface handler)

Definition at line 63 of file EventQueue.cpp.

63 {
64 SkASSERT(!fQueue.empty());
65
66 // Clear temp segment buffers.
67 fDeletionSet.clear();
68 fInsertionSet.clear();
69
70 // An events that are Lower points.
71 bool hasLower = false;
72
73 // Set up the visitors for the different event types.
74 auto handleLower = [&hasLower](const Lower& l) {
75 hasLower = true;
76 };
77
78 // Crossing Segments must be deleted and re-inserted in the sweep line.
79 auto handleCross = [this](const Cross& c) {
80 fDeletionSet.insert({c.s0, c.s1});
81 fInsertionSet.insert({c.s0, c.s1});
82 };
83
84 // Upper events are added to the sweep line, and a lower event is added to the event queue.
85 auto handleUpper = [this](const Upper& u) {
86 fInsertionSet.insert(u.s);
87 // Add the delete event for the inserted segment. Make sure we are not adding more events
88 // on this eventPoint.
89 SkASSERT(u.s.lower() != u.s.upper());
90 this->add(Event{u.s.lower(), Lower{}});
91 };
92
93 Visitor visitor{handleLower, handleCross, handleUpper};
94
95 const Point eventPoint = fQueue.begin()->where;
96
97 // We must make forward progress.
98 SkASSERT(fLastEventPoint < eventPoint);
99 fLastEventPoint = eventPoint;
100
101 // Accumulate changes for all events with the same event point.
102 auto cursor = fQueue.begin();
103 const auto queueEnd = fQueue.end();
104 for (; cursor != queueEnd && cursor->where == eventPoint;
105 ++cursor) {
106 const Event& event = *cursor;
107 std::visit(visitor, event.type);
108 }
109
110 // Remove all accumulated events with the same event point.
111 fQueue.erase(fQueue.begin(), cursor);
112
113 if (hasLower || !fDeletionSet.empty()) {
114 // There are segments to delete.
115 handler->handleDeletions(eventPoint, fDeletionSet);
116 }
117
118 if (hasLower || !fDeletionSet.empty() || !fInsertionSet.empty()) {
119 // If there are insertions then insert them. If there are no insertions, but there were
120 // deletions we need to check for new crossings.
121 handler->handleInsertionsAndCheckForNewCrossings(eventPoint, fInsertionSet, this);
122 }
123}
#define SkASSERT(cond)
Definition SkAssert.h:116
FlKeyEvent * event
Visitor(Ts...) -> Visitor< Ts... >
TPoint< Scalar > Point
Definition point.h:316

◆ hasMoreEvents()

bool bentleyottmann::EventQueue::hasMoreEvents ( ) const

Definition at line 54 of file EventQueue.cpp.

54 {
55 return !fQueue.empty();
56}

◆ Make()

std::optional< EventQueue > bentleyottmann::EventQueue::Make ( SkSpan< const Segment segments)
static

Definition at line 14 of file EventQueue.cpp.

14 {
16
17 int32_t left = Point::Largest().x,
18 top = Point::Largest().y,
20 bottom = Point::Smallest().y;
21
22 for(const Segment& s : segments) {
23 auto [l, t, r, b] = s.bounds();
24 left = std::min(l, left);
25 top = std::min(t, top);
26 right = std::max(r, right);
27 bottom = std::max(b, bottom);
28
29 queue.insert(Event{s.upper(), Upper{s}});
30 }
31
32 // If min max difference is too large, fail.
33 if (Point::DifferenceTooBig(Point{left, top}, Point{right, bottom})) {
34 return std::nullopt;
35 }
36
37 return EventQueue{std::move(queue)};
38}
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
std::set< Event > Queue
Definition EventQueue.h:63
VkQueue queue
Definition main.cc:55
static bool b
struct MyStruct s
static Point Smallest()
Definition Point.cpp:36
static bool DifferenceTooBig(Point p0, Point p1)
Definition Point.cpp:46
static Point Largest()
Definition Point.cpp:41

Friends And Related Symbol Documentation

◆ EventQueueTestingPeer

friend class EventQueueTestingPeer
friend

Definition at line 77 of file EventQueue.h.


The documentation for this class was generated from the following files: