<commit_before># calculations are (mostly) from OpenSCAD MCAD library

require_relative 'rcad'


class BaseBoltPart < Shape
  attr_accessor :bolt_dia

  def initialize(bolt_dia)
    @bolt_dia = bolt_dia
  end

  def nut_height
    0.8 * bolt_dia
  end

  def nut_dia_across_flats
    1.8 * bolt_dia
  end

  def nut_dia_across_corners
    nut_dia_across_flats / Math::cos(30.deg_to_rad)
  end
end


class HexNut < BaseBoltPart
  attr_accessor :xytol, :ztol, :full

  def initialize(bolt_dia, xytol=0, ztol=0, full=false)
    super(bolt_dia)

    @xytol = xytol
    @ztol = ztol
    @full = full
  end

  def render
    d = nut_dia_across_corners + @xytol
    h = nut_height + @ztol

    nut = reg_prism(6, d / 2.0, h)
    
    if full
      return nut
    else
      return nut.sub(
        cylinder(h + 0.02, bolt_dia + @xytol).move_z(-0.01))
    end
  end
end


class Bolt < BaseBoltPart
  attr_accessor :bolt_len, :xytol, :ztol
  
  def initialize(bolt_dia, bolt_len, xytol=0, ztol=0)
    super(bolt_dia)

    @bolt_len = bolt_len
    @xytol = xytol
    @ztol = ztol
  end
<commit_msg>Convert another bit of nuts.rb I missed earlier.<commit_after># calculations are (mostly) from OpenSCAD MCAD library

require_relative 'rcad'


class BaseBoltPart < Shape
  attr_accessor :bolt_dia

  def initialize(bolt_dia)
    @bolt_dia = bolt_dia
  end

  def nut_height
    0.8 * bolt_dia
  end

  def nut_dia_across_flats
    1.8 * bolt_dia
  end

  def nut_dia_across_corners
    nut_dia_across_flats / Math::cos(30.deg_to_rad)
  end
end


class HexNut < BaseBoltPart
  attr_accessor :xytol, :ztol, :full

  def initialize(bolt_dia, xytol=0, ztol=0, full=false)
    super(bolt_dia)

    @xytol = xytol
    @ztol = ztol
    @full = full
  end

  def render
    d = nut_dia_across_corners + @xytol
    h = nut_height + @ztol

    nut = reg_prism(6, d / 2.0, h)
    
    if full
      return nut
    else
      return sub do
          ~nut
          ~cylinder(h + 0.02, bolt_dia + @xytol)
            .move_z(-0.01)
        end
    end
  end
end


class Bolt < BaseBoltPart
  attr_accessor :bolt_len, :xytol, :ztol
  
  def initialize(bolt_dia, bolt_len, xytol=0, ztol=0)
    super(bolt_dia)

    @bolt_len = bolt_len
    @xytol = xytol
    @ztol = ztol
  end

{'fraction_non_alphanumeric': 0.08485117725455353, 'fraction_numerical': 0.016881386050644157, 'mean_word_length': 2.6617886178861787, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1801076', 'n_tokens_mistral': 988, 'n_tokens_neox': 908, 'n_words': 217}