usps_flags 0.1.26 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,33 @@
5
5
  class USPSFlags::Core::TridentSpec
6
6
  def initialize(fly: 24, unit: "in")
7
7
  @trident_config = USPSFlags::Config.trident
8
+ configure_sizes(fly)
9
+ configure_labels(unit)
10
+ end
11
+
12
+ def svg
13
+ svg = spec_header
14
+
15
+ box_left = (USPSFlags::Config::BASE_FLY*27/32)/2
16
+ box_right = (USPSFlags::Config::BASE_FLY*37/32)/2
17
+ box_top = USPSFlags::Config::BASE_HOIST/4
18
+ box_bottom = USPSFlags::Config::BASE_HOIST*3/4
19
+ svg << short_trident(box_top, box_bottom, box_left, box_right)
20
+
21
+ box_top = USPSFlags::Config::BASE_HOIST*3/16
22
+ box_bottom = USPSFlags::Config::BASE_HOIST*13/16
23
+ svg << delta_trident(box_top, box_bottom, box_left, box_right)
24
+
25
+ box_top = USPSFlags::Config::BASE_HOIST/8
26
+ box_bottom = USPSFlags::Config::BASE_HOIST*7/8
27
+ svg << circle_trident(box_top, box_bottom, box_left, box_right)
28
+ svg << long_trident(box_top, box_bottom, box_left, box_right)
29
+
30
+ svg
31
+ end
32
+
33
+ private
34
+ def configure_sizes(fly)
8
35
  hoist = (fly*Rational(2,3))
9
36
  @hoist = hoist == hoist.to_i ? hoist.to_i : hoist
10
37
 
@@ -15,12 +42,15 @@ class USPSFlags::Core::TridentSpec
15
42
  else
16
43
  @fly, @fly_fraction = fly.to_simplified_a
17
44
  end
45
+
18
46
  if hoist == hoist.to_i
19
47
  @hoist = hoist.to_i
20
48
  else
21
49
  @hoist, @hoist_fraction = hoist.to_simplified_a
22
50
  end
51
+ end
23
52
 
53
+ def configure_labels(unit)
24
54
  @label_font_size = if Math.sqrt(@fly) > 24
25
55
  USPSFlags::Config::BASE_FLY * Math.log(24, Math.sqrt(@fly)) / 60
26
56
  else
@@ -35,10 +65,8 @@ class USPSFlags::Core::TridentSpec
35
65
  @barb_label = "#{barb_label}#{@unit_text}"
36
66
  end
37
67
 
38
- def svg
39
- svg = ""
40
-
41
- svg << <<~SVG
68
+ def spec_header
69
+ <<~SVG
42
70
  <!-- Field -->
43
71
  #{USPSFlags::Core.field}
44
72
 
@@ -55,14 +83,10 @@ class USPSFlags::Core::TridentSpec
55
83
  </g>
56
84
  <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST/4}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/40}px" fill="#041E42" text-anchor="middle">Measurements not specified are the same as on the short trident.</text>
57
85
  SVG
86
+ end
58
87
 
59
- box_width = USPSFlags::Config::BASE_FLY*5/32
60
- box_left = (USPSFlags::Config::BASE_FLY*27/32)/2
61
- box_right = (USPSFlags::Config::BASE_FLY*37/32)/2
62
- box_top = USPSFlags::Config::BASE_HOIST/4
63
- box_bottom = USPSFlags::Config::BASE_HOIST*3/4
64
-
65
- svg << <<~SVG
88
+ def short_trident(box_top, box_bottom, box_left, box_right)
89
+ <<~SVG
66
90
  <!-- Short Trident -->
67
91
  <g transform="translate(-#{USPSFlags::Config::BASE_FLY*14/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
68
92
  <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Short</text>
@@ -71,29 +95,29 @@ class USPSFlags::Core::TridentSpec
71
95
  #{USPSFlags::Core::Trident.new(:s).svg}
72
96
 
73
97
  <!-- Boundary box -->
74
- <rect x="#{box_left}" y="#{box_top}" width="#{box_width}" height="#{USPSFlags::Config::BASE_HOIST/2}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
98
+ <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST/2}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
75
99
 
76
100
  <!-- Right -->
