usps_flags 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 834c5fd9b07cda04e1abbb43ce057be5bcb75a2338c4c9c9b30bf90e873c70a3
4
- data.tar.gz: 2c1967a3acab412d00a70d2b7b529494128daf71c99c9484f8fd5dc51edade5d
3
+ metadata.gz: 66522ba47851bcb474d636cc17c8dcb62e25d32564893abfb93e9c3408b9b421
4
+ data.tar.gz: d9129013df7517b33e534bb6405ee20a2008e19b3236c04169e45278f46f8fdc
5
5
  SHA512:
6
- metadata.gz: 79d043fc636b58a3bc1181716b9a21fb2fe64b552b6e376035b096ea97682aa2d36bb24896ae711b86baef52779c457dadabf17b364cc23500cb1edb1d802145
7
- data.tar.gz: 3eef4c97b191637097e01444658635882cb1b4552c2705543b6c0c77e4c5923a211430d1026f9a202d6f637a101128df6224ef5f90e0be070d4b0efa64554ab4
6
+ metadata.gz: 4092e043b877705349f24a2fd0ee3733bb2e7b0e75ddbed6f7bf1f1bb3aa1ac6a147c9ff3f69baf779332f7db1e5fb96f8f2480079231d21df181de605856e62
7
+ data.tar.gz: 4654f83943621648bde190a5bce5e889729ad138fb445017ba20c401bc0f6b2d5790b5b232a3906784f1bfa4fec854334db3351c3a04b680db19f145cf1f226c
@@ -0,0 +1 @@
1
+ 2.5.1
data/CC.png ADDED
Binary file
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.6.0)
4
+ usps_flags (0.6.1)
5
5
  file_utils (~> 1.1, >= 1.1.2)
6
6
  mini_magick (~> 4.9, >= 4.9.4)
7
7
  rubyzip (~> 1.3, >= 1.3.0)
@@ -14,13 +14,13 @@ GEM
14
14
  docile (1.1.5)
15
15
  file_utils (1.1.2)
16
16
  jaro_winkler (1.5.4)
17
- json (2.1.0)
17
+ json (2.3.1)
18
18
  mini_magick (4.10.1)
19
19
  parallel (1.19.1)
20
20
  parser (2.6.5.0)
21
21
  ast (~> 2.4.0)
22
22
  rainbow (3.0.0)
23
- rake (12.3.0)
23
+ rake (12.3.3)
24
24
  rspec (3.7.0)
25
25
  rspec-core (~> 3.7.0)
