# Core SVG data for the trident insignia. # # This class should never need to be called directly. # @private class USPSFlags::Core::Trident def initialize(type, color: :blue, field_color: nil) valid_types = [:s, :d, :stf, :n] raise "Error: Invalid trident type. Options are #{valid_types}." unless valid_types.include? type @type = type @trident_config = USPSFlags::Config.trident main_spike_overhang = @trident_config[:bar_width] / 2 side_spike_overhang = @trident_config[:bar_width] / 2 @top_point = ((USPSFlags::Config::BASE_HOIST - @trident_config[:height][@type]) / 2) crossbar_top = @top_point + @trident_config[:crossbar_from_top] @hash_from_top = @trident_config[:crossbar_from_top] + (@trident_config[:bar_width] * 2) @circle_from_top = @trident_config[:crossbar_from_top] + @trident_config[:bar_width]*123/128 + @trident_config[:width]/2 main_length = @trident_config[:height][@type] - (@trident_config[:point_height] - @trident_config[:main_point_barb]) @trident_segments = [ { # Main spike [@trident_config[:center_point], @top_point] => [ [@trident_config[:bar_width], @trident_config[:point_height]], [-main_spike_overhang, -@trident_config[:main_point_barb]], [0, main_length], [-(@trident_config[:bar_width]), 0], [0, -main_length], [-main_spike_overhang, @trident_config[:main_point_barb]], [@trident_config[:bar_width], -@trident_config[:point_height]] ] }, { # Crossbar [(@trident_config[:center_point] - @trident_config[:width]/2), (crossbar_top)] => [ [@trident_config[:width], 0], [0, @trident_config[:bar_width]], [-@trident_config[:width], 0], [0, -@trident_config[:bar_width]] ] }, { # Left spike [(@trident_config[:center_point] - @trident_config[:width]/2), (crossbar_top + 1)] => [ [0, -(@trident_config[:side_spike_height]+@trident_config[:point_height])], [(@trident_config[:bar_width]+side_spike_overhang), @trident_config[:point_height]], [-side_spike_overhang, 0], [0, @trident_config[:side_spike_height]] ] }, { # Right spike [(@trident_config[:center_point] + @trident_config[:width]/2), (crossbar_top + 1)] => [ [0, -(@trident_config[:side_spike_height]+@trident_config[:point_height])], [-(@trident_config[:bar_width]+side_spike_overhang), @trident_config[:point_height]], [side_spike_overhang, 0], [0, @trident_config[:side_spike_height]] ] } ] @lower_hash = [ [@trident_config[:hash_width], 0], [0, @trident_config[:bar_width]], [-@trident_config[:hash_width], 0], [0, -@trident_config[:bar_width]] ] case color when :white @color_code = "#FFFFFF" @field_color_code = case field_color when :red USPSFlags::Config::RED when :blue USPSFlags::Config::BLUE end when :red @color_code = USPSFlags::Config::RED @field_color_code = "#FFFFFF" when :blue @color_code = USPSFlags::Config::BLUE @field_color_code = "#FFFFFF" end end def svg svg = case @type when :d "" when :stf "" else "" end @trident_segments.each do |segment| start = segment.keys.first points = segment.values.first svg << "\n" end svg << "" if [:d, :stf].include?(@type) if @type == :d # Delta hash svg << <<~SVG SVG elsif @type == :stf # Circle hash svg << <<~SVG SVG else # Standard hash svg << "\n" # # V/C crossing, marks @ 15/32 up # vc_cross_marker = USPSFlags::Config::BASE_HOIST*7/8-(USPSFlags::Config::BASE_HOIST/8+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*3)*15/32 # svg << "" # # C/C crossing, marks @ 1/3 up # cc_cross_marker = USPSFlags::Config::BASE_HOIST*7/8-(USPSFlags::Config::BASE_HOIST/8+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*3)*1/3 # svg << "" end svg end end