77
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top, box_top+@trident_config[:bar_width], box_right, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Side spike top gap -->
78
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Top gap to hash gap -->
79
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Crossbar to hash gap -->
101
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top, box_top+@trident_config[:bar_width], box_right, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Side spike top gap -->
102
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Top gap to hash gap -->
103
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Crossbar to hash gap -->
80
104
 
81
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash -->
82
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_bottom, nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash to bottom -->
105
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash -->
106
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_bottom, nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash to bottom -->
83
107
 
84
108
  <!-- Left -->
85
- #{USPSFlags::Helpers.v_arrow(box_left-@trident_config[:bar_width]*5.25, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Boundary height -->
86
- #{USPSFlags::Helpers.v_arrow(box_left-@trident_config[:bar_width]*0.75, box_top, box_top+@trident_config[:point_height], nil, @trident_config[:center_point]-@trident_config[:bar_width], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/26, label_offset_y: -USPSFlags::Config::BASE_FLY/100, font_size: @label_font_size, label_align: "middle")} <!-- Main point height -->
87
- #{USPSFlags::Helpers.v_arrow(box_left-@trident_config[:bar_width]*1.5, box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]+@trident_config[:point_height], box_left, box_left+@trident_config[:bar_width], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/24, font_size: @label_font_size, label_align: "middle")} <!-- Side point height -->
109
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*5.25, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Boundary height -->
110
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*0.75, box_top, box_top+@trident_config[:point_height], nil, @trident_config[:center_point]-@trident_config[:bar_width], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/26, label_offset_y: -USPSFlags::Config::BASE_FLY/100, font_size: @label_font_size, label_align: "middle")} <!-- Main point height -->
111
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]+@trident_config[:point_height], box_left, box_left+@trident_config[:bar_width], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/24, font_size: @label_font_size, label_align: "middle")} <!-- Side point height -->
88
112
 
89
113
  <!-- Bottom -->
90
- #{USPSFlags::Helpers.h_arrow(box_bottom+@trident_config[:bar_width], @trident_config[:center_point]-@trident_config[:bar_width]/2, @trident_config[:center_point]+@trident_config[:bar_width]/2, box_bottom, box_bottom, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Bar width -->
91
- #{USPSFlags::Helpers.h_arrow(box_bottom+@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:hash_width]/2, @trident_config[:center_point]+@trident_config[:hash_width]/2, box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash width -->
92
- #{USPSFlags::Helpers.h_arrow(box_bottom+@trident_config[:bar_width]*4, box_left, box_right, box_bottom, box_bottom, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Boundary width -->
114
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width], @trident_config[:center_point]-@trident_config[:bar_width]/2, @trident_config[:center_point]+@trident_config[:bar_width]/2, box_bottom, box_bottom, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Bar width -->
115
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:hash_width]/2, @trident_config[:center_point]+@trident_config[:hash_width]/2, box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash width -->
116
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width]*4, box_left, box_right, box_bottom, box_bottom, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Boundary width -->
93
117
 
94
118
  <!-- Top -->
95
- #{USPSFlags::Helpers.h_arrow(box_top-@trident_config[:bar_width], box_left, box_left+@trident_config[:bar_width]*3/2, box_top, box_top+@trident_config[:bar_width]+@trident_config[:point_height], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/60, font_size: @label_font_size)} <!-- Side point width -->
96
- #{USPSFlags::Helpers.h_arrow(box_top-@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:bar_width], @trident_config[:center_point]+@trident_config[:bar_width], box_top+@trident_config[:point_height], box_top+@trident_config[:point_height], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/60, font_size: @label_font_size)} <!-- Main point width -->
119
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_top-@trident_config[:bar_width], box_left, box_left+@trident_config[:bar_width]*3/2, box_top, box_top+@trident_config[:bar_width]+@trident_config[:point_height], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/60, font_size: @label_font_size)} <!-- Side point width -->
120
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_top-@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:bar_width], @trident_config[:center_point]+@trident_config[:bar_width], box_top+@trident_config[:point_height], box_top+@trident_config[:point_height], fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/60, font_size: @label_font_size)} <!-- Main point width -->
97
121
 
98
122
  <!-- Overlay -->
99
123
  <!-- Main point barb -->