26
26
  rspec-expectations (~> 3.7.0)
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # United States Power Squadrons® Flag Generator
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/usps_flags.svg)](https://rubygems.org/gems/usps_flags)
4
- [![Build Status](https://travis-ci.org/jfiander/usps-flags.svg)](https://travis-ci.org/jfiander/usps-flags)
4
+ [![Build Status](https://img.shields.io/travis/jfiander/usps-flags/master.svg)](https://travis-ci.org/jfiander/usps-flags)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/760b824f0edac3316a11/test_coverage)](https://codeclimate.com/github/jfiander/usps-flags/test_coverage)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/760b824f0edac3316a11/maintainability)](https://codeclimate.com/github/jfiander/usps-flags/maintainability)
7
7
 
@@ -10,6 +10,10 @@ class USPSFlags
10
10
  USPSFlags::Core::TridentSpecs::Build.new(fly: fly, unit: unit, scaled_border: scaled_border).svg
11
11
  end
12
12
 
13
+ def self.intersection_spec(fly: 24, unit: 'in', scaled_border: false)
14
+ USPSFlags::Core::TridentSpecs::Build.new(fly: fly, unit: unit, scaled_border: scaled_border).intersections
15
+ end
16
+
13
17
  def self.headers(width: nil, height: nil, pennant: false, scale: nil, title: 'USPS Flag')
14
18
  USPSFlags::Core::Headers.new(width: width, height: height, pennant: pennant, scale: scale, title: title).svg
15
19
  end
@@ -0,0 +1,125 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
3
+ <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="1024" height="682" viewBox="-3.072 -4.096 3084.288 2058.24" preserveAspectRatio="xMidYMid meet">
4
+ <title>CC</title>
5
+ <metadata>
6
+ <desc id="created-by">Julian Fiander</desc>
7
+ <desc id="generated-at">20200216.1756-0500</desc>
8
+ <desc id="trademark-desc">This image is a registered trademark of United States Power Squadrons.</desc>
9
+ <desc id="trademark-link">https://www.usps.org/images/secretary/itcom/trademark.pdf</desc>
10
+ </metadata><path d="M 0 0
11
+ l 3072 0
12
+ l 0 2048
13
+ l -3072 0
14
+ l 0 -2048 z
15
+ " fill="#012169" />
16
+ <g transform="translate(-354, 236)">
17
+ <g transform="rotate(-45, 1536, 1024)">
18
+ <path d="M 1536 256
19
+ l 80 184
20
+ l -40 -24
21
+ l 0 1376
22
+ l -80 0
23
+ l 0 -1376
24
+ l -40 24
25
+ l 80 -184
26
+ " fill="#FFFFFF" />
27
+ <path d="M 1296 784
28
+ l 480 0
29
+ l 0 80
30
+ l -480 0
31
+ l 0 -80
32
+ " fill="#FFFFFF" />
33
+ <path d="M 1296 785
34
+ l 0 -464
35
+ l 120 168
36
+ l -40 0
37
+ l 0 296
38
+ " fill="#FFFFFF" />
39
+ <path d="M 1776 785
40
+ l 0 -464
41
+ l -120 168
42
+ l 40 0
43
+ l 0 296
44
+ " fill="#FFFFFF" />
45
+ <path d="M 1400 944
46
+ l 273 0
47
+ l 0 80
48
+ l -273 0
49
+ l 0 -80
50
+ " fill="#FFFFFF" />
51
+ </g>
52
+ </g>
53
+
54
+ <path d="M 1536 256
55
+ l 80 184
56
+ l -40 -24
57
+ l 0 1376
58
+ l -80 0
59
+ l 0 -1376
60
+ l -40 24
61
+ l 80 -184
62
+ " fill="#FFFFFF" />
63
+ <path d="M 1296 784
64
+ l 480 0
65
+ l 0 80
66
+ l -480 0
67
+ l 0 -80
68
+ " fill="#FFFFFF" />
69
+ <path d="M 1296 785
70
+ l 0 -464
71
+ l 120 168
72
+ l -40 0
73
+ l 0 296
74
+ " fill="#FFFFFF" />
75
+ <path d="M 1776 785
76
+ l 0 -464
77
+ l -120 168
78
+ l 40 0
79
+ l 0 296
80
+ " fill="#FFFFFF" />
81
+ <path d="M 1400 944
82
+ l 273 0
83
+ l 0 80
84
+ l -273 0
85
+ l 0 -80
86
+ " fill="#FFFFFF" />
87
+
88
+ <g transform="translate(354, 236)">
89
+ <g transform="rotate(45, 1536, 1024)">
90
+ <path d="M 1536 256
91
+ l 80 184
92
+ l -40 -24
93
+ l 0 1376
94
+ l -80 0
95
+ l 0 -1376
96
+ l -40 24
97
+ l 80 -184
98
+ " fill="#FFFFFF" />
99
+ <path d="M 1296 784
100
+ l 480 0
101
+ l 0 80
102
+ l -480 0
103
+ l 0 -80
104
+ " fill="#FFFFFF" />
105
+ <path d="M 1296 785
106
+ l 0 -464
107
+ l 120 168
108
+ l -40 0
109
+ l 0 296
110
+ " fill="#FFFFFF" />
111
+ <path d="M 1776 785
112
+ l 0 -464
113
+ l -120 168
114
+ l 40 0
115
+ l 0 296
116
+ " fill="#FFFFFF" />
117
+ <path d="M 1400 944
118
+ l 273 0
119
+ l 0 80
120
+ l -273 0
121
+ l 0 -80
122
+ " fill="#FFFFFF" />
123
+ </g>
124
+ </g>
125
+ </svg>
@@ -24,6 +24,17 @@ class USPSFlags
24
24
  svg
25
25
  end
26
26
 
27
+ def intersections
28
+ # Static labeling
29
+ @fly = Rational(2048, 5)
30
+ @unit = ''
31
+
32
+ svg = spec_header(no_measurements: true)
33
+ svg << add_intersections
34
+
35
+ svg
36
+ end
37
+
27
38
  private
28
39
 
29
40
  def box_left
@@ -53,6 +64,71 @@ class USPSFlags
53
64
  add_trident(:Long, box_top, box_bottom, box_left, box_right)
54
65
  end
55
66
 
67
+ def add_intersections
68
+ svg = +''
69
+
70
+ svg += "<g transform=\"translate(-#{BF * 1 / 16}, #{BH / 4}) scale(0.6)\">"
71
+ svg += USPSFlags::Core::Tridents.cc(trident_color: :blue)
72
+ svg += cc_label
73
+ svg += '</g>'
74
+
75
+ svg += "<g transform=\"translate(#{BF * 7 / 16}, #{BH / 4}) scale(0.6)\">"
76
+ svg += USPSFlags::Core::Tridents.vc(trident_color: :red)
77
+ svg += vc_label
78
+ svg += '</g>'
79
+
80
+ svg
81
+ end
82
+
83
+ def cc_label
84
+ offset = BF.to_f * 1 / 32
85
+ height = BF.to_f * 15 / 64
86
+
87
+ small_arrow = SA.vertical(
88
+ offset, -height / 3, 0,
89
+ pointer_top: height / 3, pointer_bottom: 0, label_offset: BF / 35,
90
+ label_offset_y: -BF / 50, label_align: 'middle', fly: @fly, unit: @unit
91
+ )
92
+
93
+ <<~SVG
94
+ <!-- CC Intersection -->
95
+ <g transform="translate(#{BF / 2}, #{BH - 200}) rotate(45)">
96
+ #{big_arrow}
97
+ #{small_arrow}
98
+ </g>
99
+ SVG
100
+ end
101
+
102
+ def vc_label
103
+ offset = BF.to_f * 1 / 32
104
+ height = BF.to_f * 15 / 64
105
+
106
+ small_arrow = SA.vertical(
107
+ offset, -height * 15 / 32, 0,
108
+ pointer_top: height * 15 / 32, pointer_bottom: 0, label_offset: BF / 35,
109
+ label_offset_y: -BF / 50, label_align: 'middle', fly: @fly, unit: @unit
110
+ )
111
+
112
+ <<~SVG
113
+ <!-- CC Intersection -->
114
+ <g transform="translate(#{BF / 2}, #{BH - 200}) rotate(45)">
115
+ #{big_arrow}
116
+ #{small_arrow}
117
+ </g>
118
+ SVG
119
+ end
120
+
121
+ def big_arrow
122
+ offset = BF * 1 / 32
123
+ height = BF * 15 / 64
124
+
125
+ SA.vertical(
126
+ offset * 3, -height, 0,
127
+ pointer_top: height, pointer_bottom: 0, label_offset: BF / 60,
128
+ label_offset_y: -BF / 10, label_align: 'left', fly: @fly, unit: @unit
129
+ )
130
+ end
131
+
56
132
  def configure_sizes(fly)
57
133
  @fly = Rational(fly)
58
134
  get_hoist_from_fly(@fly)
@@ -109,10 +185,10 @@ class USPSFlags
109
185
  end
110
186
  end
111
187
 
112
- def spec_header
188
+ def spec_header(no_measurements: false)
113
189
  USPSFlags::Core::TridentSpecs::Header.new(
114
190
  fly: @fly, fly_fraction: @fly_fraction, hoist: @hoist, hoist_fraction: @hoist_fraction,
115
- unit_text: @unit_text, scaled_border: @scaled_border
191
+ unit_text: @unit_text, scaled_border: @scaled_border, no_measurements: no_measurements
116
192
  ).p
117
193
  end
118
194
 
@@ -15,6 +15,7 @@ class USPSFlags
15
15
  @hoist_fraction = options[:hoist_fraction]
16
16
  @unit_text = options[:unit_text]
17
17
  @scaled_border = options[:scaled_border]
18
+ @no_measurements = options.key?(:no_measurements) && options[:no_measurements]
18
19
  end
19
20
 
20
21
  def p
@@ -43,11 +44,21 @@ class USPSFlags
43
44
  <text x="#{BF / 2}" y="#{BH * 3 / 40}" font-family="sans-serif" font-size="#{BH / 20}px" font-weight="bold" fill="#041E42" text-anchor="middle">United States Power Squadrons<tspan class="heading" dy ="-#{BH / 50}">®</tspan></text>
44
45
  </g>
45
46
  <text x="#{BF / 2}" y="#{BH / 8}" font-family="sans-serif" font-size="#{BH / 30}px" fill="#041E42" text-anchor="middle">Officer Flag Trident Specification</text>
47
+ #{measurements_are_relative}
48
+ SVG
49
+ end
50
+
51
+ def measurements_are_relative
52
+ return if @no_measurements
53
+
54
+ <<~SVG
46
55
  <text x="#{BF / 2}" y="#{BH * 2 / 11}" font-family="sans-serif" font-size="#{BH / 40}px" fill="#041E42" text-anchor="middle">All measurements are relative to a field with</text>
47
56
  SVG
48
57
  end
49
58
 
50
59
  def units
60
+ return angles if @no_measurements
61
+
51
62
  <<~SVG
52
63
  <g>
53
64
  <style><![CDATA[tspan.title{font-size: #{USPSFlags::Config::FRACTION_SCALE * 9 / 10}%;}]]></style>
@@ -58,6 +69,12 @@ class USPSFlags
58
69
  SVG
59
70
  end
60
71
 
72
+ def angles
73
+ <<~SVG
74
+ <text x="#{BF / 2}" y="#{BH * 4 / 19}" font-family="sans-serif" font-size="#{BH / 40}px" fill="#041E42" text-anchor="middle">Angled tridents are 45 degrees from vertical.</text>
75
+ SVG
76
+ end
77
+
61
78
  def scaled_border
62
79
  <<~SVG
63
80
  <!-- Flag border scaled to spec trident size -->
@@ -10,38 +10,32 @@ class USPSFlags
10
10
  class << self
11
11
  # The side C/C tridents are angled 45 degrees, and intersect the central one at 1/3 up from the bottom
12
12
  #
13
- # Note: translate(132, 130) corrects the center of rotation for each angled trident due to the (transparent)
14
- # field size of the include trident SVG
15
- #
16
13
  # Center of rotation:
17
14
  # # radius = USPSFlags.configuration.trident[:bar_width] / 2
18
15
  # <circle cx="#{cc_center[:x]}" cy="#{cc_center[:y]}" r="#{radius}" fill="red" />
19
- def cc(type, trident_color:)
20
- trident = USPSFlags::Core.trident(type, color: trident_color)
16
+ def cc(_ = nil, trident_color:)
17
+ trident = USPSFlags::Core.trident(:n, color: trident_color)
18
+ x_distance = USPSFlags::Config::BASE_FLY * 4 / 39 # 4/39 or 28/39
19
+ y_distance = USPSFlags::Config::BASE_FLY * 2 / 39 # 5/78 or 27/156
21
20
  <<~SVG
22
- <g transform="translate(132, 130)">
23
- <g transform="rotate(-45, #{cc_center[:x]}, #{cc_center[:y]})">
24
- #{trident}
25
- </g>
26
- <g transform="rotate(45, #{cc_center[:x]}, #{cc_center[:y]})">
27
- #{trident}
28
- </g>
21
+ <g transform="translate(-#{x_distance * 1.25}, #{y_distance})">
22
+ <g transform="rotate(-45, #{USPSFlags::Config::BASE_FLY / 2}, #{USPSFlags::Config::BASE_HOIST / 2})">\n#{trident}</g>
23
+ </g>
24
+ \n#{trident}
25
+ <g transform="translate(#{x_distance * 1.25}, #{y_distance})">
26
+ <g transform="rotate(45)" transform-origin="center">\n#{trident}</g>
29
27
  </g>
30
- #{trident}
31
28
  SVG
32
29
  end
33
30
 
34
31
  # V/C tridents are angled 45 degrees, and intersect at 15/32 up from the bottom
35
- #
36
- # Note: translate(132, 50) corrects the center of rotation for each angled trident due to the (transparent)
37
- # field size of the include trident SVG
38
- def vc(type, trident_color:)
39
- trident = USPSFlags::Core.trident(type, color: trident_color)
32
+ def vc(_ = nil, trident_color:)
33
+ trident = USPSFlags::Core.trident(:n, color: trident_color)
40
34
  <<~SVG
41
- <g transform="translate(132, 50) rotate(-45, #{vc_center[:x]}, #{vc_center[:y]})">
35
+ <g transform="rotate(-45, #{vc_center[:x]}, #{vc_center[:y]})">
42
36
  #{trident}
43
37
  </g>
44
- <g transform="translate(132, 50) rotate(45, #{vc_center[:x]}, #{vc_center[:y]})">
38
+ <g transform="rotate(45, #{vc_center[:x]}, #{vc_center[:y]})">
45
39
  #{trident}
46
40
  </g>
47
41
  SVG
@@ -84,14 +78,10 @@ class USPSFlags
84
78
  def rotation_center(height_fraction)
85
79
  {
86
80
  x: USPSFlags::Config::BASE_FLY / 2,
87
- y: (USPSFlags::Config::BASE_HOIST * 7 / 8) - (n_staff_height * height_fraction)
81
+ y: (USPSFlags::Config::BASE_HOIST * 7 / 8) - (n_staff_height * height_fraction).to_f
88
82
  }
89
83
  end
90
84
 
91
- def cc_center
92
- rotation_center(Rational(1, 3))
93
- end
94
-
95
85
  def vc_center
96
86
  rotation_center(Rational(15, 32))
97
87
  end
@@ -103,6 +103,22 @@ class USPSFlags
103
103
  USPSFlags::Helpers.output(svg, outfile: outfile)
104
104
  end
105
105
 
106
+ # Generate trident spec sheet for National Bridge intersections as an SVG image.
107
+ #
108
+ # @param [String] outfile The path to save the SVG file to. If not set, prints to console.
109
+ # @param [Integer] fly The nominal fly length of an appropriate flag field for the generated tridents.
110
+ # @param [String] outfile The unit to append to all trident measurements.
111
+ # @param [String] scale The image scale divisor factor.
112
+ # @return [String] Returns the SVG data.
113
+ def intersection_spec(outfile: nil, fly: USPSFlags::Config::BASE_FLY, unit: nil, scale: nil, scaled_border: false)
114
+ svg = +''
115
+ svg << USPSFlags::Core.headers(scale: scale, title: 'USPS Trident Specifications')
116
+ svg << USPSFlags::Core.intersection_spec(fly: fly, unit: unit, scaled_border: scaled_border)
117
+ svg << USPSFlags::Core.footer
118
+
119
+ USPSFlags::Helpers.output(svg, outfile: outfile)
120
+ end
121
+
106
122
  private
107
123
 
108
124
  def special_flag(flag, outfile, scale)
@@ -88,6 +88,10 @@ describe USPSFlags::Generate do
88
88
  it 'generates the trident specification sheet with a fractional field size' do
89
89
  expect(described_class.spec(outfile: '', fly: 23.5)).to include('<title>USPS Trident Specifications</title>')
90
90
  end
91
+
92
+ it 'generates the intersection specification sheet' do
93
+ expect(described_class.intersection_spec(outfile: '')).to include('CC Intersection')
94
+ end
91
95
  end
92
96
 
93
97
  describe 'png' do
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'usps_flags'
5
- s.version = '0.6.0'
6
- s.date = '2020-02-17'
5
+ s.version = '0.6.1'
6
+ s.date = '2020-08-03'
7
7
  s.summary = 'Flag generator for United States Power Squadrons'
8
8
  s.description = 'A flag image (PNG, SVG) generator for United States Power Squadrons.'
9
9
  s.homepage = 'http://rubygems.org/gems/usps_flags'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-17 00:00:00.000000000 Z
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: file_utils
@@ -179,8 +179,10 @@ files:
179
179
  - ".gitignore"
180
180
  - ".rspec"
181
181
  - ".rubocop.yml"
182
+ - ".ruby-version"
182
183
  - ".travis.yml"
183
184
  - ".yardopts"
185
+ - CC.png
184
186
  - CONTRIBUTING.md
185
187
  - Gemfile
186
188
  - Gemfile.lock
@@ -192,6 +194,7 @@ files:
192
194
  - lib/usps_flags/config.rb
193
195
  - lib/usps_flags/configuration.rb
194
196
  - lib/usps_flags/core.rb
197
+ - lib/usps_flags/core/CC.svg
195
198
  - lib/usps_flags/core/ensign.rb
196
199
  - lib/usps_flags/core/field.rb
197
200
  - lib/usps_flags/core/footer.rb