
DEFAULT_PARAMETER = "BATCH GENERATE".freeze D_COLORS = [ {code: "B", name: "Blue", rgb: [ 0, 0, 255]}, {code: "Bl", name: "Black", rgb: [ 0, 0, 0]}, {code: "Br", name: "Brown", rgb: [165, 42, 42]}, {code: "C", name: "Cyan", rgb: [ 0, 100, 100]}, {code: "G", name: "Green", rgb: [ 0, 255, 0]}, {code: "Gr", name: "Gray", rgb: [128, 128, 128]}, {code: "L", name: "Lime", rgb: [191, 255, 0]}, {code: "Lb", name: "Light Blue", rgb: [173, 216, 230]}, {code: "Ly", name: "Light Yellow", rgb: [255, 255, 224]}, {code: "O", name: "Orange", rgb: [255, 165, 0]}, {code: "P", name: "Purple", rgb: [128, 0, 128]}, {code: "Pi", name: "Pink", rgb: [255, 192, 203]}, {code: "R", name: "Red", rgb: [255, 0, 0]}, {code: "S", name: "Silver", rgb: [192, 192, 192]}, {code: "W", name: "White", rgb: [255, 255, 255]}, {code: "Y", name: "Yellow", rgb: [255, 255, 0]} ].freeze # We keep a reference to faces_count at module level instead of a global variable @faces_count = nil class << self attr_accessor :faces_count end #-------------------------------------------------------------------------------- # Utility methods #-------------------------------------------------------------------------------- def self.format_large_number(number) number = number.to_f units = ['', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion'] return number.to_i.to_s if number < 1_000 if number < 1_000_000_000_000_000 exponent = (Math.log(number) / Math.log(1_000)).floor unit = units[exponent] mantissa = (number / (1_000**exponent)).round(2) "#{mantissa} #{unit}" else exponent = Math.log10(number).floor mantissa = (number / (10**exponent)).round(2) "#{mantissa}e#{exponent}" end end def self.valid_colors?(colors_string, color_list) extracted_colors = colors_string.scan(/[A-Za-z]{2}|[A-Z]/) extracted_colors.all? { |color| color_list.include?(color) } end def self.midpoint(vert1, vert2) Geom::Point3d.linear_combination(0.5, vert1, 0.5, vert2) end def self.format_predicted_time(seconds) time_units = { "year(s)" => 31_536_000, # ~365 days "month(s)" => 2_592_000, # ~30 days "day(s)" => 86_400, "hour(s)" => 3_600, "minute(s)" => 60, "second(s)" => 1 } remaining_seconds = seconds.to_i formatted_time = [] time_units.each do |unit, value| next if remaining_seconds < value count, remaining_seconds = remaining_seconds.divmod(value) formatted_time << "#{count} #{unit}" end formatted_time = ["0 second(s)"] if formatted_time.empty? formatted_time.join(", ") end def self.clean_model(model) # Clear all scenes model.pages.each { |page| model.pages.erase(page)} # Clear all entities model.entities.clear! end