@@ -102,11 +126,10 @@ class USPSFlags::Core::TridentSpec
102
126
  <text x="#{@trident_config[:center_point]+@trident_config[:bar_width]*5/4}" y="#{box_top+@trident_config[:point_height]-@trident_config[:main_point_barb]}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_FLY/100}px" fill="#041E42" text-anchor="left">#{@barb_label}</text>
103
127
  </g></g>
104
128
  SVG
129
+ end
105
130
 
106
- box_top = USPSFlags::Config::BASE_HOIST*3/16
107
- box_bottom = USPSFlags::Config::BASE_HOIST*13/16
108
-
109
- svg << <<~SVG
131
+ def delta_trident(box_top, box_bottom, box_left, box_right)
132
+ <<~SVG
110
133
  <!-- Delta Trident -->
111
134
  <g transform="translate(#{USPSFlags::Config::BASE_FLY*5/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
112
135
  <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Delta</text>
@@ -115,22 +138,21 @@ class USPSFlags::Core::TridentSpec
115
138
  #{USPSFlags::Core::Trident.new(:d).svg}
116
139
 
117
140
  <!-- Boundary box -->
118
- <rect x="#{box_left}" y="#{box_top}" width="#{box_width}" height="#{USPSFlags::Config::BASE_HOIST*5/8}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
141
+ <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST*5/8}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
119
142
 
120
143
  <!-- Right -->
121
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width]-@trident_config[:delta_gap_height], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], @trident_config[:center_point], @trident_config[:center_point]+@trident_config[:delta_gap_width], fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Delta gap height -->
122
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Delta width -->
123
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], box_bottom, nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Delta to bottom -->
144
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width]-@trident_config[:delta_gap_height], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], @trident_config[:center_point], @trident_config[:center_point]+@trident_config[:delta_gap_width], fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Delta gap height -->
145
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Delta width -->
146
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], box_bottom, nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Delta to bottom -->
124
147
 
125
148
  <!-- Left -->
126
- #{USPSFlags::Helpers.v_arrow(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY*2/11, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
149
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY*2/11, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
127
150
  </g></g>
128
151
  SVG
152
+ end
129
153
 
130
- box_top = USPSFlags::Config::BASE_HOIST/8
131
- box_bottom = USPSFlags::Config::BASE_HOIST*7/8
132
-
133
- svg << <<~SVG
154
+ def circle_trident(box_top, box_bottom, box_left, box_right)
155
+ <<~SVG
134
156
  <!-- Circle Trident -->
135
157
  <g transform="translate(#{USPSFlags::Config::BASE_FLY*23/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
136
158
  <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Circle</text>
@@ -139,19 +161,21 @@ class USPSFlags::Core::TridentSpec
139
161
  #{USPSFlags::Core::Trident.new(:stf).svg}
140
162
 
141
163
  <!-- Boundary box -->
142
- <rect x="#{box_left}" y="#{box_top}" width="#{box_width}" height="#{USPSFlags::Config::BASE_HOIST*3/4}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
164
+ <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST*3/4}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
143
165
 
144
166
  <!-- Right -->
145
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*2, box_top+@trident_config[:crossbar_from_top]+@trident_config[:width], @trident_config[:center_point], @trident_config[:center_point], fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Inner circle diameter -->
146
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]+@trident_config[:width], nil, @trident_config[:center_point]+@trident_config[:bar_width]/2, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Outer circle diameter -->
147
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]+@trident_config[:width], box_bottom, nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Circle to bottom -->
167
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*2, box_top+@trident_config[:crossbar_from_top]+@trident_config[:width], @trident_config[:center_point], @trident_config[:center_point], fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Inner circle diameter -->
168
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]+@trident_config[:width], nil, @trident_config[:center_point]+@trident_config[:bar_width]/2, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Outer circle diameter -->
169
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]+@trident_config[:width], box_bottom, nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Circle to bottom -->
148
170
 
149
171
  <!-- Left -->
150
- #{USPSFlags::Helpers.v_arrow(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
172
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
151
173
  </g></g>
152
174
  SVG
175
+ end
153
176
 
154
- svg << <<~SVG
177
+ def long_trident(box_top, box_bottom, box_left, box_right)
178
+ <<~SVG
155
179
  <!-- Long Trident -->
