contrek 1.0.6 → 1.0.8
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/Gemfile.lock +1 -1
- data/README.md +102 -6
- data/ext/cpp_polygon_finder/PolygonFinder/Makefile +4 -4
- data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.cpp +5 -4
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/bitmaps/FastPngBitmap.cpp +3 -5
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.cpp +1 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.cpp +2 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.h +1 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.cpp +28 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.h +1 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Finder.cpp +12 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Hub.cpp +5 -5
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Hub.h +11 -7
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.h +2 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.cpp +108 -66
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.h +5 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.cpp +33 -28
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.h +5 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Position.cpp +2 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Queueable.h +15 -20
- data/ext/cpp_polygon_finder/cpp_polygon_finder.cpp +128 -131
- data/lib/contrek/bitmaps/rgb_color.rb +0 -15
- data/lib/contrek/bitmaps/rgb_cpp_color.rb +10 -0
- data/lib/contrek/finder/concurrent/cluster.rb +2 -2
- data/lib/contrek/finder/concurrent/cursor.rb +32 -15
- data/lib/contrek/finder/concurrent/finder.rb +23 -9
- data/lib/contrek/finder/concurrent/hub.rb +2 -2
- data/lib/contrek/finder/concurrent/part.rb +6 -1
- data/lib/contrek/finder/concurrent/partitionable.rb +61 -33
- data/lib/contrek/finder/concurrent/polyline.rb +44 -2
- data/lib/contrek/finder/concurrent/queueable.rb +12 -20
- data/lib/contrek/finder/polygon_finder.rb +8 -6
- data/lib/contrek/finder/result.rb +13 -0
- data/lib/contrek/results/cpp_result.rb +21 -0
- data/lib/contrek/version.rb +1 -1
- data/lib/contrek.rb +6 -3
- metadata +5 -2
|
@@ -27,7 +27,15 @@ module Contrek
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def inspect
|
|
30
|
-
"#{self.class}
|
|
30
|
+
"#{self.class}#{named} (#{raw.count} => #{raw.inspect})"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def named
|
|
34
|
+
"[b#{@tile.name} S#{@name} #{"B" if boundary?}]"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def numpy_raw
|
|
38
|
+
raw.flat_map { |p| [p[:x], p[:y]] }
|
|
31
39
|
end
|
|
32
40
|
|
|
33
41
|
def info
|
|
@@ -46,8 +54,35 @@ module Contrek
|
|
|
46
54
|
(@flags & flag) != 0
|
|
47
55
|
end
|
|
48
56
|
|
|
57
|
+
def reset_tracked_endpoints!
|
|
58
|
+
@tracked_endpoints = nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# returns for every position of intersection an array composed by the indexes of parts (self,other) involved
|
|
62
|
+
# es [[1,3],[2,6],...]. The first time the sequence for self is computed is stored.
|
|
49
63
|
def intersection(other)
|
|
50
|
-
@
|
|
64
|
+
if @tracked_endpoints.nil?
|
|
65
|
+
@tracked_endpoints = {} # memoize found sequence
|
|
66
|
+
parts.each_with_index do |part, part_index|
|
|
67
|
+
next if !part.is?(Part::SEAM) && part.trasmuted
|
|
68
|
+
part.each do |pos|
|
|
69
|
+
@tracked_endpoints[pos.end_point.object_id] = part_index
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
matching_parts = []
|
|
74
|
+
other.parts.each_with_index do |part, part_index|
|
|
75
|
+
next if !part.is?(Part::SEAM) && part.trasmuted
|
|
76
|
+
part.each do |pos|
|
|
77
|
+
if (self_index = @tracked_endpoints[pos.end_point.object_id])
|
|
78
|
+
matching_parts << [self_index, part_index]
|
|
79
|
+
false
|
|
80
|
+
else
|
|
81
|
+
true
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
matching_parts
|
|
51
86
|
end
|
|
52
87
|
|
|
53
88
|
def empty?
|
|
@@ -82,6 +117,13 @@ module Contrek
|
|
|
82
117
|
!(@max_y < other.min_y || other.max_y < @min_y)
|
|
83
118
|
end
|
|
84
119
|
|
|
120
|
+
def get_bounds
|
|
121
|
+
{min_x: @min_x,
|
|
122
|
+
max_x: @max_x,
|
|
123
|
+
min_y: @min_y,
|
|
124
|
+
max_y: @max_y}
|
|
125
|
+
end
|
|
126
|
+
|
|
85
127
|
private
|
|
86
128
|
|
|
87
129
|
def find_boundary
|
|
@@ -10,6 +10,16 @@ module Contrek
|
|
|
10
10
|
@size = 0
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
def singleton!
|
|
14
|
+
if @head&.next
|
|
15
|
+
@head.next.prev = nil
|
|
16
|
+
@head.next = nil
|
|
17
|
+
end
|
|
18
|
+
@tail = nil
|
|
19
|
+
@size = 1
|
|
20
|
+
@iterator = 0
|
|
21
|
+
end
|
|
22
|
+
|
|
13
23
|
def rem(node)
|
|
14
24
|
Raise "Not my node" if node.owner != self
|
|
15
25
|
|
|
@@ -84,12 +94,13 @@ module Contrek
|
|
|
84
94
|
@iterator = 0
|
|
85
95
|
end
|
|
86
96
|
|
|
97
|
+
# from yield: false => stop, true => continue
|
|
87
98
|
def each(&block)
|
|
88
99
|
last = nil
|
|
89
100
|
unless @head.nil?
|
|
90
101
|
pointer = @head
|
|
91
102
|
loop do
|
|
92
|
-
yield(pointer)
|
|
103
|
+
break unless yield(pointer)
|
|
93
104
|
last = pointer
|
|
94
105
|
break unless (pointer = pointer.next)
|
|
95
106
|
end
|
|
@@ -142,25 +153,6 @@ module Contrek
|
|
|
142
153
|
rem(@tail)
|
|
143
154
|
end
|
|
144
155
|
|
|
145
|
-
def intersection_with(queueable)
|
|
146
|
-
int = []
|
|
147
|
-
each do |node|
|
|
148
|
-
int += queueable.map do |e|
|
|
149
|
-
break [e.payload] if e.payload == node.payload
|
|
150
|
-
end.compact
|
|
151
|
-
end
|
|
152
|
-
int
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def intersection_with_array?(array)
|
|
156
|
-
each { |node| return true if array.index(node.payload) }
|
|
157
|
-
false
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def intersect_with?(queueable)
|
|
161
|
-
intersection_with(queueable).any?
|
|
162
|
-
end
|
|
163
|
-
|
|
164
156
|
def remove_adjacent_pairs(array = nil)
|
|
165
157
|
array = to_a if array.nil?
|
|
166
158
|
n = array.size
|
|
@@ -43,12 +43,14 @@ module Contrek
|
|
|
43
43
|
|
|
44
44
|
# infos
|
|
45
45
|
def process_info
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
metadata = {
|
|
47
|
+
named_sequence: @node_cluster.sequences.map { |list| list.map(&:name).join }.join("-"),
|
|
48
|
+
groups: @node_cluster.sequences.size,
|
|
49
|
+
groups_names: @node_cluster.root_nodes.map(&:name).join,
|
|
50
|
+
benchmarks: format_benchmarks,
|
|
51
|
+
treemap: (@node_cluster.treemap if @options.has_key?(:treemap))
|
|
52
|
+
}
|
|
53
|
+
Result.new(@node_cluster.polygons, metadata)
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
def get_shapelines
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Contrek
|
|
2
|
+
module Results
|
|
3
|
+
class CPPFinder::Result
|
|
4
|
+
def points
|
|
5
|
+
raw_list = polygons.to_a
|
|
6
|
+
@to_points ||= raw_list.map do |polygon|
|
|
7
|
+
{outer: self.class.to_points(polygon[:outer]),
|
|
8
|
+
inner: polygon[:inner].map { |s| self.class.to_points(s) }}
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def total_time
|
|
13
|
+
metadata[:benchmarks].values.sum
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.to_points(flat_polygon)
|
|
17
|
+
flat_polygon.each_slice(2).map { |x, y| {x: x, y: y} }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/contrek/version.rb
CHANGED
data/lib/contrek.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "contrek/bitmaps/chunky_bitmap"
|
|
|
5
5
|
require "contrek/bitmaps/png_bitmap"
|
|
6
6
|
require "contrek/bitmaps/custom_bitmap"
|
|
7
7
|
require "contrek/bitmaps/rgb_color"
|
|
8
|
+
require "contrek/bitmaps/rgb_cpp_color"
|
|
8
9
|
require "contrek/finder/bounds"
|
|
9
10
|
require "contrek/bitmaps/sample_generator"
|
|
10
11
|
require "contrek/finder/list"
|
|
@@ -15,6 +16,7 @@ require "contrek/finder/node"
|
|
|
15
16
|
require "contrek/finder/node_cluster"
|
|
16
17
|
require "contrek/finder/concurrent/fake_cluster"
|
|
17
18
|
require "contrek/finder/polygon_finder"
|
|
19
|
+
require "contrek/finder/result"
|
|
18
20
|
require "contrek/finder/concurrent/clipped_polygon_finder"
|
|
19
21
|
require "contrek/finder/concurrent/hub"
|
|
20
22
|
require "contrek/finder/concurrent/end_point"
|
|
@@ -41,6 +43,7 @@ require "contrek/reducers/uniq_reducer"
|
|
|
41
43
|
require "contrek/reducers/visvalingam_reducer"
|
|
42
44
|
require "cpp_polygon_finder"
|
|
43
45
|
require "contrek/cpp/cpp_concurrent_finder"
|
|
46
|
+
require "contrek/results/cpp_result"
|
|
44
47
|
|
|
45
48
|
module Contrek
|
|
46
49
|
class << self
|
|
@@ -52,10 +55,10 @@ module Contrek
|
|
|
52
55
|
private
|
|
53
56
|
|
|
54
57
|
def compute_cpp(png_file_path, options)
|
|
55
|
-
color = Bitmaps::
|
|
58
|
+
color = Bitmaps::RgbCppColor.new(**options[:color])
|
|
56
59
|
png_bitmap = CPPPngBitMap.new(png_file_path)
|
|
57
60
|
rgb_matcher_klass = (options[:class] == "value_not_matcher") ? CPPRGBNotMatcher : CPPRGBMatcher
|
|
58
|
-
rgb_matcher = rgb_matcher_klass.new(color.
|
|
61
|
+
rgb_matcher = rgb_matcher_klass.new(color.raw)
|
|
59
62
|
if options.key?(:number_of_threads) || options[:finder]&.key?(:number_of_tiles)
|
|
60
63
|
Contrek::Cpp::CPPConcurrentFinder.new(
|
|
61
64
|
number_of_threads: options.dig(:number_of_threads) || 0,
|
|
@@ -72,7 +75,7 @@ module Contrek
|
|
|
72
75
|
end
|
|
73
76
|
|
|
74
77
|
def compute_ruby_pure(png_file_path, options)
|
|
75
|
-
color = Bitmaps::
|
|
78
|
+
color = Bitmaps::RgbCppColor.new(**options[:color])
|
|
76
79
|
png_bitmap = Bitmaps::PngBitmap.new(png_file_path)
|
|
77
80
|
rgb_matcher = const_get("Contrek::Matchers::" + camelize("value_not_matcher")).new(color.raw)
|
|
78
81
|
if options.key?(:number_of_threads) || options[:finder]&.key?(:number_of_tiles)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: contrek
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emanuele Cesaroni
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -229,6 +229,7 @@ files:
|
|
|
229
229
|
- lib/contrek/bitmaps/painting.rb
|
|
230
230
|
- lib/contrek/bitmaps/png_bitmap.rb
|
|
231
231
|
- lib/contrek/bitmaps/rgb_color.rb
|
|
232
|
+
- lib/contrek/bitmaps/rgb_cpp_color.rb
|
|
232
233
|
- lib/contrek/bitmaps/sample_generator.rb
|
|
233
234
|
- lib/contrek/cpp/cpp_concurrent_finder.rb
|
|
234
235
|
- lib/contrek/finder/bounds.rb
|
|
@@ -256,6 +257,7 @@ files:
|
|
|
256
257
|
- lib/contrek/finder/node.rb
|
|
257
258
|
- lib/contrek/finder/node_cluster.rb
|
|
258
259
|
- lib/contrek/finder/polygon_finder.rb
|
|
260
|
+
- lib/contrek/finder/result.rb
|
|
259
261
|
- lib/contrek/map/mercator_projection.rb
|
|
260
262
|
- lib/contrek/matchers/matcher.rb
|
|
261
263
|
- lib/contrek/matchers/matcher_hsb.rb
|
|
@@ -264,6 +266,7 @@ files:
|
|
|
264
266
|
- lib/contrek/reducers/reducer.rb
|
|
265
267
|
- lib/contrek/reducers/uniq_reducer.rb
|
|
266
268
|
- lib/contrek/reducers/visvalingam_reducer.rb
|
|
269
|
+
- lib/contrek/results/cpp_result.rb
|
|
267
270
|
- lib/contrek/version.rb
|
|
268
271
|
homepage: https://github.com/runout77/contrek
|
|
269
272
|
licenses:
|