<commit_before>const rectangleFactory = require('./rectangle');
const svgConstants = require('./svg_constants');

const RECT_WIDTH = 10;
const RECT_HEIGHT = 10;

/**
 * Convert between DOM coords and SVG viewbox coords
 * @param {Number} width
 * @param {Number} height
 * @param {Number} x
 * @param {Number} y
 * @returns {{ x: Number, y: Number }}
 */
function toViewBoxCoords(width, height, x, y) {
  return {
    x: svgConstants.DIMENSIONS_X * x / width,
    y: svgConstants.DIMENSIONS_Y * y / height,
  };
}

/**
 * Given two rectangles, returns true if they're overlapping, false otherwise
 * @param {{ x: Number, y: Number, width: Number, height: Number }} boxA
 * @param {{ x: Number, y: Number, width: Number, height: Number }} boxB
 * @returns {Boolean}
 */
function isColliding(rectA, rectB) {
  if (rectA.x > rectB.x + rectB.width || rectA.x + rectA.width < rectB.x) {
    return false;
  }
  if (rectA.y > rectB.y + rectB.height || rectA.y + rectA.height < rectB.y) {
    return false;
  }

  return true;
}

/**
 * Get the dimensions from the given SVG <rect/>
 * @param {Node} rect
 * @returns {{ x: Number, y: Number, width: Number, height: Number }}
 */
function getRectDimensions(rect) {
  return {
    x: parseInt(rect.getAttribute('x')),
    y: parseInt(rect.getAttribute('y')),
    width: parseInt(rect.getAttribute('width')),
    height: parseInt(rect.getAttribute('height')),
  };
}<commit_msg>Use floats for non-embarrassingly bad accuracy<commit_after>const rectangleFactory = require('./rectangle');
const svgConstants = require('./svg_constants');

const RECT_WIDTH = 10;
const RECT_HEIGHT = 10;

/**
 * Convert between DOM coords and SVG viewbox coords
 * @param {Number} width
 * @param {Number} height
 * @param {Number} x
 * @param {Number} y
 * @returns {{ x: Number, y: Number }}
 */
function toViewBoxCoords(width, height, x, y) {
  return {
    x: svgConstants.DIMENSIONS_X * x / width,
    y: svgConstants.DIMENSIONS_Y * y / height,
  };
}

/**
 * Given two rectangles, returns true if they're overlapping, false otherwise
 * @param {{ x: Number, y: Number, width: Number, height: Number }} boxA
 * @param {{ x: Number, y: Number, width: Number, height: Number }} boxB
 * @returns {Boolean}
 */
function isColliding(rectA, rectB) {
  if (rectA.x > rectB.x + rectB.width || rectA.x + rectA.width < rectB.x) {
    return false;
  }
  if (rectA.y > rectB.y + rectB.height || rectA.y + rectA.height < rectB.y) {
    return false;
  }

  return true;
}

/**
 * Get the dimensions from the given SVG <rect/>
 * @param {Node} rect
 * @returns {{ x: Number, y: Number, width: Number, height: Number }}
 */
function getRectDimensions(rect) {
  return {
    x: parseFloat(rect.getAttribute('x')),
    y: parseFloat(rect.getAttribute('y')),
    width: parseFloat(rect.getAttribute('width')),
    height: parseFloat(rect.getAttribute('height')),
  };
}
{'fraction_non_alphanumeric': 0.15467500868960724, 'fraction_numerical': 0.002780674313521029, 'mean_word_length': 3.788685524126456, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6454116', 'n_tokens_mistral': 984, 'n_tokens_neox': 977, 'n_words': 279}