156
180
  <g transform="translate(#{USPSFlags::Config::BASE_FLY*40/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
157
181
  <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Long</text>
@@ -160,16 +184,14 @@ class USPSFlags::Core::TridentSpec
160
184
  #{USPSFlags::Core::Trident.new(:n).svg}
161
185
 
162
186
  <!-- Boundary box -->
163
- <rect x="#{box_left}" y="#{box_top}" width="#{box_width}" height="#{USPSFlags::Config::BASE_HOIST*3/4}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
187
+ <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST*3/4}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
164
188
 
165
189
  <!-- Right -->
166
- #{USPSFlags::Helpers.v_arrow(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*3, box_bottom, @trident_config[:center_point]+@trident_config[:hash_width]/2, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash to bottom -->
190
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*3, box_bottom, @trident_config[:center_point]+@trident_config[:hash_width]/2, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash to bottom -->
167
191
 
168
192
  <!-- Left -->
169
- #{USPSFlags::Helpers.v_arrow(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
193
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
170
194
  </g></g>
171
195
  SVG
172
-
173
- svg
174
196
  end
175
197
  end
@@ -0,0 +1,61 @@
1
+ # SVG generators for multiple tridents.
2
+ #
3
+ # These methods should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Tridents
6
+ class << self
7
+ def cc(type, trident_color:)
8
+ # The side C/C tridents are angled 45 degrees, and intersect the central one at 1/3 up from the bottom
9
+ trident = USPSFlags::Core.trident(type, color: trident_color)
10
+ x_distance = USPSFlags::Config::BASE_FLY*4/39
11
+ y_distance = USPSFlags::Config::BASE_FLY*5/78
12
+ <<~SVG
13
+ <g transform="translate(-#{x_distance}, #{y_distance})"><g transform="rotate(-45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})">\n#{trident}</g></g>
14
+ \n#{trident}
15
+ <g transform="translate(#{x_distance}, #{y_distance})"><g transform="rotate(45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})">\n#{trident}</g></g>
16
+ SVG
17
+ end
18
+
19
+ def vc(type, trident_color:)
20
+ # V/C tridents are angled 45 degrees, and intersect at 15/32 up from the bottom
21
+ trident = USPSFlags::Core.trident(type, color: trident_color)
22
+ x_distance = USPSFlags::Config::BASE_FLY*4/55
23
+ <<~SVG
24
+ <g transform="translate(-#{x_distance})"><g transform="rotate(-45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})">\n#{trident}</g></g>
25
+ <g transform="translate(#{x_distance})"><g transform="rotate(45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})">\n#{trident}</g></g>
26
+ SVG
27
+ end
28
+
29
+ def three(type, trident_color:, field_color:)
30
+ # Cdr and D/C tridents are spaced 1/2 the fly apart with the central one 1/4 the fly above the sides
31
+ trident = USPSFlags::Core.trident(type, color: trident_color, field_color: field_color)
32
+ x_distance = USPSFlags::Config::BASE_FLY/4
33
+ y_distance = USPSFlags::Config::BASE_FLY/16
34
+ <<~SVG
35
+ <g transform="translate(-#{x_distance}, #{y_distance})">\n#{trident}</g>
36
+ <g transform="translate(0, -#{y_distance+1})">\n#{trident}</g>
37
+ <g transform="translate(#{x_distance}, #{y_distance})">\n#{trident}</g>
38
+ SVG
39
+ end
40
+
41
+ def two(type, trident_color:, field_color:)
42
+ # Lt/C and D/Lt/C tridents are spaced 1/3 the fly apart
43
+ trident = USPSFlags::Core.trident(type, color: trident_color, field_color: field_color)
44
+ x_distance = USPSFlags::Config::BASE_FLY/6
45
+ <<~SVG
46
+ <g transform="translate(-#{x_distance})">\n#{trident}</g>
47
+ <g transform="translate(#{x_distance})">\n#{trident}</g>
48
+ SVG
49
+ end
50
+
51
+ def offset(type, field_color:, field: true)
52
+ # Swallowtail tridents need to move towards the hoist due to the tails
53
+ x_distance = USPSFlags::Config::BASE_FLY/10 if field
54
+ svg = ""
55
+ svg << "<g transform=\"translate(-#{x_distance})\">" if field
56
+ svg << USPSFlags::Core.trident(type, field_color: field_color, color: :red)
57
+ svg << "</g>" if field
58
+ svg
59
+ end
60
+ end
61
+ end
@@ -9,7 +9,17 @@ class USPSFlags::Core::Trumpet
9
9
  end
