<commit_before>calculator = require './common/calculator'
copper = require './common/copper'
courtyard = require './common/courtyard'
silkscreen = require './common/silkscreen'

module.exports = (pattern, element) ->
  housing = element.housing
  settings = pattern.settings
  pattern.name ?= element.name.toUpperCase()

  pad =
    x: 0
    y: 0
    drill: housing.drillDiameter
    shape: 'circle'

  if housing.padDiameter? or housing.padWidth? or housing.padHeight?
    housing.padWidth ?= housing.padDiameter
    housing.padHeight ?= housing.padDiameter
    pad.type = 'through-hole'
    pad.layer = ['topCopper', 'topMask', 'topPaste', 'bottomCopper', 'bottomMask', 'bottomPaste']
    pad.width = housing.padDiameter ? housing.padWidth
    pad.height = housing.padDiameter ? housing.padHeight
  else
    pad.type = 'mounting-hole'
    pad.layer = ['topCopper', 'topMask', 'bottomCopper', 'bottomMask']
    pad.width = housing.drillDiameter
    pad.height = housing.drillDiameter
    pad.shape = 'circle'

  pattern.pad 1, pad

  copper.mask pattern

  if housing.viaDiameter?
    viaPad =
      type: 'through-hole'
      shape: 'circle'
      drill: housing.viaDiameter
      width: housing.viaDiameter + settings.minimum.ringWidth
      height: housing.viaDiameter + settings.minimum.ringWidth
      layer: ['topCopper', 'bottomCopper']
    count = housing.viaCount ? 8
    r = housing.drillDiameter/2 + ((housing.padDiameter ? housing.padWidth) - housing.drillDiameter)/4
    for i in [0..(count-1)]
      angle = i*2*Math.PI/count
      viaPad.x = r*Math.cos(angle)
      viaPad.y = r*Math.sin(angle)
      pattern.pad 1, viaPad

  courtyard
    .preamble pattern, housing
    .circle 0, 0, pad.width/2 + { M: 0.5, N: 0.25, L: 0.12 }[settings.densityLevel]<commit_msg>Improve pattern generation of mounting hole<commit_after>calculator = require './common/calculator'
copper = require './common/copper'
courtyard = require './common/courtyard'
silkscreen = require './common/silkscreen'

module.exports = (pattern, element) ->
  housing = element.housing
  settings = pattern.settings
  pattern.name ?= element.name.toUpperCase()

  pad =
    x: 0
    y: 0
    drill: housing.drillDiameter
    shape: 'circle'

  if housing.padDiameter? or housing.padWidth? or housing.padHeight?
    housing.padWidth ?= housing.padDiameter
    housing.padHeight ?= housing.padDiameter
    pad.type = 'through-hole'
    pad.layer = ['topCopper', 'topMask', 'topPaste', 'bottomCopper', 'bottomMask', 'bottomPaste']
    pad.width = housing.padDiameter ? housing.padWidth
    pad.height = housing.padDiameter ? housing.padHeight
  else
    pad.type = 'mounting-hole'
    pad.layer = ['topCopper', 'topMask', 'bottomCopper', 'bottomMask']
    pad.width = housing.drillDiameter
    pad.height = housing.drillDiameter
    pad.shape = 'circle'

  pattern.pad 1, pad

  copper.mask pattern

  if housing.viaDiameter?
    viaPad =
      type: 'through-hole'
      shape: 'circle'
      drill: housing.viaDiameter
      width: housing.viaDiameter + settings.minimum.ringWidth
      height: housing.viaDiameter + settings.minimum.ringWidth
      layer: ['topCopper', 'bottomCopper']
    count = housing.viaCount ? 8
    r = housing.drillDiameter/2 + ((housing.padDiameter ? housing.padWidth) - housing.drillDiameter)/4
    for i in [0..(count-1)]
      angle = i*2*Math.PI/count
      viaPad.x = r*Math.cos(angle)
      viaPad.y = r*Math.sin(angle)
      pattern.pad 1, viaPad

  housing.keepout ?= { M: 0.5, N: 0.25, L: 0.12 }[settings.densityLevel]

  courtyard
    .preamble pattern, housing
    .circle 0, 0, pad.width/2 + housing.keepout

  # Assembly layer
  pattern
    .layer 'topAssembly'
    .lineWidth settings.lineWidth.assembly
    .attribute 'refDes',
      x: 0
      y: 0
      halign: 'center'
      valign: 'center'
    .attribute 'value',
      text: pattern.name
      x: 0
      y: 0
      halign: 'center'
      valign: 'center'
      visible: false
{'fraction_non_alphanumeric': 0.12598026815077157, 'fraction_numerical': 0.011636731596256009, 'mean_word_length': 3.093167701863354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6189101', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1314, 'n_words': 293}