-
Notifications
You must be signed in to change notification settings - Fork 0
/
external.rb
48 lines (39 loc) · 1.26 KB
/
external.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
require_relative '../../../Polygonoid/examples/search/Circular'
module Search
srand(0)
CLOCK = 'clock'
COUNTER = 'counter'
CIRCLES = Array.new(100) {Circle.new(50 + rand(1000), 50 + rand(1000), 5 + rand(50))}
@symbol_object = {
'start' => Circle.new(0,80,0),
'goal' => Circle.new(1000,1000,0)
}
@pos_counter = 0
def symbol(object)
symbol = @symbol_object.key(object) or @symbol_object[symbol = "pos#{@pos_counter += 1}"] = object
symbol
end
def search_circular(agent, start, goal)
@plan = Circular.search(@symbol_object[start], @symbol_object[goal], CIRCLES)&.map! {|i| symbol(i)}
end
def plan_position(index)
@plan[index.to_i]
end
def plan_size
@plan.size.to_f.to_s
end
def closest(circle, to, out_circle, in_dir, out_dir, goal)
g = @symbol_object[goal]
circles_sort = CIRCLES.sort_by {|c| Circular.center_distance(c, g)}
Circular.each_bitangent(@symbol_object[circle], in_dir == CLOCK, circles_sort) {|c,l,d|
out_circle.replace(symbol(c))
to.replace(symbol(l.to))
out_dir.replace(d ? CLOCK : COUNTER)
yield
}
end
def visible(point, circle, goal)
g = @symbol_object[goal]
Circular.visible?(Line.new(@symbol_object[point], g), CIRCLES, @symbol_object[circle], g)
end
end