astromapper 1.0.51 → 1.1.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/lib/astromapper/svg.rb +51 -37
- data/lib/astromapper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d9a36dfde13824da0135e67df60a7c8331aecd8
|
4
|
+
data.tar.gz: 8f5f3fcdac9e026fdda26572b7ad5b6901cdc3ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8efcc69879ee5a75435cfe57fa22adc5af8c91cfe18dc3a9bf997374c651f2899415d29933b6f392281e39303642bb2532faf7fc3892b564a1b650b1ab9ebe4
|
7
|
+
data.tar.gz: 67053e837773e6cd6de6b7675424ff6213f4e5fc6b1863460c7be208fd351705aeda2dff0c8d6ef9b8590c0ccfe736fe935c3c8d7a64ba32210df708dd0efa25
|
data/lib/astromapper/svg.rb
CHANGED
@@ -18,6 +18,7 @@ module Astromapper
|
|
18
18
|
@volumes = []
|
19
19
|
# @routes = {}
|
20
20
|
@routes = []
|
21
|
+
@slopes = {}
|
21
22
|
@name = config['name']
|
22
23
|
|
23
24
|
@hex = {
|
@@ -29,46 +30,60 @@ module Astromapper
|
|
29
30
|
def from_file
|
30
31
|
File.open(@source_filename,'r').readlines.each { |line| @volumes << line if /^\d{4}/.match(line) }
|
31
32
|
end
|
33
|
+
def calc_route(keys,x,x1,y,y1)
|
34
|
+
route = nil
|
35
|
+
c = "%02d%02d" % [x1, y1]
|
36
|
+
k = "%02d%02d" % [x, y]
|
37
|
+
# puts "#{k}:#{c} (#{x}, #{y}) (#{x1}, #{y1})"
|
38
|
+
# Calcuate Route Distance
|
39
|
+
d = Math.sqrt((x - x1)**2 + (y - y1)**2).round(0)
|
40
|
+
return route if d == 0
|
41
|
+
|
42
|
+
# Calculate Route Slope to avoid slope collisions
|
43
|
+
s = ((x1 - x) == 0) ? 0 : ((y1 - y) / (x1 - x))
|
44
|
+
# return route if (@slopes[k].include?(s))
|
45
|
+
|
46
|
+
if (keys.include?(c) and !@routes.include?("#{k}#{c}"))
|
47
|
+
a = center_of(k)
|
48
|
+
b = center_of(c)
|
49
|
+
@slopes[k] << s
|
50
|
+
@routes << "#{c}#{k}" # reverse look-up.
|
51
|
+
route = "<!-- #{k} > #{c} --><line class='line#{d}' x1='#{a[0]}' y1='#{a[1]}' x2='#{b[0]}' y2='#{b[1]}' />"
|
52
|
+
end
|
53
|
+
return route
|
54
|
+
end
|
32
55
|
def build_routes
|
33
|
-
routes = []
|
56
|
+
routes = ["<g class='routes'>"]
|
34
57
|
keys = @volumes.map do |v|
|
35
58
|
v[0..3]
|
36
|
-
end
|
37
|
-
slopes = {}
|
59
|
+
end.sort
|
60
|
+
@slopes = {}
|
61
|
+
paths = {
|
62
|
+
"0" => (-4..4).to_a,
|
63
|
+
"1" => (-3..3).to_a,
|
64
|
+
"2" => (-3..3).to_a,
|
65
|
+
"3" => (-2..2).to_a,
|
66
|
+
"4" => (-2..2).to_a,
|
67
|
+
}
|
38
68
|
keys.each do |k|
|
39
69
|
x = k[0..1].to_i
|
40
70
|
y = k[2..3].to_i
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
next if d == 0
|
52
|
-
# Calculate Route Slope to avoid slope collisions
|
53
|
-
s = 0
|
54
|
-
s = (y1 - y) / (x1 - x) unless ((x1 - x) == 0)
|
55
|
-
next if slopes[k].include?(s)
|
56
|
-
slopes[k] << s
|
57
|
-
|
58
|
-
c = "%02d%02d" % [x1, y1]
|
59
|
-
# if (keys.include?(c) and !@routes[c].include?(k))
|
60
|
-
if (keys.include?(c) and !@routes.include?("#{k}#{c}"))
|
61
|
-
a = center_of(k)
|
62
|
-
b = center_of(c)
|
63
|
-
routes << "<!-- #{k} > #{c} --><line class='line#{d}' x1='#{a[0]}' y1='#{a[1]}' x2='#{b[0]}' y2='#{b[1]}' />"
|
64
|
-
# @routes[k] << c
|
65
|
-
# @routes[c] = [k] if @routes[c].nil?
|
66
|
-
@routes << "#{c}#{k}" # reverse look-up.
|
71
|
+
@slopes[k] = []
|
72
|
+
paths.keys.each do |pk|
|
73
|
+
[pk.to_i, pk.to_i * -1].each do |m|
|
74
|
+
paths[pk].each do |n|
|
75
|
+
x1 = (x + m)
|
76
|
+
y1 = (y + n)
|
77
|
+
c = "%02d%02d" % [x1, y1]
|
78
|
+
k = "%02d%02d" % [x, y]
|
79
|
+
puts "#{k}:#{c} (#{x}, #{y}) (#{x1}, #{y1}) / (#{pk}:#{paths[pk].inspect}):(#{m}:#{n})"
|
80
|
+
routes << calc_route(keys,x,x1,y,y1)
|
67
81
|
end
|
68
82
|
end
|
69
83
|
end
|
70
84
|
end
|
71
|
-
routes
|
85
|
+
routes << "</g>"
|
86
|
+
routes.compact.join("\n")
|
72
87
|
end
|
73
88
|
def convert
|
74
89
|
from_file
|
@@ -120,27 +135,25 @@ module Astromapper
|
|
120
135
|
}
|
121
136
|
line {
|
122
137
|
opacity: 0.5;
|
138
|
+
stroke-linecap: round;
|
123
139
|
}
|
124
140
|
line.line1 {
|
125
141
|
stroke: #666;
|
126
142
|
stroke-width:4;
|
127
143
|
}
|
128
144
|
line.line2 {
|
129
|
-
stroke: #
|
145
|
+
stroke: #69C;
|
130
146
|
stroke-width:3;
|
131
147
|
}
|
132
148
|
line.line3 {
|
133
|
-
stroke: #
|
149
|
+
stroke: #C96;
|
134
150
|
stroke-width:2;
|
135
|
-
|
136
|
-
display:none;
|
151
|
+
stroke-dasharray: 5, 5, 1, 5;
|
137
152
|
}
|
138
153
|
line.line4 {
|
139
|
-
stroke: #
|
154
|
+
stroke: #C66;
|
140
155
|
stroke-width:1;
|
141
156
|
stroke-dasharray: 2,6;
|
142
|
-
stroke-linecap: round;
|
143
|
-
display:none;
|
144
157
|
}
|
145
158
|
polyline {
|
146
159
|
fill: none;
|
@@ -169,6 +182,7 @@ module Astromapper
|
|
169
182
|
stroke: #B90;
|
170
183
|
stroke-width: 3;
|
171
184
|
stroke-dasharray: 3,6;
|
185
|
+
stroke-linecap: round;
|
172
186
|
}
|
173
187
|
</style>
|
174
188
|
<rect width='#{@width}' height='#{@height}' />
|
data/lib/astromapper/version.rb
CHANGED