contrek 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -3
  3. data/CHANGELOG.md +21 -0
  4. data/Gemfile.lock +4 -4
  5. data/README.md +34 -30
  6. data/Rakefile +3 -0
  7. data/contrek.gemspec +7 -4
  8. data/ext/cpp_polygon_finder/PolygonFinder/Makefile +44 -0
  9. data/ext/cpp_polygon_finder/PolygonFinder/images/sample_10240x10240.png +0 -0
  10. data/ext/cpp_polygon_finder/PolygonFinder/src/Main.cpp +14 -5
  11. data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.cpp +136 -15
  12. data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.h +5 -4
  13. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/CpuTimer.h +44 -0
  14. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.cpp +8 -0
  15. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/Bitmap.h +3 -4
  16. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.cpp +63 -573
  17. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.h +17 -18
  18. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.cpp +22 -5
  19. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/RemoteFastPngBitmap.h +4 -8
  20. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/spng.c +6980 -0
  21. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/spng.h +537 -0
  22. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/FinderUtils.cpp +101 -0
  23. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/FinderUtils.h +16 -0
  24. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.cpp +0 -3
  25. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/List.h +4 -7
  26. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.cpp +13 -13
  27. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Lists.h +5 -7
  28. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.cpp +47 -41
  29. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Node.h +15 -10
  30. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.cpp +181 -178
  31. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/NodeCluster.h +19 -20
  32. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/Polygon.h +20 -0
  33. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.cpp +52 -137
  34. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.h +85 -16
  35. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/RectBounds.h +39 -0
  36. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/ClippedPolygonFinder.cpp +14 -0
  37. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/ClippedPolygonFinder.h +17 -0
  38. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.cpp +117 -0
  39. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.h +32 -0
  40. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.cpp +344 -0
  41. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.h +46 -0
  42. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/EndPoint.cpp +14 -0
  43. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/EndPoint.h +22 -0
  44. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/FakeCluster.cpp +13 -0
  45. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/FakeCluster.h +17 -0
  46. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Finder.cpp +138 -0
  47. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Finder.h +52 -0
  48. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Hub.cpp +23 -0
  49. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Hub.h +40 -0
  50. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.cpp +70 -0
  51. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.h +47 -0
  52. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/PartPool.cpp +24 -0
  53. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/PartPool.h +23 -0
  54. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.cpp +182 -0
  55. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.h +30 -0
  56. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.cpp +108 -0
  57. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.h +52 -0
  58. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Poolable.cpp +59 -0
  59. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Poolable.h +52 -0
  60. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Position.cpp +31 -0
  61. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Position.h +25 -0
  62. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Queue.h +36 -0
  63. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Queueable.h +230 -0
  64. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Sequence.cpp +35 -0
  65. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Sequence.h +20 -0
  66. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Shape.cpp +26 -0
  67. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Shape.h +23 -0
  68. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.cpp +105 -0
  69. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.h +56 -0
  70. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.cpp +3 -3
  71. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/Matcher.h +5 -8
  72. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBMatcher.h +3 -7
  73. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.cpp +2 -2
  74. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/RGBNotMatcher.h +4 -8
  75. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.cpp +2 -2
  76. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/matchers/ValueNotMatcher.h +3 -7
  77. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.cpp +23 -15
  78. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/LinearReducer.h +6 -8
  79. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.cpp +2 -5
  80. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/Reducer.h +4 -8
  81. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.cpp +9 -12
  82. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/UniqReducer.h +3 -7
  83. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.cpp +26 -27
  84. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.h +76 -87
  85. data/ext/cpp_polygon_finder/cpp_polygon_finder.cpp +64 -32
  86. data/ext/cpp_polygon_finder/extconf.rb +14 -0
  87. data/lib/contrek/bitmaps/sample_generator.rb +56 -0
  88. data/lib/contrek/cpp/cpp_concurrent_finder.rb +9 -0
  89. data/lib/contrek/finder/bounds.rb +17 -0
  90. data/lib/contrek/finder/concurrent/cluster.rb +2 -2
  91. data/lib/contrek/finder/concurrent/cursor.rb +8 -8
  92. data/lib/contrek/finder/concurrent/finder.rb +10 -9
  93. data/lib/contrek/finder/concurrent/part.rb +2 -2
  94. data/lib/contrek/finder/concurrent/partitionable.rb +1 -1
  95. data/lib/contrek/finder/concurrent/polyline.rb +17 -15
  96. data/lib/contrek/finder/concurrent/sequence.rb +11 -0
  97. data/lib/contrek/finder/concurrent/tile.rb +3 -3
  98. data/lib/contrek/finder/node_cluster.rb +16 -8
  99. data/lib/contrek/finder/polygon_finder.rb +1 -4
  100. data/lib/contrek/version.rb +1 -1
  101. data/lib/contrek.rb +9 -1
  102. metadata +62 -15
  103. data/ext/cpp_polygon_finder/PolygonFinder/.cproject +0 -136
  104. data/ext/cpp_polygon_finder/PolygonFinder/.project +0 -27
  105. data/ext/cpp_polygon_finder/PolygonFinder/.settings/org.eclipse.ltk.core.refactoring.prefs +0 -2
  106. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.cpp +0 -48
  107. data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/PngBitmap.h +0 -32
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Position.cpp
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+ #include <iostream>
9
+ #include "Position.h"
10
+ #include "Hub.h"
11
+
12
+ Position::Position(Hub* hub, Point* point)
13
+ : QNode<Point>(point)
14
+ { int key = point->y * hub->width() + point->x;
15
+ EndPoint* existing_ep = hub->get(key);
16
+ if (existing_ep == nullptr)
17
+ { end_point_ = hub->spawn_end_point();
18
+ hub->put(key, end_point_);
19
+ } else {
20
+ end_point_ = existing_ep;
21
+ }
22
+ }
23
+
24
+ void Position::before_rem(Queueable<Point>* q) {
25
+ auto& queues = this->end_point_->queues();
26
+ queues.erase(std::remove(queues.begin(), queues.end(), q), queues.end());
27
+ }
28
+
29
+ void Position::after_add(Queueable<Point>* q) {
30
+ this->end_point_->queues().push_back(q);
31
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Position.h
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #pragma once
10
+ #include "Queueable.h"
11
+ #include "../Node.h"
12
+ #include "EndPoint.h"
13
+ #include "Hub.h"
14
+
15
+ class EndPoint;
16
+ class Hub;
17
+ class Position : public QNode<Point>{
18
+ public:
19
+ explicit Position(Hub* hub, Point* point);
20
+ const EndPoint* end_point() const { return end_point_; }
21
+ void before_rem(Queueable<Point>* q) override;
22
+ void after_add(Queueable<Point>* q) override;
23
+ private:
24
+ EndPoint* end_point_;
25
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Queue.h
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #pragma once
10
+ #include <queue>
11
+ #include <mutex>
12
+ #include <condition_variable>
13
+ #include <utility>
14
+
15
+ template <typename T>
16
+ class Queue {
17
+ public:
18
+ void queue_push(T value) {
19
+ std::lock_guard<std::mutex> lock(mutex_);
20
+ queue_.push(value);
21
+ cond_.notify_one();
22
+ }
23
+
24
+ T queue_pop() {
25
+ std::unique_lock<std::mutex> lock(mutex_);
26
+ cond_.wait(lock, [this]{ return !queue_.empty(); });
27
+ T value = queue_.front();
28
+ queue_.pop();
29
+ return value;
30
+ }
31
+
32
+ private:
33
+ std::queue<T> queue_;
34
+ std::mutex mutex_;
35
+ std::condition_variable cond_;
36
+ };
@@ -0,0 +1,230 @@
1
+ /*
2
+ * Queueable.h
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #pragma once
10
+ #include <vector>
11
+ #include <list>
12
+ #include <functional>
13
+ #include <stdexcept>
14
+ #include <iostream>
15
+
16
+ template <typename T>
17
+ class Queueable;
18
+
19
+ template <typename T>
20
+ class QNode {
21
+ public:
22
+ T* payload;
23
+ QNode<T>* next {nullptr};
24
+ QNode<T>* prev {nullptr};
25
+ Queueable<T>* owner {nullptr};
26
+ explicit QNode(T* value) : payload(value) {}
27
+ virtual ~QNode() = default;
28
+ virtual void before_rem(Queueable<T>* q) {}
29
+ virtual void after_add(Queueable<T>* q) {}
30
+ };
31
+
32
+
33
+ template <typename T>
34
+ class Queueable {
35
+ public:
36
+ QNode<T>* head {nullptr};
37
+ QNode<T>* tail {nullptr};
38
+ QNode<T>* _iterator {nullptr};
39
+ bool _started = false;
40
+ size_t size {0};
41
+ Queueable() = default;
42
+ virtual ~Queueable() = default;
43
+
44
+ QNode<T>* rem(QNode<T>* node) {
45
+ if (!node) return nullptr;
46
+ if (node->owner != this)
47
+ throw std::runtime_error("Not my node");
48
+ node->before_rem(this);
49
+ if (node->prev) node->prev->next = node->next;
50
+ if (node->next) node->next->prev = node->prev;
51
+ if (node == head) head = node->next;
52
+ if (node == tail) tail = node->prev;
53
+ node->next = nullptr;
54
+ node->prev = nullptr;
55
+ node->owner = nullptr;
56
+ if (size > 0) size--;
57
+ return node;
58
+ }
59
+
60
+ void add(QNode<T>* node) {
61
+ if (!node) return;
62
+ if (node->owner)
63
+ node->owner->rem(node);
64
+ if (tail) {
65
+ tail->next = node;
66
+ node->prev = tail;
67
+ } else {
68
+ head = node;
69
+ node->prev = nullptr;
70
+ }
71
+ tail = node;
72
+ node->next = nullptr;
73
+ node->owner = this;
74
+ size++;
75
+ node->after_add(this);
76
+ }
77
+
78
+ void reset() {
79
+ head = nullptr;
80
+ tail = nullptr;
81
+ _iterator = nullptr;
82
+ size = 0;
83
+ }
84
+
85
+ void replace(Queueable<T>& q) {
86
+ reset();
87
+ append(q);
88
+ }
89
+
90
+ void append(Queueable<T>& q) {
91
+ if (q.size == 0) return;
92
+ QNode<T>* current = q.head;
93
+ while (current) {
94
+ current->before_rem(&q);
95
+ current->owner = this;
96
+ current = current->next;
97
+ }
98
+ if (tail) {
99
+ tail->next = q.head;
100
+ q.head->prev = tail;
101
+ } else {
102
+ head = q.head;
103
+ }
104
+ tail = q.tail;
105
+ size += q.size;
106
+ q.reset();
107
+ each([&](QNode<T>* n) -> bool {
108
+ n->after_add(this);
109
+ return(true);
110
+ });
111
+ }
112
+
113
+ void rewind() {
114
+ _iterator = nullptr;
115
+ _started = false;
116
+ }
117
+
118
+ QNode<T>* iterator() const {
119
+ if (!_started) return head;
120
+ return _iterator;
121
+ }
122
+
123
+ void forward() {
124
+ if (!_started)
125
+ { _iterator = head ? head->next : nullptr;
126
+ _started = true;
127
+ } else if (_iterator) {
128
+ _iterator = _iterator->next;
129
+ }
130
+ }
131
+
132
+ void next_of(QNode<T>* node) {
133
+ if (!node) throw std::runtime_error("nil node");
134
+ if (node->owner != this) throw std::runtime_error("wrong node");
135
+ _iterator = node->next;
136
+ _started = true;
137
+ }
138
+
139
+ template<typename Func>
140
+ void each(Func func) {
141
+ QNode<T>* current = head;
142
+ while (current) {
143
+ if (!func(current)) break;
144
+ current = current->next;
145
+ }
146
+ }
147
+
148
+ template<typename Func>
149
+ void reverse_each(Func func) {
150
+ QNode<T>* current = tail;
151
+ while (current) {
152
+ if (!func(current)) break;
153
+ current = current->prev;
154
+ }
155
+ }
156
+
157
+ template<typename Func>
158
+ void move_from(Queueable<T>& queueable, Func func) {
159
+ queueable.rewind();
160
+ while (QNode<T>* node = queueable.iterator())
161
+ { queueable.forward();
162
+ if (func(node)) add(node);
163
+ }
164
+ }
165
+
166
+ std::vector<T*> to_vector() const {
167
+ std::vector<T*> out;
168
+ QNode<T>* current = head;
169
+ while (current) {
170
+ out.push_back(current->payload);
171
+ current = current->next;
172
+ }
173
+ return out;
174
+ }
175
+
176
+ std::vector<T> map(std::function<T(QNode<T>*)> fn) {
177
+ std::vector<T> out;
178
+ each([&](QNode<T>* n){
179
+ out.push_back(fn(n));
180
+ });
181
+ return out;
182
+ }
183
+
184
+ bool intersection_with_array(const std::vector<T*>& array) {
185
+ if (array.empty() || size == 0) return false;
186
+
187
+ QNode<T>* current = head;
188
+ while (current) {
189
+ if (current->payload) {
190
+ for (T* item : array) {
191
+ if (item && *item == *(current->payload)) {
192
+ return true;
193
+ }
194
+ }
195
+ }
196
+ current = current->next;
197
+ }
198
+ return false;
199
+ }
200
+
201
+ QNode<T>* pop() {
202
+ if (!tail) return nullptr;
203
+ return rem(tail);
204
+ }
205
+
206
+ bool contains(const T& value) const {
207
+ QNode<T>* current = head;
208
+ while (current) {
209
+ if (current->payload == value)
210
+ return true;
211
+ current = current->next;
212
+ }
213
+ return false;
214
+ }
215
+
216
+ std::vector<T*> remove_adjacent_pairs(const std::vector<T*>& input = {}) const {
217
+ const std::vector<T*>& source = input.empty() ? to_vector() : input;
218
+ std::vector<T*> result;
219
+ result.reserve(source.size());
220
+
221
+ for (T* current : source) {
222
+ if (!result.empty() && *result.back() == *current) {
223
+ result.pop_back(); // "Annulla" la coppia invece di ricominciare
224
+ } else {
225
+ result.push_back(current);
226
+ }
227
+ }
228
+ return result;
229
+ }
230
+ };
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Sequence.cpp
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #include <string>
10
+ #include "Sequence.h"
11
+
12
+ std::string Sequence::toString() {
13
+ std::string retme = "";
14
+ this->each([&](QNode<Point>* pos) -> bool {
15
+ retme += pos->payload->toString();
16
+ return true;
17
+ });
18
+ return(retme);
19
+ }
20
+
21
+ bool Sequence::is_not_vertical()
22
+ { if (this->size < 2) {
23
+ return false;
24
+ }
25
+ int x0 = head->payload->x;
26
+ this->rewind();
27
+
28
+ while (QNode<Point>* position = this->iterator())
29
+ { if (position->payload->x != x0) {
30
+ return true;
31
+ }
32
+ this->forward();
33
+ }
34
+ return false;
35
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Sequence.h
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #pragma once
10
+ #include <string>
11
+ #include "Queueable.h"
12
+ #include "../Node.h"
13
+ #include "Position.h"
14
+
15
+ class Sequence : public Queueable<Point>{
16
+ public:
17
+ Sequence() {}
18
+ std::string toString();
19
+ bool is_not_vertical();
20
+ };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Shape.cpp
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #include <list>
10
+ #include "Shape.h"
11
+ #include "Polyline.h"
12
+
13
+ Shape::Shape(Polyline* outer_polyline, const std::list<std::vector<Point*>>& inner_polylines)
14
+ : outer_polyline(outer_polyline),
15
+ inner_polylines(inner_polylines) {
16
+ }
17
+
18
+ Shape::~Shape() {
19
+ if (outer_polyline) {
20
+ delete outer_polyline;
21
+ }
22
+ }
23
+
24
+ void Shape::clear_inner() {
25
+ inner_polylines.clear();
26
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Shape.h
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #pragma once
10
+ #include <list>
11
+ #include <iostream>
12
+ #include <vector>
13
+
14
+ class Point;
15
+ class Polyline;
16
+ class Shape {
17
+ public:
18
+ Shape(Polyline* outer_polyline, const std::list<std::vector<Point*>>& inner_polylines);
19
+ virtual ~Shape();
20
+ Polyline* outer_polyline = nullptr;
21
+ std::list<std::vector<Point*>> inner_polylines;
22
+ void clear_inner();
23
+ };
@@ -0,0 +1,105 @@
1
+ /*
2
+ * Tile.cpp
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+
9
+ #include <string>
10
+ #include <iostream>
11
+ #include <list>
12
+ #include <utility>
13
+ #include "Tile.h"
14
+ #include "Shape.h"
15
+ #include "Polyline.h"
16
+
17
+ class Shape;
18
+ class Polyline;
19
+
20
+ Tile::Tile(Finder *finder, int start_x, int end_x, std::string name, const Benchmarks& b)
21
+ : finder(finder),
22
+ start_x_(start_x),
23
+ end_x_(end_x),
24
+ name_(name),
25
+ benchmarks(b) {
26
+ }
27
+
28
+ Tile::~Tile() {
29
+ for (Shape* shape : shapes_) {
30
+ delete shape;
31
+ }
32
+ shapes_.clear();
33
+ }
34
+
35
+ bool Tile::whole() {
36
+ return(start_x_ == 0 && end_x_ == finder->maximum_width());
37
+ }
38
+
39
+ bool Tile::left() {
40
+ return(start_x_ == 0);
41
+ }
42
+
43
+ bool Tile::right() {
44
+ return(end_x_ == finder->maximum_width());
45
+ }
46
+
47
+ void Tile::initial_process(ClippedPolygonFinder *finder) {
48
+ this->assign_raw_polygons(finder->get_cluster()->polygons);
49
+ }
50
+
51
+ void Tile::assign_raw_polygons(const std::list<Polygon>& raw_polylines) {
52
+ for (const auto& raw_polyline : raw_polylines)
53
+ { if (raw_polyline.bounds.width() > 0)
54
+ { Polyline* polyline = new Polyline(this, raw_polyline.outer, raw_polyline.bounds);
55
+ { Shape* shape = new Shape(polyline, raw_polyline.inner);
56
+ polyline->shape = shape;
57
+ this->shapes_.push_back(shape);
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ void Tile::assign_shapes(std::list<Shape*>& shapes) {
64
+ for (Shape *shape : shapes) {
65
+ shape->outer_polyline->tile = this;
66
+ }
67
+ this->shapes_ = shapes;
68
+ }
69
+
70
+ bool Tile::tg_border(const Point& coord) {
71
+ return( coord.x == (this->next == nullptr ? start_x_ : (end_x_ - 1)));
72
+ }
73
+
74
+ void Tile::info() {
75
+ std::cout << "TILE name=" << name_ << " start_x=" << start_x_ << " end_x=" << end_x_ << std::endl;
76
+ }
77
+
78
+ const std::list<Shape*>& Tile::boundary_shapes()
79
+ { if (!boundary_shapes_initialized_)
80
+ { for (Shape* s : shapes_)
81
+ { if (s->outer_polyline->boundary())
82
+ { boundary_shapes_.push_back(s);
83
+ }
84
+ }
85
+ boundary_shapes_initialized_ = true;
86
+ }
87
+ return boundary_shapes_;
88
+ }
89
+
90
+ std::list<Polygon> Tile::to_raw_polygons()
91
+ { std::list<Polygon> retme;
92
+ for (Shape* s : shapes_)
93
+ { if (s->outer_polyline && !s->outer_polyline->is_empty())
94
+ { Polygon poly;
95
+ poly.outer = s->outer_polyline->raw();
96
+ if (!s->inner_polylines.empty()) {
97
+ for (auto inner : s->inner_polylines) {
98
+ poly.inner.push_back(inner);
99
+ }
100
+ }
101
+ retme.push_back(std::move(poly));
102
+ }
103
+ }
104
+ return(retme);
105
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Tile.h
3
+ *
4
+ * Created on: 23 nov 2025
5
+ * Author: ema
6
+ * Copyright 2025 Emanuele Cesaroni
7
+ */
8
+ #pragma once
9
+ #include <string>
10
+ #include <list>
11
+ #include "Finder.h"
12
+ #include "ClippedPolygonFinder.h"
13
+
14
+ class Finder;
15
+ class Cluster;
16
+ class Shape;
17
+
18
+ struct Benchmarks {
19
+ double outer;
20
+ double inner;
21
+ };
22
+
23
+ class Tile {
24
+ private:
25
+ Finder *finder;
26
+ int start_x_;
27
+ int end_x_;
28
+ std::string name_;
29
+ std::list<Shape*> shapes_;
30
+ std::list<Shape*> boundary_shapes_;
31
+ bool boundary_shapes_initialized_ = false;
32
+ void assign_raw_polygons(const std::list<Polygon>& raw_polylines);
33
+
34
+ public:
35
+ Tile(Finder *finder, int start_x, int end_x, std::string name, const Benchmarks& b);
36
+ virtual ~Tile();
37
+ Tile *prev = nullptr;
38
+ Tile *next = nullptr;
39
+ Tile* circular_next = nullptr;
40
+ Cluster *cluster = nullptr;
41
+ int start_x() const { return start_x_; }
42
+ int end_x() const { return end_x_; }
43
+ std::string name() const { return name_; }
44
+ const std::list<Shape*>& shapes() const { return shapes_; }
45
+ std::list<Shape*>& shapes() { return shapes_; }
46
+ const std::list<Shape*>& boundary_shapes();
47
+ bool whole();
48
+ bool left();
49
+ bool right();
50
+ void initial_process(ClippedPolygonFinder *finder);
51
+ void info();
52
+ bool tg_border(const Point& coord);
53
+ void assign_shapes(std::list<Shape*>& shapes);
54
+ std::list<Polygon> to_raw_polygons();
55
+ Benchmarks benchmarks;
56
+ };
@@ -8,16 +8,16 @@
8
8
 
9
9
  #include "Matcher.h"
10
10
  #include <iostream>
11
- Matcher::Matcher(char value) {
11
+ Matcher::Matcher(unsigned int value) {
12
12
  this->value = value;
13
13
  }
14
14
 
15
15
  Matcher::~Matcher() {
16
16
  }
17
17
 
18
- bool Matcher::match(char value) {
18
+ bool Matcher::match(unsigned int value) {
19
19
  return(this->value == value);
20
20
  }
21
- bool Matcher::unmatch(char value) {
21
+ bool Matcher::unmatch(unsigned int value) {
22
22
  return(!match(value));
23
23
  }
@@ -6,18 +6,15 @@
6
6
  * Copyright 2025 Emanuele Cesaroni
7
7
  */
8
8
 
9
- #ifndef POLYGON_MATCHERS_MATCHER_H_
10
- #define POLYGON_MATCHERS_MATCHER_H_
9
+ #pragma once
11
10
 
12
11
  class Matcher {
13
12
  protected:
14
- char value;
13
+ unsigned int value;
15
14
 
16
15
  public:
17
- Matcher(char value);
18
- virtual bool match(char value);
19
- virtual bool unmatch(char value);
16
+ explicit Matcher(unsigned int value);
17
+ virtual bool match(unsigned int value);
18
+ virtual bool unmatch(unsigned int value);
20
19
  virtual ~Matcher();
21
20
  };
22
-
23
- #endif /* POLYGON_MATCHERS_MATCHER_H_ */
@@ -6,18 +6,14 @@
6
6
  * Copyright 2025 Emanuele Cesaroni
7
7
  */
8
8
 
9
- #ifndef POLYGON_MATCHERS_RGBMATCHER_H_
10
- #define POLYGON_MATCHERS_RGBMATCHER_H_
11
-
9
+ #pragma once
12
10
  #include "Matcher.h"
13
11
 
14
12
  class RGBMatcher : public Matcher {
15
13
  public:
16
- RGBMatcher(unsigned int rgb_value);
14
+ explicit RGBMatcher(unsigned int rgb_value);
17
15
  virtual ~RGBMatcher();
18
- bool match(unsigned int value);
16
+ bool match(unsigned int value) override;
19
17
  private:
20
18
  unsigned int rgb_value;
21
19
  };
22
-
23
- #endif /* POLYGON_MATCHERS_RGBMATCHER_H_ */
@@ -8,13 +8,13 @@
8
8
 
9
9
  #include "RGBNotMatcher.h"
10
10
  #include <iostream>
11
- RGBNotMatcher::RGBNotMatcher(int rgb_value) : Matcher(0L) {
11
+ RGBNotMatcher::RGBNotMatcher(unsigned int rgb_value) : Matcher(0L) {
12
12
  this->rgb_value = rgb_value;
13
13
  }
14
14
 
15
15
  RGBNotMatcher::~RGBNotMatcher() {
16
16
  }
17
17
 
18
- bool RGBNotMatcher::match(int value) {
18
+ bool RGBNotMatcher::match(unsigned int value) {
19
19
  return(this->rgb_value != value);
20
20
  }
@@ -6,18 +6,14 @@
6
6
  * Copyright 2025 Emanuele Cesaroni
7
7
  */
8
8
 
9
- #ifndef POLYGON_MATCHERS_RGBNOTMATCHER_H_
10
- #define POLYGON_MATCHERS_RGBNOTMATCHER_H_
11
-
9
+ #pragma once
12
10
  #include "Matcher.h"
13
11
 
14
12
  class RGBNotMatcher : public Matcher {
15
13
  public:
16
- RGBNotMatcher(int rgb_value);
14
+ explicit RGBNotMatcher(unsigned int rgb_value);
17
15
  virtual ~RGBNotMatcher();
18
- bool match(int value);
16
+ bool match(unsigned int value) override;
19
17
  private:
20
- int rgb_value;
18
+ unsigned int rgb_value;
21
19
  };
22
-
23
- #endif /* POLYGON_MATCHERS_RGBMATCHER_H_ */