Skip to content

Round and truncate to 6 decimals in Vector2D

When creating vectors, some floating point rounding errors may arise.

Example: !928

with input:

Wago_734-53x:
  # This connector needs another pad row at 3.65mm Y distance, with the same numbering
  # This series need centering at top pin 1
  library: 'Wago'
  pad_pitch: 3.5
  row_pitch: null # only one row
  first_pin:
    position: 'top'     # top (default) or bottom
    offset: 
    marker:
      shape: 'line' 
      offset: 0.2
      fab: True
      size: 1.1547 # 1mm side arrow
    pad:
      shape: 'rect'
      drill: 1.6
      size: [2.5, 2.5]
  clean_silk: True
  description: 'Socket terminal block, {pad_pitch}mm Pitch, Single Row, {options}'
  tags: 'conn  wire'
  pads:
    drill: 1.6
    size: [2.5, 2.5]
  source: 'https://www.wago.com/global/pluggable-connectors/tht-male-header/p/734-533'
  options: 'horizontal (right angle)'
  fp_suffix: '_Horizontal'
  offset:
    body: [0, 5.75]
  body_size:
    x_offset: 0
    y: 14.7
  body_shape:
    right:
      polyline: [[pr+3.3, -1.6], [pr+3.3, -1.6+8.2], [pr+3.3-1.5, -1.6+8.2], [pr+3.3-1.5, -1.6+14.7]]
    left:
      polyline: [[pl-1.7, -1.6], [pl-1.7, -1.6+14.7]]
  fp_name: 'Wago_734-53{num_pos:01d}'
  positions: [2]
  rule_areas:
    pluggable_connector: # key is unique for each rule area
      name: 'Pluggable connector' # visible name of the rule area
      layers: 'F.Cu'  # layers of the rule area
      shapes:
        - 'rect': [
                   [pl-3.55, pb+9.9+0.1],
                   [pr+3.8, pb+9.9+23.3]
                  ]
      keepouts:
        footprints: deny

Rounding vectors to 6 decimals helps to reduce those errors. In the above example: Before this MR:

[Vector2D (x=-1.75, y=-1.5999999999999996), Vector2D (x=1.75, y=-1.5999999999999996), Vector2D (x=5.05, y=-1.6), Vector2D (x=5.05, y=6.6), Vector2D (x=3.55, y=6.6), Vector2D (x=3.55, y=13.1), Vector2D (x=1.75, y=13.1), Vector2D (x=-1.75, y=13.1), Vector2D (x=-3.45, y=13.1), Vector2D (x=-3.45, y=-1.6), Vector2D (x=-1.75, y=-1.5999999999999996)]```

With this MR:

[Vector2D (x=-1.75, y=-1.6), Vector2D (x=1.75, y=-1.6), Vector2D (x=5.05, y=-1.6), Vector2D (x=5.05, y=6.6), Vector2D (x=3.55, y=6.6), Vector2D (x=3.55, y=13.1), Vector2D (x=1.75, y=13.1), Vector2D (x=-1.75, y=13.1), Vector2D (x=-3.45, y=13.1), Vector2D (x=-3.45, y=-1.6), Vector2D (x=-1.75, y=-1.6)]
Edited by Carlos Nieves Ónega

Merge request reports