10
10
 
11
11
  def svg
12
- trumpet = "<path d=\"M1139.9999958974363,480.00000000000006c-44.15476410256406,-6.5910035897434796,-116.84910635897381,-20.41065056410247,-114.87185282051291,-47.179479230769175c4.028547230769618,-65.74318056410249,367.85434817948703,-61.23149248717954,369.23087128205134,-2.051282051282101c-4.777324897435847,30.46226187179502,-55.229016102563946,41.4042592820515,-114.87183128205106,49.230751282051415c20.35720646153868,375.0059741538461,27.19074102564059,490.4570292564102,53.33331769230767,1003.0769130769231c87.68105358974367,28.51730900000007,159.61708317948705,60.951568051282266,231.79492435897487,145.6410723076924c-309.3606388717951,-1.4643622051280545,-403.6171671794875,0.35877820512882863,-709.7436194871801,-2.0512861538461493c106.18124384615362,-96.7690410256414,99.88082358974339,-91.1716969230772,229.74356769230792,-141.53843102564088\" fill=\"#{color}\" />"
12
+ trumpet = <<~SVG
13
+ <path d="M1139.9999958974363,480.00000000000006
14
+ c-44.15476410256406,-6.5910035897434796,-116.84910635897381,-20.41065056410247,-114.87185282051291,-47.179479230769175
15
+ c4.028547230769618,-65.74318056410249,367.85434817948703,-61.23149248717954,369.23087128205134,-2.051282051282101
16
+ c-4.777324897435847,30.46226187179502,-55.229016102563946,41.4042592820515,-114.87183128205106,49.230751282051415
17
+ c20.35720646153868,375.0059741538461,27.19074102564059,490.4570292564102,53.33331769230767,1003.0769130769231
18
+ c87.68105358974367,28.51730900000007,159.61708317948705,60.951568051282266,231.79492435897487,145.6410723076924
19
+ c-309.3606388717951,-1.4643622051280545,-403.6171671794875,0.35877820512882863,-709.7436194871801,-2.0512861538461493
20
+ c106.18124384615362,-96.7690410256414,99.88082358974339,-91.1716969230772,229.74356769230792,-141.53843102564088"
21
+ fill="#{@color}" />
22
+ SVG
13
23
 
14
24
  if @count == 2
15
25
  <<~SVG
