# Core SVG data for the trident specification sheet.
#
# This class should never need to be called directly.
# @private
class USPSFlags::Core::TridentSpec
def initialize(fly: 24, unit: "in")
@trident_config = USPSFlags::Config.trident
hoist = (fly*Rational(2,3))
@hoist = hoist == hoist.to_i ? hoist.to_i : hoist
@fly_fraction = ""
@hoist_fraction = ""
if fly == fly.to_i
@fly = fly.to_i
else
@fly, @fly_fraction = fly.to_simplified_a
end
if hoist == hoist.to_i
@hoist = hoist.to_i
else
@hoist, @hoist_fraction = hoist.to_simplified_a
end
@label_font_size = if Math.sqrt(@fly) > 24
USPSFlags::Config::BASE_FLY * Math.log(24, Math.sqrt(@fly)) / 60
else
USPSFlags::Config::BASE_FLY / 60
end
@unit_text = unit.nil? ? "" : "#{unit}"
@unit = unit
barb_label = Rational(@trident_config[:main_point_barb]) * @fly / USPSFlags::Config::BASE_FLY
barb_label = barb_label == barb_label.to_i ? barb_label.to_i : barb_label.to_simplified_s
@barb_label = "#{barb_label}#{@unit_text}"
end
def svg
svg = ""
svg << <<~SVG
#{USPSFlags::Core.field}
United States Power Squadrons®
Officer Flag Trident Specification
All measurements are relative to a field with
fly of #{@fly} #{@fly_fraction} #{@unit_text} and hoist of #{@hoist} #{@hoist_fraction} #{@unit_text}.
Measurements not specified are the same as on the short trident.
SVG
box_width = USPSFlags::Config::BASE_FLY*5/32
box_left = (USPSFlags::Config::BASE_FLY*27/32)/2
box_right = (USPSFlags::Config::BASE_FLY*37/32)/2
box_top = USPSFlags::Config::BASE_HOIST/4
box_bottom = USPSFlags::Config::BASE_HOIST*3/4
svg << <<~SVG
Short
Squadron Officers
#{USPSFlags::Core::Trident.new(:s).svg}
#{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)}
#{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)}
#{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)}
#{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)}
#{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)}
#{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)}
#{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")}
#{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")}
#{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)}
#{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)}
#{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)}
#{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)}
#{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)}
#{@barb_label}
SVG
box_top = USPSFlags::Config::BASE_HOIST*3/16
box_bottom = USPSFlags::Config::BASE_HOIST*13/16
svg << <<~SVG
Delta
District Officers
#{USPSFlags::Core::Trident.new(:d).svg}
#{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)}
#{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)}
#{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)}
#{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")}
SVG
box_top = USPSFlags::Config::BASE_HOIST/8
box_bottom = USPSFlags::Config::BASE_HOIST*7/8
svg << <<~SVG
Circle
Staff Commanders Only
#{USPSFlags::Core::Trident.new(:stf).svg}
#{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)}
#{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)}
#{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)}
#{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")}
SVG
svg << <<~SVG
Long
National Officers
#{USPSFlags::Core::Trident.new(:n).svg}
#{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)}
#{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")}
SVG
svg
end
end