contrek 1.1.9 → 1.2.0
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 +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cluster.cpp +1 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.cpp +66 -158
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Cursor.h +0 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/EndPoint.h +4 -2
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.cpp +0 -13
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Part.h +1 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.cpp +0 -128
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Partitionable.h +0 -6
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.cpp +0 -50
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Polyline.h +2 -8
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Position.cpp +22 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Queueable.h +1 -57
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.cpp +0 -12
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/Tile.h +0 -3
- data/ext/cpp_polygon_finder/PolygonFinder/src/polygon/finder/concurrent/VerticalMerger.cpp +11 -3
- data/lib/contrek/finder/concurrent/cluster.rb +1 -2
- data/lib/contrek/finder/concurrent/cursor.rb +56 -120
- data/lib/contrek/finder/concurrent/end_point.rb +2 -0
- data/lib/contrek/finder/concurrent/part.rb +2 -20
- data/lib/contrek/finder/concurrent/partitionable.rb +0 -81
- data/lib/contrek/finder/concurrent/polyline.rb +3 -47
- data/lib/contrek/finder/concurrent/position.rb +8 -2
- data/lib/contrek/finder/concurrent/queueable.rb +0 -41
- data/lib/contrek/finder/concurrent/tile.rb +0 -4
- data/lib/contrek/finder/concurrent/vertical_merger.rb +9 -5
- data/lib/contrek/version.rb +1 -1
- metadata +3 -3
- /data/{LICENSE-MIT.md → lib/LICENSE-MIT.md} +0 -0
|
@@ -18,23 +18,6 @@ module Contrek
|
|
|
18
18
|
new_part.orient! if new_part.is?(Part::SEAM)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def insert_after(part, new_part)
|
|
22
|
-
part_index = @parts.index(part)
|
|
23
|
-
@parts.insert(part_index + 1, new_part)
|
|
24
|
-
new_part.prev = part
|
|
25
|
-
new_part.next = new_part.circular_next = part.next
|
|
26
|
-
part.next.prev = new_part if part.next
|
|
27
|
-
part.next = part.circular_next = new_part
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def find_first_part_by_position(position, versus)
|
|
31
|
-
@parts.find do |part|
|
|
32
|
-
part.is?(Part::SEAM) &&
|
|
33
|
-
part.versus == -versus &&
|
|
34
|
-
position.end_point.queues.include?(part)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
21
|
def inspect_parts
|
|
39
22
|
[" "] + ["#{self.class} parts=#{@parts.size}"] + @parts.map { |p| p.inspect } + [" "]
|
|
40
23
|
end
|
|
@@ -67,70 +50,6 @@ module Contrek
|
|
|
67
50
|
trasmute_parts!
|
|
68
51
|
end
|
|
69
52
|
|
|
70
|
-
def sew!(intersection, other)
|
|
71
|
-
matching_part_indexes, other_matching_part_indexes = intersection.transpose.map(&:sort)
|
|
72
|
-
# other_matching_part_indexes and matching_part_indexes always must contain at least one element
|
|
73
|
-
before_parts = other.parts[other_matching_part_indexes.last + 1..]
|
|
74
|
-
after_parts = other_matching_part_indexes.first.zero? ? [] : other.parts[0..other_matching_part_indexes.first - 1]
|
|
75
|
-
part_start = parts[matching_part_indexes.first]
|
|
76
|
-
part_end = parts[matching_part_indexes.last]
|
|
77
|
-
|
|
78
|
-
# left and right side reduces will be combined and later converted into orphan inners sequences
|
|
79
|
-
returning_data = [[matching_part_indexes, parts], [other_matching_part_indexes, other.parts]].map do |matching_part_indexes, parts|
|
|
80
|
-
lastn = 0
|
|
81
|
-
result = []
|
|
82
|
-
(matching_part_indexes.first + 1).upto(matching_part_indexes.last - 1) do |n|
|
|
83
|
-
if matching_part_indexes.index(n).nil?
|
|
84
|
-
part = parts[n]
|
|
85
|
-
if part.is?(Part::SEAM) && part.size > 0 && !part.delayed # fallback, delays the shape
|
|
86
|
-
part.delayed = true
|
|
87
|
-
return nil
|
|
88
|
-
end
|
|
89
|
-
if (lastn == (n - 1)) && result.any?
|
|
90
|
-
result.last.concat part.to_a
|
|
91
|
-
else
|
|
92
|
-
result << part.to_a
|
|
93
|
-
end
|
|
94
|
-
lastn = n
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
result
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
if part_start != part_end
|
|
101
|
-
(matching_part_indexes.last - 1).downto(matching_part_indexes.first + 1) do |n|
|
|
102
|
-
delete_part = parts[n]
|
|
103
|
-
delete_part.prev.next = delete_part.next if delete_part.prev
|
|
104
|
-
delete_part.next.prev = delete_part.prev if delete_part.next
|
|
105
|
-
parts.delete_at(n)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
all_parts = before_parts + after_parts
|
|
110
|
-
will_be_last = all_parts.last
|
|
111
|
-
all_parts.reverse_each do |part|
|
|
112
|
-
insert_after(part_start, part)
|
|
113
|
-
other.parts.delete(part)
|
|
114
|
-
part.set_polyline(self)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
part_start.type = Part::EXCLUSIVE
|
|
118
|
-
new_end_part = Part.new(Part::EXCLUSIVE, self)
|
|
119
|
-
new_end_part.add(part_end.tail)
|
|
120
|
-
part_start.singleton! # reduce part to its head only
|
|
121
|
-
|
|
122
|
-
if part_start != part_end
|
|
123
|
-
part_end.prev.next = part_end.next if part_end.prev
|
|
124
|
-
part_end.next.prev = part_end.prev if part_end.next
|
|
125
|
-
parts.delete(part_end)
|
|
126
|
-
end
|
|
127
|
-
insert_after(will_be_last, new_end_part)
|
|
128
|
-
|
|
129
|
-
reset_tracked_endpoints!
|
|
130
|
-
|
|
131
|
-
returning_data
|
|
132
|
-
end
|
|
133
|
-
|
|
134
53
|
private
|
|
135
54
|
|
|
136
55
|
# If there are SEAM parts and one is canceled out by another within the same polyline,
|
|
@@ -4,10 +4,9 @@ module Contrek
|
|
|
4
4
|
prepend Partitionable
|
|
5
5
|
|
|
6
6
|
TRACKED_OUTER = 1 << 0
|
|
7
|
-
TRACKED_INNER = 1 << 1
|
|
8
7
|
|
|
9
|
-
attr_reader :raw, :name, :min_y, :max_y
|
|
10
|
-
attr_accessor :shape, :tile, :
|
|
8
|
+
attr_reader :raw, :name, :min_y, :max_y
|
|
9
|
+
attr_accessor :shape, :tile, :any_ancients
|
|
11
10
|
|
|
12
11
|
def initialize(tile:, polygon:, shape: nil, bounds: nil)
|
|
13
12
|
@tile = tile
|
|
@@ -15,7 +14,7 @@ module Contrek
|
|
|
15
14
|
@raw = polygon
|
|
16
15
|
@shape = shape
|
|
17
16
|
@flags = 0
|
|
18
|
-
@
|
|
17
|
+
@any_ancients = false
|
|
19
18
|
|
|
20
19
|
if bounds.nil?
|
|
21
20
|
find_boundary
|
|
@@ -55,38 +54,6 @@ module Contrek
|
|
|
55
54
|
(@flags & flag) != 0
|
|
56
55
|
end
|
|
57
56
|
|
|
58
|
-
def reset_tracked_endpoints!
|
|
59
|
-
@tracked_endpoints = nil
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# returns for every position of intersection an array composed by the indexes of parts (self,other) involved
|
|
63
|
-
# es [[1,3],[2,6],...]. The first time the sequence for self is computed is stored.
|
|
64
|
-
def intersection(other)
|
|
65
|
-
if @tracked_endpoints.nil?
|
|
66
|
-
@tracked_endpoints = {} # memoize found sequence
|
|
67
|
-
parts.each_with_index do |part, part_index|
|
|
68
|
-
next if !part.is?(Part::SEAM) && part.trasmuted
|
|
69
|
-
part.each do |pos|
|
|
70
|
-
next if pos.end_point.nil?
|
|
71
|
-
@tracked_endpoints[pos.end_point.object_id] = part_index
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
matching_parts = []
|
|
76
|
-
other.parts.each_with_index do |part, part_index|
|
|
77
|
-
next if !part.is?(Part::SEAM) && part.trasmuted
|
|
78
|
-
part.each do |pos|
|
|
79
|
-
if (self_index = @tracked_endpoints[pos.end_point.object_id])
|
|
80
|
-
matching_parts << [self_index, part_index]
|
|
81
|
-
false
|
|
82
|
-
else
|
|
83
|
-
true
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
matching_parts
|
|
88
|
-
end
|
|
89
|
-
|
|
90
57
|
def empty?
|
|
91
58
|
@raw.empty?
|
|
92
59
|
end
|
|
@@ -104,17 +71,6 @@ module Contrek
|
|
|
104
71
|
@max_x - @min_x
|
|
105
72
|
end
|
|
106
73
|
|
|
107
|
-
# Pre-detects, for the current polyline, adjacent ones in the neighboring tile
|
|
108
|
-
# that vertically intersect.
|
|
109
|
-
def precalc!
|
|
110
|
-
@next_tile_eligible_shapes = @tile
|
|
111
|
-
.circular_next.boundary_shapes
|
|
112
|
-
.select { |s|
|
|
113
|
-
!s.outer_polyline.on?(Polyline::TRACKED_OUTER) &&
|
|
114
|
-
vert_intersect?(s.outer_polyline)
|
|
115
|
-
}
|
|
116
|
-
end
|
|
117
|
-
|
|
118
74
|
def vert_intersect?(other)
|
|
119
75
|
!(@max_y < other.min_y || other.max_y < @min_y)
|
|
120
76
|
end
|
|
@@ -20,11 +20,17 @@ module Contrek
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def after_add(new_queue)
|
|
23
|
-
@end_point
|
|
23
|
+
if @end_point && new_queue.instance_of?(Contrek::Concurrent::Part)
|
|
24
|
+
@end_point.queues << new_queue if !@end_point.queues.include?(new_queue)
|
|
25
|
+
if @end_point.queues.size > 1
|
|
26
|
+
new_queue.polyline.any_ancients = true
|
|
27
|
+
@end_point.queues.first.polyline.any_ancients = true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
24
30
|
end
|
|
25
31
|
|
|
26
32
|
def before_rem(old_queue)
|
|
27
|
-
@end_point&.queues&.delete(old_queue)
|
|
33
|
+
# @end_point&.queues&.delete(old_queue) if old_queue.class == Contrek::Concurrent::Part
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
def inspect
|
|
@@ -10,16 +10,6 @@ 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
|
-
|
|
23
13
|
def rem(node)
|
|
24
14
|
Raise "Not my node" if node.owner != self
|
|
25
15
|
|
|
@@ -55,30 +45,6 @@ module Contrek
|
|
|
55
45
|
node.after_add(self)
|
|
56
46
|
end
|
|
57
47
|
|
|
58
|
-
def replace!(queueable)
|
|
59
|
-
reset!
|
|
60
|
-
append(queueable)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def append(queueable)
|
|
64
|
-
return if queueable.size.zero?
|
|
65
|
-
queueable.each do |node|
|
|
66
|
-
node.before_rem(queueable)
|
|
67
|
-
node.owner = self
|
|
68
|
-
end
|
|
69
|
-
if @tail
|
|
70
|
-
@tail.next = queueable.head
|
|
71
|
-
queueable.head.prev = @tail
|
|
72
|
-
else
|
|
73
|
-
@head = queueable.head
|
|
74
|
-
end
|
|
75
|
-
@tail = queueable.tail
|
|
76
|
-
@size += queueable.size
|
|
77
|
-
queueable.reset!
|
|
78
|
-
|
|
79
|
-
each { |node| node.after_add(self) }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
48
|
def move_from(queueable, &block)
|
|
83
49
|
queueable.rewind!
|
|
84
50
|
while (node = queueable.iterator)
|
|
@@ -87,13 +53,6 @@ module Contrek
|
|
|
87
53
|
end
|
|
88
54
|
end
|
|
89
55
|
|
|
90
|
-
def reset!
|
|
91
|
-
@head = nil
|
|
92
|
-
@tail = nil
|
|
93
|
-
@size = 0
|
|
94
|
-
@iterator = 0
|
|
95
|
-
end
|
|
96
|
-
|
|
97
56
|
# from yield: false => stop, true => continue
|
|
98
57
|
def each(&block)
|
|
99
58
|
last = nil
|
|
@@ -31,10 +31,6 @@ module Contrek
|
|
|
31
31
|
assign_raw_polygons!(result[:polygons], result.metadata[:treemap])
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
def boundary_shapes
|
|
35
|
-
@bbs ||= shapes.select { |s| s.outer_polyline.boundary? }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
34
|
def iterate
|
|
39
35
|
@shapes.each do |shape|
|
|
40
36
|
shape.outer_polyline.raw.each do |position|
|
|
@@ -28,13 +28,17 @@ module Contrek
|
|
|
28
28
|
def transpose(result)
|
|
29
29
|
result.metadata[:width], result.metadata[:height] = result.metadata[:height], result.metadata[:width]
|
|
30
30
|
result.polygons.each do |polygon|
|
|
31
|
-
|
|
32
|
-
polygon[:
|
|
33
|
-
|
|
31
|
+
invert_point = ->(p) { {x: p[:y], y: p[:x]} }
|
|
32
|
+
polygon[:outer] = polygon[:outer].map(&invert_point)
|
|
33
|
+
polygon[:inner] = polygon[:inner].map do |sequence|
|
|
34
|
+
sequence.map(&invert_point)
|
|
34
35
|
end
|
|
35
36
|
if polygon.key?(:bounds)
|
|
36
|
-
|
|
37
|
-
polygon[:bounds]
|
|
37
|
+
b = polygon[:bounds]
|
|
38
|
+
polygon[:bounds] = {
|
|
39
|
+
min_x: b[:min_y], min_y: b[:min_x],
|
|
40
|
+
max_x: b[:max_y], max_y: b[:max_x]
|
|
41
|
+
}
|
|
38
42
|
end
|
|
39
43
|
end
|
|
40
44
|
result
|
data/lib/contrek/version.rb
CHANGED
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.
|
|
4
|
+
version: 1.2.0
|
|
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-
|
|
11
|
+
date: 2026-05-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -135,7 +135,6 @@ files:
|
|
|
135
135
|
- CHANGELOG.md
|
|
136
136
|
- Gemfile
|
|
137
137
|
- Gemfile.lock
|
|
138
|
-
- LICENSE-MIT.md
|
|
139
138
|
- LICENSE.md
|
|
140
139
|
- README.md
|
|
141
140
|
- Rakefile
|
|
@@ -242,6 +241,7 @@ files:
|
|
|
242
241
|
- ext/cpp_polygon_finder/PolygonFinder/src/polygon/reducers/VisvalingamReducer.h
|
|
243
242
|
- ext/cpp_polygon_finder/cpp_polygon_finder.cpp
|
|
244
243
|
- ext/cpp_polygon_finder/extconf.rb
|
|
244
|
+
- lib/LICENSE-MIT.md
|
|
245
245
|
- lib/contrek.rb
|
|
246
246
|
- lib/contrek/bitmaps/bitmap.rb
|
|
247
247
|
- lib/contrek/bitmaps/chunky_bitmap.rb
|
|
File without changes
|