skymap 0.3.0 → 0.5.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 +153 -1
- data/README.md +702 -31
- data/data/LICENSE-deep_sky_objects.txt +30 -0
- data/data/LICENSE-stars.txt +35 -0
- data/data/deep_sky_objects.csv +1742 -0
- data/data/star_names.csv +334 -0
- data/data/stars.bin +0 -0
- data/lib/skymap/canvas.rb +12 -3
- data/lib/skymap/catalog/deep_sky_objects.rb +60 -0
- data/lib/skymap/catalog/star_names.rb +23 -0
- data/lib/skymap/catalog/star_records.rb +322 -0
- data/lib/skymap/catalog/stars.rb +75 -12
- data/lib/skymap/chart.rb +19 -4
- data/lib/skymap/cone.rb +21 -0
- data/lib/skymap/context.rb +326 -8
- data/lib/skymap/deep_sky_object.rb +140 -0
- data/lib/skymap/eyepiece.rb +22 -0
- data/lib/skymap/field.rb +20 -0
- data/lib/skymap/geometry.rb +47 -0
- data/lib/skymap/horizon.rb +33 -3
- data/lib/skymap/label_placement.rb +263 -0
- data/lib/skymap/layers/cardinal_directions.rb +2 -0
- data/lib/skymap/layers/constellation_lines.rb +6 -1
- data/lib/skymap/layers/constellation_names.rb +5 -2
- data/lib/skymap/layers/deep_sky_objects.rb +128 -0
- data/lib/skymap/layers/ecliptic.rb +1 -7
- data/lib/skymap/layers/field_circles.rb +169 -0
- data/lib/skymap/layers/grid.rb +153 -0
- data/lib/skymap/layers/moon.rb +22 -12
- data/lib/skymap/layers/planets.rb +8 -9
- data/lib/skymap/layers/scale.rb +75 -0
- data/lib/skymap/layers/star_names.rb +62 -0
- data/lib/skymap/layers/stars.rb +31 -8
- data/lib/skymap/layers/sun.rb +13 -9
- data/lib/skymap/magnitude_limit.rb +15 -0
- data/lib/skymap/print_size.rb +50 -0
- data/lib/skymap/projection/oblique_stereographic.rb +87 -0
- data/lib/skymap/projection/stereographic.rb +11 -0
- data/lib/skymap/renderer/caption.rb +60 -1
- data/lib/skymap/renderer/deep_sky_symbol.rb +67 -0
- data/lib/skymap/renderer/field_circle.rb +7 -0
- data/lib/skymap/renderer/grid.rb +7 -0
- data/lib/skymap/renderer/horizon_line.rb +7 -0
- data/lib/skymap/renderer/label.rb +3 -1
- data/lib/skymap/renderer/scale_bar.rb +7 -0
- data/lib/skymap/renderer/svg.rb +242 -42
- data/lib/skymap/setup.rb +48 -0
- data/lib/skymap/star.rb +127 -2
- data/lib/skymap/star_list.rb +25 -0
- data/lib/skymap/telescope.rb +17 -0
- data/lib/skymap/theme.rb +148 -0
- data/lib/skymap/version.rb +1 -1
- data/lib/skymap/view.rb +49 -0
- data/lib/skymap.rb +27 -0
- metadata +35 -2
- data/data/stars.csv +0 -9097
|
@@ -3,11 +3,70 @@
|
|
|
3
3
|
module Skymap
|
|
4
4
|
module Renderer
|
|
5
5
|
CAPTION_SIZE_RATIO = 0.028
|
|
6
|
+
CAPTION_CHARACTER_WIDTH_RATIO = 0.55
|
|
7
|
+
|
|
8
|
+
module TextWidth
|
|
9
|
+
def self.of(text, size)
|
|
10
|
+
text.length * size * CAPTION_CHARACTER_WIDTH_RATIO
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def width
|
|
14
|
+
TextWidth.of(text, size)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Caption = Data.define(
|
|
19
|
+
:position,
|
|
20
|
+
:text,
|
|
21
|
+
:size,
|
|
22
|
+
:kind,
|
|
23
|
+
:anchor,
|
|
24
|
+
:clearance
|
|
25
|
+
) do
|
|
26
|
+
include TextWidth
|
|
27
|
+
|
|
28
|
+
def initialize(
|
|
29
|
+
position:,
|
|
30
|
+
text:,
|
|
31
|
+
size:,
|
|
32
|
+
kind:,
|
|
33
|
+
anchor: nil,
|
|
34
|
+
clearance: 0.0
|
|
35
|
+
)
|
|
36
|
+
super
|
|
37
|
+
end
|
|
6
38
|
|
|
7
|
-
Caption = Data.define(:position, :text, :size, :kind) do
|
|
8
39
|
def self.size_for(canvas)
|
|
9
40
|
CAPTION_SIZE_RATIO * canvas.radius
|
|
10
41
|
end
|
|
42
|
+
|
|
43
|
+
def self.beside(center:, radius:, canvas:, text:, kind:)
|
|
44
|
+
size = size_for(canvas)
|
|
45
|
+
towards_center = (center.y > canvas.center.y) ? -1 : 1
|
|
46
|
+
y = center.y + towards_center * (radius + size)
|
|
47
|
+
|
|
48
|
+
new(
|
|
49
|
+
position: Point.new(
|
|
50
|
+
x: within_sky(center.x, y, text, size, canvas),
|
|
51
|
+
y: y
|
|
52
|
+
),
|
|
53
|
+
text: text,
|
|
54
|
+
size: size,
|
|
55
|
+
kind: kind,
|
|
56
|
+
anchor: center,
|
|
57
|
+
clearance: radius
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.within_sky(x, y, text, size, canvas)
|
|
62
|
+
dy = (y - canvas.center.y).abs + size / 2
|
|
63
|
+
room = Math.sqrt([canvas.radius**2 - dy**2, 0].max)
|
|
64
|
+
half_width = TextWidth.of(text, size) / 2
|
|
65
|
+
reach = [room - half_width, 0].max
|
|
66
|
+
|
|
67
|
+
canvas.center.x + (x - canvas.center.x).clamp(-reach, reach)
|
|
68
|
+
end
|
|
69
|
+
private_class_method :within_sky
|
|
11
70
|
end
|
|
12
71
|
end
|
|
13
72
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skymap
|
|
4
|
+
module Renderer
|
|
5
|
+
DeepSkySymbol = Data.define(
|
|
6
|
+
:center,
|
|
7
|
+
:kind,
|
|
8
|
+
:semi_major,
|
|
9
|
+
:semi_minor,
|
|
10
|
+
:rotation,
|
|
11
|
+
:width
|
|
12
|
+
) do
|
|
13
|
+
def hollow?
|
|
14
|
+
DeepSkySymbol::HOLLOW_KINDS.include?(kind)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def outline
|
|
18
|
+
return corners if kind == :nebula
|
|
19
|
+
|
|
20
|
+
steps = outline_steps
|
|
21
|
+
|
|
22
|
+
Array.new(steps) do |step|
|
|
23
|
+
angle = 2 * Math::PI * step / steps
|
|
24
|
+
|
|
25
|
+
at(semi_major * Math.cos(angle), semi_minor * Math.sin(angle))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def outline_steps
|
|
32
|
+
flatness = [1 - DeepSkySymbol::OUTLINE_TOLERANCE / semi_major, -1].max
|
|
33
|
+
|
|
34
|
+
(Math::PI / Math.acos(flatness)).ceil
|
|
35
|
+
.clamp(DeepSkySymbol::MIN_OUTLINE_STEPS,
|
|
36
|
+
DeepSkySymbol::MAX_OUTLINE_STEPS)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def corners
|
|
40
|
+
[[-1, -1], [1, -1], [1, 1], [-1, 1]].map do |sx, sy|
|
|
41
|
+
at(sx * semi_major, sy * semi_minor)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def at(dx, dy)
|
|
46
|
+
turn = rotation * Math::PI / 180
|
|
47
|
+
|
|
48
|
+
Point.new(
|
|
49
|
+
x: center.x + dx * Math.cos(turn) - dy * Math.sin(turn),
|
|
50
|
+
y: center.y + dx * Math.sin(turn) + dy * Math.cos(turn)
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
DeepSkySymbol::HOLLOW_KINDS = %i[
|
|
56
|
+
galaxy
|
|
57
|
+
open_cluster
|
|
58
|
+
asterism
|
|
59
|
+
supernova_remnant
|
|
60
|
+
planetary_nebula
|
|
61
|
+
nebula
|
|
62
|
+
].freeze
|
|
63
|
+
DeepSkySymbol::OUTLINE_TOLERANCE = 0.5
|
|
64
|
+
DeepSkySymbol::MIN_OUTLINE_STEPS = 8
|
|
65
|
+
DeepSkySymbol::MAX_OUTLINE_STEPS = 720
|
|
66
|
+
end
|
|
67
|
+
end
|
data/lib/skymap/renderer/svg.rb
CHANGED
|
@@ -5,50 +5,82 @@ require "victor"
|
|
|
5
5
|
module Skymap
|
|
6
6
|
module Renderer
|
|
7
7
|
class SVG
|
|
8
|
-
SKY_COLOR = "#000000"
|
|
9
|
-
HORIZON_COLOR = "#3262a8"
|
|
10
8
|
HORIZON_WIDTH = 3
|
|
11
|
-
|
|
12
|
-
LINE_COLOR = "#46689c"
|
|
13
|
-
BOUNDARY_COLOR = "#2b3f5e"
|
|
9
|
+
FRAME_WIDTH = 1
|
|
14
10
|
BOUNDARY_DASH_RATIO = 4
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
LABEL_COLOR = HORIZON_COLOR
|
|
23
|
-
LABEL_FONT = "sans-serif"
|
|
24
|
-
|
|
25
|
-
def initialize(canvas:)
|
|
11
|
+
DEEP_SKY_DASH_RATIO = 3
|
|
12
|
+
DEEP_SKY_DOT_GAP_RATIO = 2.5
|
|
13
|
+
DEEP_SKY_TICK_RATIO = 0.6
|
|
14
|
+
DEEP_SKY_BAR_RATIO = 1.8
|
|
15
|
+
DEEP_SKY_CORNER_RATIO = 0.3
|
|
16
|
+
|
|
17
|
+
def initialize(canvas:, theme:, clipped: false)
|
|
26
18
|
@canvas = canvas
|
|
19
|
+
@theme = theme
|
|
20
|
+
@clipped = clipped
|
|
27
21
|
end
|
|
28
22
|
|
|
29
23
|
def render(elements)
|
|
24
|
+
printed_size = (@canvas.print_size || @canvas.size).to_s
|
|
30
25
|
svg = Victor::SVG.new(
|
|
31
26
|
viewBox: "0 0 #{@canvas.size} #{@canvas.size}",
|
|
32
|
-
width:
|
|
33
|
-
height:
|
|
27
|
+
width: printed_size,
|
|
28
|
+
height: printed_size
|
|
34
29
|
)
|
|
35
30
|
|
|
31
|
+
draw_background(svg)
|
|
32
|
+
|
|
36
33
|
svg.circle(
|
|
37
34
|
cx: @canvas.center.x.round(2),
|
|
38
35
|
cy: @canvas.center.y.round(2),
|
|
39
36
|
r: @canvas.radius.round(2),
|
|
40
|
-
fill:
|
|
41
|
-
stroke:
|
|
42
|
-
stroke_width: HORIZON_WIDTH
|
|
37
|
+
fill: @theme.sky,
|
|
38
|
+
stroke: @theme.horizon,
|
|
39
|
+
stroke_width: @clipped ? FRAME_WIDTH : HORIZON_WIDTH
|
|
43
40
|
)
|
|
44
41
|
|
|
42
|
+
if @clipped
|
|
43
|
+
clip_to_sky(svg)
|
|
44
|
+
svg.g(clip_path: "url(##{clip_id})") { draw_elements(svg, elements) }
|
|
45
|
+
else
|
|
46
|
+
draw_elements(svg, elements)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
svg.render
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def clip_to_sky(svg)
|
|
55
|
+
radius = @canvas.radius.round(2)
|
|
56
|
+
cx = @canvas.center.x.round(2)
|
|
57
|
+
cy = @canvas.center.y.round(2)
|
|
58
|
+
|
|
59
|
+
svg.defs do
|
|
60
|
+
svg.clipPath(id: clip_id) { svg.circle(cx: cx, cy: cy, r: radius) }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def clip_id
|
|
65
|
+
geometry = [@canvas.center.x, @canvas.center.y, @canvas.radius]
|
|
66
|
+
.map { |value| value.round(2).to_s.tr(".", "_") }
|
|
67
|
+
|
|
68
|
+
"sky-#{geometry.join("-")}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def draw_elements(svg, elements)
|
|
45
72
|
elements.each do |element|
|
|
46
73
|
case element
|
|
47
74
|
when Boundary then draw_boundary(svg, element)
|
|
48
75
|
when Caption then draw_caption(svg, element)
|
|
49
76
|
when Line then draw_line(svg, element)
|
|
77
|
+
when ScaleBar then draw_scale_bar(svg, element)
|
|
78
|
+
when DeepSkySymbol then draw_deep_sky_symbol(svg, element)
|
|
50
79
|
when Dot then draw_dot(svg, element)
|
|
51
80
|
when Ecliptic then draw_ecliptic(svg, element)
|
|
81
|
+
when FieldCircle then draw_field_circle(svg, element)
|
|
82
|
+
when Grid then draw_grid(svg, element)
|
|
83
|
+
when HorizonLine then draw_horizon_line(svg, element)
|
|
52
84
|
when Label then draw_label(svg, element)
|
|
53
85
|
when Moon then draw_moon(svg, element)
|
|
54
86
|
when Planet then draw_planet(svg, element)
|
|
@@ -56,11 +88,24 @@ module Skymap
|
|
|
56
88
|
else raise ArgumentError, "unknown element: #{element.class}"
|
|
57
89
|
end
|
|
58
90
|
end
|
|
91
|
+
end
|
|
59
92
|
|
|
60
|
-
|
|
93
|
+
def format_points(points)
|
|
94
|
+
points.map { |point| "#{point.x.round(2)},#{point.y.round(2)}" }
|
|
95
|
+
.join(" ")
|
|
61
96
|
end
|
|
62
97
|
|
|
63
|
-
|
|
98
|
+
def draw_background(svg)
|
|
99
|
+
return if @theme.background == "none"
|
|
100
|
+
|
|
101
|
+
svg.rect(
|
|
102
|
+
x: 0,
|
|
103
|
+
y: 0,
|
|
104
|
+
width: @canvas.size,
|
|
105
|
+
height: @canvas.size,
|
|
106
|
+
fill: @theme.background
|
|
107
|
+
)
|
|
108
|
+
end
|
|
64
109
|
|
|
65
110
|
def draw_line(svg, line)
|
|
66
111
|
svg.line(
|
|
@@ -68,34 +113,67 @@ module Skymap
|
|
|
68
113
|
y1: line.from.y.round(2),
|
|
69
114
|
x2: line.to.x.round(2),
|
|
70
115
|
y2: line.to.y.round(2),
|
|
71
|
-
stroke:
|
|
116
|
+
stroke: @theme.constellation_line,
|
|
72
117
|
stroke_width: line.width.round(2),
|
|
73
118
|
stroke_linecap: "round"
|
|
74
119
|
)
|
|
75
120
|
end
|
|
76
121
|
|
|
122
|
+
def draw_scale_bar(svg, bar)
|
|
123
|
+
top = bar.from.y - bar.tick
|
|
124
|
+
points = [
|
|
125
|
+
Point.new(x: bar.from.x, y: top), bar.from,
|
|
126
|
+
bar.to, Point.new(x: bar.to.x, y: top)
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
svg.polyline(
|
|
130
|
+
points: format_points(points),
|
|
131
|
+
fill: "none",
|
|
132
|
+
stroke: @theme.scale,
|
|
133
|
+
stroke_width: bar.width.round(2)
|
|
134
|
+
)
|
|
135
|
+
end
|
|
136
|
+
|
|
77
137
|
def draw_boundary(svg, boundary)
|
|
78
138
|
dash = (boundary.width * BOUNDARY_DASH_RATIO).round(2)
|
|
79
139
|
|
|
80
140
|
svg.polyline(
|
|
81
|
-
points: boundary.points
|
|
82
|
-
"#{point.x.round(2)},#{point.y.round(2)}"
|
|
83
|
-
}.join(" "),
|
|
141
|
+
points: format_points(boundary.points),
|
|
84
142
|
fill: "none",
|
|
85
|
-
stroke:
|
|
143
|
+
stroke: @theme.boundary,
|
|
86
144
|
stroke_width: boundary.width.round(2),
|
|
87
145
|
stroke_dasharray: "#{dash} #{dash}"
|
|
88
146
|
)
|
|
89
147
|
end
|
|
90
148
|
|
|
91
149
|
def draw_ecliptic(svg, ecliptic)
|
|
150
|
+
draw_polyline(svg, ecliptic, @theme.ecliptic)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def draw_field_circle(svg, circle)
|
|
154
|
+
draw_polyline(svg, circle, @theme.field_circle)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def draw_grid(svg, grid)
|
|
158
|
+
draw_polyline(svg, grid, @theme.grid)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def draw_polyline(svg, element, stroke)
|
|
162
|
+
svg.polyline(
|
|
163
|
+
points: format_points(element.points),
|
|
164
|
+
fill: "none",
|
|
165
|
+
stroke: stroke,
|
|
166
|
+
stroke_width: element.width.round(2),
|
|
167
|
+
stroke_linejoin: "round"
|
|
168
|
+
)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def draw_horizon_line(svg, line)
|
|
92
172
|
svg.polyline(
|
|
93
|
-
points:
|
|
94
|
-
"#{point.x.round(2)},#{point.y.round(2)}"
|
|
95
|
-
}.join(" "),
|
|
173
|
+
points: format_points(line.points),
|
|
96
174
|
fill: "none",
|
|
97
|
-
stroke:
|
|
98
|
-
stroke_width:
|
|
175
|
+
stroke: @theme.horizon,
|
|
176
|
+
stroke_width: HORIZON_WIDTH,
|
|
99
177
|
stroke_linejoin: "round"
|
|
100
178
|
)
|
|
101
179
|
end
|
|
@@ -105,7 +183,7 @@ module Skymap
|
|
|
105
183
|
cx: dot.center.x.round(2),
|
|
106
184
|
cy: dot.center.y.round(2),
|
|
107
185
|
r: dot.radius.round(2),
|
|
108
|
-
fill:
|
|
186
|
+
fill: @theme.star
|
|
109
187
|
)
|
|
110
188
|
end
|
|
111
189
|
|
|
@@ -114,7 +192,7 @@ module Skymap
|
|
|
114
192
|
cx: planet.center.x.round(2),
|
|
115
193
|
cy: planet.center.y.round(2),
|
|
116
194
|
r: planet.radius.round(2),
|
|
117
|
-
fill:
|
|
195
|
+
fill: @theme.planet
|
|
118
196
|
)
|
|
119
197
|
end
|
|
120
198
|
|
|
@@ -123,7 +201,7 @@ module Skymap
|
|
|
123
201
|
cx: sun.center.x.round(2),
|
|
124
202
|
cy: sun.center.y.round(2),
|
|
125
203
|
r: sun.radius.round(2),
|
|
126
|
-
fill:
|
|
204
|
+
fill: @theme.sun
|
|
127
205
|
)
|
|
128
206
|
end
|
|
129
207
|
|
|
@@ -139,26 +217,148 @@ module Skymap
|
|
|
139
217
|
lit = "M #{top} A #{radius},#{radius} 0 0 1 #{bottom} " \
|
|
140
218
|
"A #{terminator},#{radius} 0 0 #{bulge} #{top} Z"
|
|
141
219
|
|
|
220
|
+
theme = @theme
|
|
142
221
|
svg.build do
|
|
143
222
|
g(transform: "rotate(#{moon.rotation.round(2)} #{x} #{y})") do
|
|
144
223
|
circle(
|
|
145
224
|
cx: x,
|
|
146
225
|
cy: y,
|
|
147
226
|
r: radius,
|
|
148
|
-
fill:
|
|
149
|
-
fill_opacity:
|
|
227
|
+
fill: theme.moon_shadow,
|
|
228
|
+
fill_opacity: theme.moon_shadow_opacity.to_f
|
|
150
229
|
)
|
|
151
|
-
path(d: lit, fill:
|
|
230
|
+
path(d: lit, fill: theme.moon)
|
|
152
231
|
end
|
|
153
232
|
end
|
|
154
233
|
end
|
|
155
234
|
|
|
235
|
+
def draw_deep_sky_symbol(svg, symbol)
|
|
236
|
+
x = symbol.center.x.round(2)
|
|
237
|
+
y = symbol.center.y.round(2)
|
|
238
|
+
width = symbol.width.round(2)
|
|
239
|
+
|
|
240
|
+
svg.g(
|
|
241
|
+
transform: "rotate(#{symbol.rotation.round(2)} #{x} #{y})",
|
|
242
|
+
fill: "none",
|
|
243
|
+
stroke: @theme.deep_sky,
|
|
244
|
+
stroke_width: width,
|
|
245
|
+
stroke_linejoin: "round"
|
|
246
|
+
) do
|
|
247
|
+
draw_deep_sky_shape(
|
|
248
|
+
svg,
|
|
249
|
+
symbol.kind,
|
|
250
|
+
x: x,
|
|
251
|
+
y: y,
|
|
252
|
+
rx: symbol.semi_major.round(2),
|
|
253
|
+
ry: symbol.semi_minor.round(2),
|
|
254
|
+
width: width
|
|
255
|
+
)
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def draw_deep_sky_shape(svg, kind, **shape)
|
|
260
|
+
case kind
|
|
261
|
+
when :galaxy then draw_deep_sky_ellipse(svg, **shape)
|
|
262
|
+
when :open_cluster then draw_deep_sky_ellipse(svg, dashed: true,
|
|
263
|
+
**shape)
|
|
264
|
+
when :asterism then draw_deep_sky_ellipse(svg, dotted: true, **shape)
|
|
265
|
+
when :supernova_remnant then draw_remnant(svg, **shape)
|
|
266
|
+
when :globular_cluster then draw_globular_cluster(svg, **shape)
|
|
267
|
+
when :planetary_nebula then draw_planetary_nebula(svg, **shape)
|
|
268
|
+
when :nebula then draw_nebula(svg, **shape)
|
|
269
|
+
when :double_star then draw_double_star(svg, **shape)
|
|
270
|
+
when :other then draw_cross(svg, **shape)
|
|
271
|
+
else raise ArgumentError, "unknown deep-sky object type: #{kind}"
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def draw_deep_sky_ellipse(svg, x:, y:, rx:, ry:, width:, **style)
|
|
276
|
+
svg.ellipse(
|
|
277
|
+
cx: x, cy: y, rx: rx, ry: ry, **deep_sky_dashes(width, **style)
|
|
278
|
+
)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def deep_sky_dashes(width, dashed: false, dotted: false)
|
|
282
|
+
if dashed
|
|
283
|
+
dash = (width * DEEP_SKY_DASH_RATIO).round(2)
|
|
284
|
+
{stroke_dasharray: "#{dash} #{dash}"}
|
|
285
|
+
elsif dotted
|
|
286
|
+
gap = (width * DEEP_SKY_DOT_GAP_RATIO).round(2)
|
|
287
|
+
{stroke_dasharray: "0 #{gap}", stroke_linecap: "round"}
|
|
288
|
+
else
|
|
289
|
+
{}
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def draw_remnant(svg, x:, y:, rx:, ry:, width:)
|
|
294
|
+
draw_deep_sky_ellipse(svg, x: x, y: y, rx: rx, ry: ry, width: width,
|
|
295
|
+
dashed: true)
|
|
296
|
+
svg.circle(cx: x, cy: y, r: width, fill: @theme.deep_sky,
|
|
297
|
+
stroke: "none")
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def draw_globular_cluster(svg, x:, y:, rx:, ry:, width:)
|
|
301
|
+
draw_deep_sky_ellipse(svg, x: x, y: y, rx: rx, ry: ry, width: width)
|
|
302
|
+
draw_cross(svg, x: x, y: y, rx: rx, ry: ry, width: width)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def draw_planetary_nebula(svg, x:, y:, rx:, ry:, width:)
|
|
306
|
+
draw_deep_sky_ellipse(svg, x: x, y: y, rx: rx, ry: ry, width: width)
|
|
307
|
+
tick = (DEEP_SKY_TICK_RATIO * [rx, ry].min).round(2)
|
|
308
|
+
[[1, 0], [-1, 0], [0, 1], [0, -1]].each do |dx, dy|
|
|
309
|
+
svg.line(
|
|
310
|
+
x1: (x + dx * rx).round(2),
|
|
311
|
+
y1: (y + dy * ry).round(2),
|
|
312
|
+
x2: (x + dx * (rx + tick)).round(2),
|
|
313
|
+
y2: (y + dy * (ry + tick)).round(2)
|
|
314
|
+
)
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def draw_nebula(svg, x:, y:, rx:, ry:, width:)
|
|
319
|
+
dash = (width * DEEP_SKY_DASH_RATIO).round(2)
|
|
320
|
+
corner = (DEEP_SKY_CORNER_RATIO * [rx, ry].min).round(2)
|
|
321
|
+
|
|
322
|
+
svg.rect(
|
|
323
|
+
x: (x - rx).round(2),
|
|
324
|
+
y: (y - ry).round(2),
|
|
325
|
+
width: (2 * rx).round(2),
|
|
326
|
+
height: (2 * ry).round(2),
|
|
327
|
+
rx: corner,
|
|
328
|
+
stroke_dasharray: "#{dash} #{dash}"
|
|
329
|
+
)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def draw_double_star(svg, x:, y:, rx:, ry:, width:)
|
|
333
|
+
draw_deep_sky_ellipse(svg, x: x, y: y, rx: rx, ry: ry, width: width)
|
|
334
|
+
reach = (DEEP_SKY_BAR_RATIO * rx).round(2)
|
|
335
|
+
svg.line(x1: (x - reach).round(2), y1: y, x2: (x + reach).round(2),
|
|
336
|
+
y2: y)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def draw_cross(svg, x:, y:, rx:, ry:, **)
|
|
340
|
+
svg.line(x1: (x - rx).round(2), y1: y, x2: (x + rx).round(2), y2: y)
|
|
341
|
+
svg.line(x1: x, y1: (y - ry).round(2), x2: x, y2: (y + ry).round(2))
|
|
342
|
+
end
|
|
343
|
+
|
|
156
344
|
def draw_label(svg, label)
|
|
157
|
-
draw_text(svg, label,
|
|
345
|
+
draw_text(svg, label, @theme.label)
|
|
158
346
|
end
|
|
159
347
|
|
|
160
348
|
def draw_caption(svg, caption)
|
|
161
|
-
draw_text(svg, caption,
|
|
349
|
+
draw_text(svg, caption, caption_color(caption.kind))
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
def caption_color(kind)
|
|
353
|
+
case kind
|
|
354
|
+
when :constellation then @theme.constellation_name
|
|
355
|
+
when :star then @theme.star_name
|
|
356
|
+
when :planet then @theme.planet_name
|
|
357
|
+
when :field then @theme.field_circle
|
|
358
|
+
when :scale then @theme.scale
|
|
359
|
+
when :deep_sky then @theme.deep_sky
|
|
360
|
+
else raise ArgumentError, "unknown caption kind: #{kind}"
|
|
361
|
+
end
|
|
162
362
|
end
|
|
163
363
|
|
|
164
364
|
def draw_text(svg, label, fill)
|
|
@@ -167,7 +367,7 @@ module Skymap
|
|
|
167
367
|
x: label.position.x.round(2),
|
|
168
368
|
y: label.position.y.round(2),
|
|
169
369
|
font_size: label.size.round(2),
|
|
170
|
-
font_family:
|
|
370
|
+
font_family: @theme.font,
|
|
171
371
|
text_anchor: "middle",
|
|
172
372
|
dominant_baseline: "central",
|
|
173
373
|
fill: fill
|
data/lib/skymap/setup.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skymap
|
|
4
|
+
Setup = Data.define(:telescope, :eyepiece) do
|
|
5
|
+
def initialize(telescope:, eyepiece:)
|
|
6
|
+
unless telescope.is_a?(Telescope)
|
|
7
|
+
raise ArgumentError, "telescope must be a Skymap::Telescope"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
unless eyepiece.is_a?(Eyepiece)
|
|
11
|
+
raise ArgumentError, "eyepiece must be a Skymap::Eyepiece"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def magnification
|
|
18
|
+
telescope.focal_length_mm.fdiv(eyepiece.focal_length_mm)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def true_field
|
|
22
|
+
Astronoby::Angle.from_degrees(
|
|
23
|
+
eyepiece.apparent_field_of_view.degrees / magnification
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def label
|
|
28
|
+
"#{plain(eyepiece.focal_length_mm.to_f)} mm, " \
|
|
29
|
+
"#{magnification.round}×, #{plain_angle(true_field)}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def plain_angle(angle)
|
|
35
|
+
seconds = (angle.degrees * 3600).round
|
|
36
|
+
return "#{seconds}″" if seconds < 60
|
|
37
|
+
|
|
38
|
+
minutes = (angle.degrees * 60).round
|
|
39
|
+
return "#{minutes}′" if minutes < 60
|
|
40
|
+
|
|
41
|
+
"#{plain(angle.degrees.round(1))}°"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def plain(number)
|
|
45
|
+
number.to_s.delete_suffix(".0")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|