contrek 1.2.1 → 1.2.3
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 +16 -1
- data/Gemfile.lock +1 -1
- data/PERFORMANCE.md +177 -0
- data/README.md +2 -1
- data/contrek.gemspec +5 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/ContrekApi.h +39 -16
- data/ext/cpp_polygon_finder/PolygonFinder/src/Tests.cpp +4 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/PolygonFinder.h +74 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.cpp +32 -41
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.h +2 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.cpp +33 -5
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.h +3 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/InnerPolyline.cpp +1 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/InnerPolyline.h +1 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.cpp +16 -20
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.h +8 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Shape.cpp +5 -0
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Shape.h +3 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/ShapePool.cpp +2 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/ShapePool.h +1 -1
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.cpp +5 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.h +4 -4
- data/ext/cpp_polygon_finder/cpp_polygon_finder.cpp +2 -3
- data/lib/contrek/cpp/cpp_result.rb +2 -0
- data/lib/contrek/finder/concurrent/cluster.rb +30 -29
- data/lib/contrek/finder/concurrent/cursor.rb +35 -12
- data/lib/contrek/finder/concurrent/inner_polyline.rb +2 -3
- data/lib/contrek/finder/concurrent/polyline.rb +5 -7
- data/lib/contrek/finder/concurrent/shape.rb +7 -3
- data/lib/contrek/finder/concurrent/tile.rb +5 -4
- data/lib/contrek/finder/result.rb +2 -0
- data/lib/contrek/shared/result.rb +23 -0
- data/lib/contrek/version.rb +1 -1
- data/lib/contrek.rb +2 -1
- metadata +4 -6
- data/ext/cpp_polygon_finder/PolygonFinder/examples/example.cpp +0 -56
- data/ext/cpp_polygon_finder/PolygonFinder/images/graphs_1024x1024.png +0 -0
- data/ext/cpp_polygon_finder/PolygonFinder/images/labyrinth.png +0 -0
- data/ext/cpp_polygon_finder/PolygonFinder/images/sample_10240x10240.png +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module Contrek
|
|
2
2
|
module Concurrent
|
|
3
3
|
class Shape
|
|
4
|
-
attr_accessor :outer_polyline, :inner_polylines, :merged_to_shape,
|
|
5
|
-
:
|
|
4
|
+
attr_accessor :outer_polyline, :inner_polylines, :merged_to_shape,
|
|
5
|
+
:parent_inner_polyline, :fixed
|
|
6
6
|
attr_reader :parent_shape, :children_shapes
|
|
7
7
|
|
|
8
8
|
def initialize
|
|
@@ -10,7 +10,7 @@ module Contrek
|
|
|
10
10
|
@merged_to_shape = nil
|
|
11
11
|
@parent_inner_polyline = nil
|
|
12
12
|
@children_shapes = []
|
|
13
|
-
@
|
|
13
|
+
@fixed = false
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def self.init_by(set_outer_polyline, set_inner_polylines)
|
|
@@ -24,6 +24,10 @@ module Contrek
|
|
|
24
24
|
@inner_polylines.clear
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def name
|
|
28
|
+
outer_polyline.named
|
|
29
|
+
end
|
|
30
|
+
|
|
27
31
|
def set_parent_shape(shape)
|
|
28
32
|
@parent_shape&.children_shapes&.delete(self)
|
|
29
33
|
@parent_shape = shape
|
|
@@ -61,15 +61,15 @@ module Contrek
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def compute_treemap
|
|
64
|
-
|
|
64
|
+
shapes_map = {}
|
|
65
65
|
shape_index = 0
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
shapes.map do |shape|
|
|
68
68
|
next if shape.outer_polyline.empty?
|
|
69
|
-
|
|
69
|
+
shapes_map[shape] = shape_index
|
|
70
70
|
shape_index += 1
|
|
71
71
|
if shape.parent_shape
|
|
72
|
-
[
|
|
72
|
+
[shapes_map[shape.parent_shape], shape.parent_shape.inner_polylines.index(shape.parent_inner_polyline)]
|
|
73
73
|
else
|
|
74
74
|
[-1, -1]
|
|
75
75
|
end
|
|
@@ -104,6 +104,7 @@ module Contrek
|
|
|
104
104
|
if treemap_entry != [-1, -1]
|
|
105
105
|
parent = shapes_map[treemap_entry.first]
|
|
106
106
|
shape.set_parent_shape(parent)
|
|
107
|
+
shape.fixed = true
|
|
107
108
|
shape.parent_inner_polyline = parent.inner_polylines[treemap_entry.last]
|
|
108
109
|
end
|
|
109
110
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Contrek
|
|
2
|
+
module Shared
|
|
3
|
+
module Result
|
|
4
|
+
def to_svg
|
|
5
|
+
width = metadata[:width]
|
|
6
|
+
height = metadata[:height]
|
|
7
|
+
lines = []
|
|
8
|
+
lines << %(<svg xmlns="http://www.w3.org/2000/svg" width="#{width}" height="#{height}">)
|
|
9
|
+
points.each do |poly|
|
|
10
|
+
pts = poly[:outer].map { |p| "#{p[:x]},#{p[:y]}" }.join(" ")
|
|
11
|
+
lines << %(<polygon points="#{pts}" fill="none" stroke="red" stroke-width="1"/>)
|
|
12
|
+
poly[:inner].each do |sequence|
|
|
13
|
+
next if sequence.empty?
|
|
14
|
+
pts = sequence.map { |p| "#{p[:x]},#{p[:y]}" }.join(" ")
|
|
15
|
+
lines << %(<polygon points="#{pts}" fill="none" stroke="green" stroke-width="1"/>)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
lines << "</svg>"
|
|
19
|
+
lines.join("\n")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/contrek/version.rb
CHANGED
data/lib/contrek.rb
CHANGED
|
@@ -6,8 +6,9 @@ require "contrek/bitmaps/png_bitmap"
|
|
|
6
6
|
require "contrek/bitmaps/raw_bitmap"
|
|
7
7
|
require "contrek/bitmaps/rgb_color"
|
|
8
8
|
require "contrek/bitmaps/rgb_cpp_color"
|
|
9
|
-
require "contrek/finder/bounds"
|
|
10
9
|
require "contrek/bitmaps/sample_generator"
|
|
10
|
+
require "contrek/shared/result"
|
|
11
|
+
require "contrek/finder/bounds"
|
|
11
12
|
require "contrek/finder/list"
|
|
12
13
|
require "contrek/finder/list_entry"
|
|
13
14
|
require "contrek/finder/listable"
|
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.2.
|
|
4
|
+
version: 1.2.3
|
|
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-05-
|
|
11
|
+
date: 2026-05-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -136,6 +136,7 @@ files:
|
|
|
136
136
|
- Gemfile
|
|
137
137
|
- Gemfile.lock
|
|
138
138
|
- LICENSE.md
|
|
139
|
+
- PERFORMANCE.md
|
|
139
140
|
- README.md
|
|
140
141
|
- Rakefile
|
|
141
142
|
- contrek.gemspec
|
|
@@ -143,10 +144,6 @@ files:
|
|
|
143
144
|
- ext/cpp_polygon_finder/PolygonFinder/CMakeLists.txt
|
|
144
145
|
- ext/cpp_polygon_finder/PolygonFinder/LICENSE_AGPL.txt
|
|
145
146
|
- ext/cpp_polygon_finder/PolygonFinder/clean.sh
|
|
146
|
-
- ext/cpp_polygon_finder/PolygonFinder/examples/example.cpp
|
|
147
|
-
- ext/cpp_polygon_finder/PolygonFinder/images/graphs_1024x1024.png
|
|
148
|
-
- ext/cpp_polygon_finder/PolygonFinder/images/labyrinth.png
|
|
149
|
-
- ext/cpp_polygon_finder/PolygonFinder/images/sample_10240x10240.png
|
|
150
147
|
- ext/cpp_polygon_finder/PolygonFinder/src/ContrekApi.h
|
|
151
148
|
- ext/cpp_polygon_finder/PolygonFinder/src/Tests.cpp
|
|
152
149
|
- ext/cpp_polygon_finder/PolygonFinder/src/Tests.h
|
|
@@ -294,6 +291,7 @@ files:
|
|
|
294
291
|
- lib/contrek/reducers/reducer.rb
|
|
295
292
|
- lib/contrek/reducers/uniq_reducer.rb
|
|
296
293
|
- lib/contrek/reducers/visvalingam_reducer.rb
|
|
294
|
+
- lib/contrek/shared/result.rb
|
|
297
295
|
- lib/contrek/version.rb
|
|
298
296
|
homepage: https://github.com/runout77/contrek
|
|
299
297
|
licenses:
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* example.cpp
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025-2026 Emanuele Cesaroni
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the GNU Affero General Public License v3 (AGPLv3).
|
|
7
|
-
* See the LICENSE file in this directory for the full license text.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
#include <iostream>
|
|
11
|
-
#include <gperftools/malloc_extension.h>
|
|
12
|
-
#include "ContrekApi.h"
|
|
13
|
-
#include "Tests.h"
|
|
14
|
-
|
|
15
|
-
void run_test() {
|
|
16
|
-
CpuTimer cpu_timer;
|
|
17
|
-
Tests test_suite;
|
|
18
|
-
cpu_timer.start();
|
|
19
|
-
|
|
20
|
-
// test_suite.test_a();
|
|
21
|
-
// test_suite.test_b();
|
|
22
|
-
// test_suite.test_c();
|
|
23
|
-
// test_suite.test_d();
|
|
24
|
-
// test_suite.test_e();
|
|
25
|
-
// test_suite.test_f();
|
|
26
|
-
// test_suite.test_g();
|
|
27
|
-
// test_suite.test_h();
|
|
28
|
-
// test_suite.test_i();
|
|
29
|
-
std::cout << "compute time =" << cpu_timer.stop() << std::endl;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
int main() {
|
|
33
|
-
MallocExtension::instance()->SetNumericProperty(
|
|
34
|
-
"tcmalloc.max_total_thread_cache_bytes",
|
|
35
|
-
1024 * 1024 * 1024
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
Contrek::Config cfg;
|
|
39
|
-
cfg.threads = 4;
|
|
40
|
-
cfg.tiles = 4;
|
|
41
|
-
cfg.compress_unique = true;
|
|
42
|
-
// cfg.treemap = true;
|
|
43
|
-
// cfg.connectivity_mode = Contrek::Connectivity::OMNIDIRECTIONAL;
|
|
44
|
-
|
|
45
|
-
CpuTimer cpu_timer;
|
|
46
|
-
cpu_timer.start();
|
|
47
|
-
std::cout << "--- Start Native Benchmark ---" << std::endl;
|
|
48
|
-
// auto result = Contrek::trace("../images/graphs_1024x1024.png", cfg);
|
|
49
|
-
auto result = Contrek::trace("../images/sample_10240x10240.png", cfg);
|
|
50
|
-
result->print_info();
|
|
51
|
-
std::cout << "Found polygons: " << result->groups << std::endl;
|
|
52
|
-
std::cout << "Time: " << cpu_timer.stop() << " ms" << std::endl;
|
|
53
|
-
|
|
54
|
-
// run_test();
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|