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

#include <SweepLine.h>

Inheritance diagram for bentleyottmann::SweepLine:
bentleyottmann::SweepLineInterface

Public Member Functions

 SweepLine ()
 
void handleDeletions (Point eventPoint, const DeletionSegmentSet &removing) override
 
void handleInsertionsAndCheckForNewCrossings (Point eventPoint, const InsertionSegmentSet &inserting, EventQueueInterface *queue) override
 
- Public Member Functions inherited from bentleyottmann::SweepLineInterface
virtual ~SweepLineInterface ()=default
 

Friends

struct SweepLineTestingPeer
 

Detailed Description

Definition at line 16 of file SweepLine.h.

Constructor & Destructor Documentation

◆ SweepLine()

bentleyottmann::SweepLine::SweepLine ( )

Definition at line 18 of file SweepLine.cpp.

18 {
19 static constexpr Segment LeftSentinel = {{-std::numeric_limits<int32_t>::max(),
20 -std::numeric_limits<int32_t>::max()},
21 {-std::numeric_limits<int32_t>::max(),
22 std::numeric_limits<int32_t>::max()}};
23 static constexpr Segment RightSentinel = {{std::numeric_limits<int32_t>::max(),
24 -std::numeric_limits<int32_t>::max()},
25 {std::numeric_limits<int32_t>::max(),
26 std::numeric_limits<int32_t>::max()}};
27
28 fSweepLine.reserve(8);
29 fSweepLine.push_back(LeftSentinel);
30 fSweepLine.push_back(RightSentinel);
31}

Member Function Documentation

◆ handleDeletions()

void bentleyottmann::SweepLine::handleDeletions ( Point  eventPoint,
const DeletionSegmentSet removing 
)
overridevirtual

Implements bentleyottmann::SweepLineInterface.

Definition at line 41 of file SweepLine.cpp.

41 {
42 std::vector<Segment>::iterator newEnd;
43 if (removing.empty()) {
44 // Remove ending segments
45 auto toRemove = [eventPoint](Segment s) {
46 return s.lower() == eventPoint;
47 };
48 newEnd = std::remove_if(fSweepLine.begin(), fSweepLine.end(), toRemove);
49 } else {
50 // Remove all ending and crossing segments.
51 auto toRemove = [eventPoint, &removing](Segment s) {
52 return s.lower() == eventPoint || removing.find(s) != removing.end();
53 };
54 newEnd = std::remove_if(fSweepLine.begin(), fSweepLine.end(), toRemove);
55 }
56 fSweepLine.erase(newEnd, fSweepLine.end());
57}
struct MyStruct s

◆ handleInsertionsAndCheckForNewCrossings()

void bentleyottmann::SweepLine::handleInsertionsAndCheckForNewCrossings ( Point  eventPoint,
const InsertionSegmentSet inserting,
EventQueueInterface queue 
)
overridevirtual

Implements bentleyottmann::SweepLineInterface.

Definition at line 59 of file SweepLine.cpp.

60 {
61 // The SlopeSegmentSet makes sure that these segments are in the right order for insertion.
62 auto comp = [](const Segment& s, Point p) {
64 };
65
66 const auto rightOfInsertion = std::lower_bound(
67 fSweepLine.begin(), fSweepLine.end(), eventPoint, comp);
68 SkASSERT(rightOfInsertion != fSweepLine.begin());
69 const auto leftOfInsertion = rightOfInsertion - 1;
70
71 if (inserting.empty()) {
72 // There were deletions, but no insertions, so check if the two segments at the insertion
73 // point cross.
74 if (auto crossingPoint = intersect(*leftOfInsertion, *rightOfInsertion)) {
75 queue->addCrossing(crossingPoint.value(), *leftOfInsertion, *rightOfInsertion);
76 }
77 } else {
78 // Check if the left most inserted segment crosses the segment immediately to the left of
79 // the insertion cursor.
80 if (auto crossingPoint = intersect(*leftOfInsertion, *inserting.begin())) {
81 queue->addCrossing(crossingPoint.value(), *leftOfInsertion, *inserting.begin());
82 }
83
84 // Check if the right most inserted segment crosses the segment immediately to the right of
85 // the insertion cursor.
86 if (auto crossingPoint = intersect(*inserting.rbegin(), *rightOfInsertion)) {
87 queue->addCrossing(crossingPoint.value(), *inserting.rbegin(), *rightOfInsertion);
88 }
89
90 // Insert the set in the sweep line.
91 fSweepLine.insert(rightOfInsertion, inserting.begin(), inserting.end());
92 }
93}
#define SkASSERT(cond)
Definition SkAssert.h:116
VkQueue queue
Definition main.cc:55
bool point_less_than_segment_in_x(Point p, const Segment &segment)
Definition Segment.cpp:214
std::optional< Point > intersect(const Segment &s0, const Segment &s1)
Definition Segment.cpp:97
TPoint< Scalar > Point
Definition point.h:316

Friends And Related Symbol Documentation

◆ SweepLineTestingPeer

friend struct SweepLineTestingPeer
friend

Definition at line 27 of file SweepLine.h.


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