<commit_before>part of nodes;

Map coercion = {
  'mm': {
    'cm': 10,
    'in': 25.4
  },
  'cm': {
    'mm': 1 / 10,
    'in': 2.54
  },
  'in': {
    'mm': 1 / 25.4,
    'cm': 1 / 2.54
  },
  'ms': {
    's': 1000
  },
  's': {
    'ms': 1 / 1000
  },
  'rad': {
    'deg': PI / 180
  },
  'deg': {
    'rad': 180 / PI
  }
};

class Dimension extends Node {
  num value;
  String unit;

  Dimension(value, [unit]) {
    this.value = value is num ? value : double.parse(value);
    this.unit = unit != null ? unit : '';
  }

  operate(String op, Dimension other) {
    if ((op == '-' || op == '+') && other.unit == '%') {
      other.value = value * (value / 100);
    } else {
      other = coerce(other);
    }
    return new Dimension(calc(op, value, other.value),
                         unit != '' ? unit : other.unit );
  }

  coerce(other) {
    if (other is Dimension) {
      var multiplier = 1;
      if (coercion[unit] != null && coercion[unit][other.unit] != null) {
        multiplier = coercion[unit][other.unit];
      }
      return new Dimension(other.value * multiplier, unit != '' ? unit : other.unit);
    }
    return new Dimension(double.parse(other), this.unit);
  }

  calc(op, a, b) {
    switch (op) {
      case '+':
        return a + b;
      case '-':
        return a - b;
      case '*':
        return a * b;
      case '/':
        return a / b;
    }
  }

  css(env) {
    var n = this.value;<commit_msg>fix double vs int<commit_after>part of nodes;

Map coercion = {
  'mm': {
    'cm': 10,
    'in': 25.4
  },
  'cm': {
    'mm': 1 / 10,
    'in': 2.54
  },
  'in': {
    'mm': 1 / 25.4,
    'cm': 1 / 2.54
  },
  'ms': {
    's': 1000
  },
  's': {
    'ms': 1 / 1000
  },
  'rad': {
    'deg': PI / 180
  },
  'deg': {
    'rad': 180 / PI
  }
};

class Dimension extends Node {
  num value;
  String unit;

  Dimension(value, [unit]) {
    this.value = value is num ? value : double.parse(value);
    this.unit = unit != null ? unit : '';
  }
  
  parse(num n) {
    var i = n.toInt();
    if (i == n) {
      return i;
    } else {
      return n;
    }
  }

  operate(String op, Dimension other) {
    if ((op == '-' || op == '+') && other.unit == '%') {
      other.value = value * (value / 100);
    } else {
      other = coerce(other);
    }
    return new Dimension(calc(op, value, other.value),
                         unit != '' ? unit : other.unit );
  }

  coerce(other) {
    if (other is Dimension) {
      var multiplier = 1;
      if (coercion[unit] != null && coercion[unit][other.unit] != null) {
        multiplier = coercion[unit][other.unit];
      }
      return new Dimension(other.value * multiplier, unit != '' ? unit : other.unit);
    }
    return new Dimension(double.parse(other), this.unit);
  }

  calc(op, a, b) {
    switch (op) {
      case '+':
        return a + b;
      case '-':
        return a - b;
      case '*':
        return a * b;
      case '/':
        return a / b;
    }
  }

  css(env) {
    var n = parse(this.value);
{'fraction_non_alphanumeric': 0.18884832392963824, 'fraction_numerical': 0.02522402920677066, 'mean_word_length': 1.747493163172288, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5497660', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1102, 'n_words': 279}