@@ -0,0 +1,115 @@
1
+ # SVG generators for special flags.
2
+ #
3
+ # These methods should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Generate::Flag
6
+ class << self
7
+ def officer(rank: nil, width: USPSFlags::Config::BASE_FLY, outfile: nil, scale: nil, field: true)
8
+ raise "Error: No rank specified." if rank.nil?
9
+ rank = rank.to_s.upcase
10
+
11
+ svg = ""
12
+ svg << USPSFlags::Core.headers(scale: scale, title: rank)
13
+
14
+ rank.slice!(0) if !field && USPSFlags::Helpers.valid_flags(:past).include?(rank)
15
+ rank = "CDR" if rank == "C"
16
+
17
+ flag_details = USPSFlags::Helpers.flag_details(rank)
18
+ trident_color = field ? :white : flag_details[:color]
19
+
20
+ svg << USPSFlags::Core.field(style: flag_details[:style], color: flag_details[:color]) if field
21
+ svg << "<g transform=\"translate(-150, 400)\"><g transform=\"scale(0.58333)\">" if flag_details[:style] == :past
22
+
23
+ if flag_details[:type] == :n && flag_details[:count] == 3
24
+ svg << USPSFlags::Core::Tridents.cc(flag_details[:type], trident_color: trident_color)
25
+ elsif flag_details[:type] == :n && flag_details[:count] == 2
26
+ svg << USPSFlags::Core::Tridents.vc(flag_details[:type], trident_color: trident_color)
27
+ elsif [:s, :d].include?(flag_details[:type]) && flag_details[:count] == 3
28
+ svg << USPSFlags::Core::Tridents.three(flag_details[:type], trident_color: trident_color, field_color: flag_details[:color])
29
+ elsif [:s, :d].include?(flag_details[:type]) && flag_details[:count] == 2
30
+ svg << USPSFlags::Core::Tridents.two(flag_details[:type], trident_color: trident_color, field_color: flag_details[:color])
31
+ elsif [:s, :d, :stf, :n].include?(flag_details[:type]) && %w[LT DLT].include?(rank)
32
+ svg << USPSFlags::Core::Tridents.offset(flag_details[:type], field_color: flag_details[:color], field: field)
33
+ elsif [:a, :f, :fc, :pc].include?(flag_details[:type])
34
+ svg << special(flag_details[:type], level: flag_details[:level], field: field)
35
+ else
36
+ svg << USPSFlags::Core.trident(flag_details[:type], field_color: flag_details[:color])
37
+ end
38
+
39
+ svg << "</g></g>" if flag_details[:style] == :past
40
+ svg << USPSFlags::Core.footer
41
+
42
+ USPSFlags::Helpers.output(svg, outfile: outfile)
43
+ end
44
+
45
+ def special(type, level:, field: true)
46
+ # Paths were designed for a base fly of 3000 pixels, but the base was changed for more useful fractions.
47
+ svg = ""
48
+ svg << "<g transform=\"translate(#{USPSFlags::Config::BASE_FLY/10})\">" unless field
49
+ svg << "<g transform=\"scale(#{Rational(USPSFlags::Config::BASE_FLY,3000).to_f})\">"
50
+ svg << case type
51
+ when :a
52
+ USPSFlags::Core.binoculars(level)
53
+ when :f
54
+ USPSFlags::Core.trumpet(level)
55
+ when :fc
56
+ USPSFlags::Core.anchor
57
+ when :pc
58
+ USPSFlags::Core.lighthouse
59
+ end
60
+ svg << "</g>"
61
+ svg << "</g>" unless field
62
+
63
+ svg
64
+ end
65
+
66
+ def pennant(type: "CRUISE", outfile: nil, scale: nil)
67
+ type = type.upcase
68
+ svg = ""
69
+ title = case type
70
+ when "CRUISE"
71
+ "Cruise Pennant"
72
+ when "OIC"
73
+ "Officer-in-Charge Pennant"
74
+ end
75
+ svg << USPSFlags::Core.headers(pennant: true, scale: scale, title: title)
76
+ svg << USPSFlags::Core.pennant(type)
77
+ svg << USPSFlags::Core.footer
78
+
79
+ USPSFlags::Helpers.output(svg, outfile: outfile)
80
+ end
81
+
82
+ def ensign(outfile: nil, scale: nil)
83
+ svg = ""
84
+ svg << USPSFlags::Core.headers(scale: scale, title: "USPS Ensign")
85
+ svg << USPSFlags::Core.ensign
86
+ svg << USPSFlags::Core.footer
87
+
88
+ USPSFlags::Helpers.output(svg, outfile: outfile)
89
+ end
90
+
91
+ def wheel(outfile: nil, scale: nil)
92
+ width = 4327.4667
93
+ height = 4286.9333
94
+ svg = ""
95
+ svg << USPSFlags::Core.headers(width: width, height: height, scale: scale, title: "USPS Ensign Wheel")
96
+ svg << USPSFlags::Core.wheel
97
+ svg << USPSFlags::Core.footer
98
+
99
+ USPSFlags::Helpers.output(svg, outfile: outfile)
100
+ end
101
+
102
+ def us(outfile: nil, scale: nil)
103
+ base_hoist = 2000.to_f
104
+ base_fly = base_hoist * 1.91
105
+ hoist = scale.nil? ? base_hoist : (base_hoist / scale)
106
+ fly = hoist * 1.91
107
+ svg = ""
108
+ svg << USPSFlags::Core.headers(width: fly, height: hoist, scale: scale, title: "US Ensign")
109
+ svg << USPSFlags::Core.us
110
+ svg << USPSFlags::Core.footer
111
+
112
+ USPSFlags::Helpers.output(svg, outfile: outfile)
113
+ end
114
+ end
115
+ end