-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
101 lines (76 loc) · 2.19 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require_relative "lib/generator"
require_relative "lib/collision_map"
require_relative "lib/libraries/debug"
Random::srand(174244244925392674317086725143365111051)
(1..1).each do
g = Generator.new(16, [20, 20])
nodes = g.run
nodes.each { |node| node.position.store.map! {|a| a.round(2)} }
# print nodes.map(&:position)
puts
puts
puts "---"
puts
collision_map = CollisionMap.new(nodes)
# thingify = Proc.new {|r| r.is_a?(Array) ? thingify.call(r) : r.class }
# .map {|r| r.is_a?(Array) ? r.map(&:class) : r.class }
# strify = Proc.new do |thing|
# strify_sub = Proc.new do |t|
# if t.is_a?(Array) || t.is_a?(CollisionList)
# t.map(&strify_sub)
# else
# t.x
# end
# end
#
# thing.map(&strify_sub)
# end
# print strify.call(collision_map.partition)
puts
# print collision_map.partition[1]
puts
node = nodes.sample
print node.position
puts
Debug.elapsed "old algorithm; one collision" do
collision = nodes.any? do |other|
other.distance(node) < other.radius + node.radius
end
end
Debug.elapsed "old algorithm; #{nodes.length} collisions" do
0.upto(nodes.length) do
collision = nodes.any? do |other|
other.distance(node) < other.radius + node.radius
end
end
end
Debug.elapsed "new algorithm; generating collision map & one collision" do
cmap = CollisionMap.new(nodes)
rs = collision_map.search(node.position)
rs.closest(node)
end
Debug.elapsed "new algorithm; generating collision map & #{nodes.length} collisions" do
cmap = CollisionMap.new(nodes)
0.upto(nodes.length) do
rs = collision_map.search(node.position)
rs.closest(node)
end
end
results = collision_map.search(node.position)
print results.length
puts
print results.map {|r| r.is_a?(Array) ? r.map(&:class) : r.class }
puts
print "query node: \n"
print node.position.to_a
puts
print "result nodes: \n"
print results.map(&:position).map(&:to_a)
puts
print "closest result: \n"
print results.closest(node).position.to_a
puts
puts
puts "---"
puts
end