<commit_before>import { onResize } from '../app/window_resize'
import { system } from '../preinit/system_capabilities'
import { BUILDING_SPACE } from '../segments/buildings'
import { getSegmentVariantInfo } from '../segments/info'
import { getSegmentWidthResolution } from '../segments/resizing'
import { TILE_SIZE } from '../segments/view'
import store from '../store'
import { updateOccupiedWidth, updateSegments } from '../store/actions/street'

export const DEFAULT_STREET_WIDTH = 80

const MIN_CUSTOM_STREET_WIDTH = 10
export const MAX_CUSTOM_STREET_WIDTH = 400

const WIDTH_ROUNDING = 0.01

export const SEGMENT_WARNING_OUTSIDE = 1
export const SEGMENT_WARNING_WIDTH_TOO_SMALL = 2
export const SEGMENT_WARNING_WIDTH_TOO_LARGE = 3

export function resizeStreetWidth (dontScroll) {
  var width = store.getState().street.width * TILE_SIZE

  document.querySelector('#street-section-canvas').style.width = width + 'px'
  if (!dontScroll) {
    document.querySelector('#street-section-outer').scrollLeft =
      (width + (BUILDING_SPACE * 2) - system.viewportWidth) / 2
  }

  onResize()
}

export function normalizeStreetWidth (width) {
  if (width < MIN_CUSTOM_STREET_WIDTH) {
    width = MIN_CUSTOM_STREET_WIDTH
  } else if (width > MAX_CUSTOM_STREET_WIDTH) {
    width = MAX_CUSTOM_STREET_WIDTH
  }

  var resolution = getSegmentWidthResolution()
  width = Math.round(width / resolution) * resolution

  return width
}

export function recalculateOccupiedWidth () {
  const street = store.getState().street
  let occupiedWidth = 0

  for (var i in street.segments) {
    let segment = street.segments[i]

    occupiedWidth += segment.width
  }

  let remainingWidth = street.width - occupiedWidth
  // Rounding problems :·(
  if (Math.abs(remainingWidth) < WIDTH_ROUNDING) {
    remainingWidth = 0
  }
  store.dispatch(updateOccupiedWidth(occupiedWidth, remainingWidth))
  // updateStreetMetadata(street)
}

export function recalculateWidth () {
  recalculateOccupiedWidth()

  const street = store.getState().street
  var position = (street.width / 2) - (street.occupiedWidth / 2)

  const segments = []
  for (var i in street.segments) {
    var segment = street.segments[i]
    const variantInfo = getSegmentVariantInfo(segment.type, segment.variantString)

    if (segment.el) {
      if ((street.remainingWidth < 0) &&
        ((position < 0) || ((position + segment.width) > street.width))) {
        segment.warnings[SEGMENT_WARNING_OUTSIDE] = true
      } else {
        segment.warnings[SEGMENT_WARNING_OUTSIDE] = false
      }

      if (variantInfo.minWidth && (segment.width < variantInfo.minWidth)) {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_SMALL] = true
      } else {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_SMALL] = false
      }

      if (variantInfo.maxWidth && (segment.width > variantInfo.maxWidth)) {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_LARGE] = true
      } else {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_LARGE] = false
      }
    }

    segments.push(segment)
    position += street.segments[i].width
  }

  store.dispatch(updateSegments(segments))

  if (street.remainingWidth >= 0) {
    document.body.classList.remove('street-overflows')
  } else {
    document.body.classList.add('street-overflows')
  }
}<commit_msg>removed adding class "street-overflows" since building component now handles check<commit_after>import { onResize } from '../app/window_resize'
import { system } from '../preinit/system_capabilities'
import { BUILDING_SPACE } from '../segments/buildings'
import { getSegmentVariantInfo } from '../segments/info'
import { getSegmentWidthResolution } from '../segments/resizing'
import { TILE_SIZE } from '../segments/view'
import store from '../store'
import { updateOccupiedWidth, updateSegments } from '../store/actions/street'

export const DEFAULT_STREET_WIDTH = 80

const MIN_CUSTOM_STREET_WIDTH = 10
export const MAX_CUSTOM_STREET_WIDTH = 400

const WIDTH_ROUNDING = 0.01

export const SEGMENT_WARNING_OUTSIDE = 1
export const SEGMENT_WARNING_WIDTH_TOO_SMALL = 2
export const SEGMENT_WARNING_WIDTH_TOO_LARGE = 3

export function resizeStreetWidth (dontScroll) {
  var width = store.getState().street.width * TILE_SIZE

  document.querySelector('#street-section-canvas').style.width = width + 'px'
  if (!dontScroll) {
    document.querySelector('#street-section-outer').scrollLeft =
      (width + (BUILDING_SPACE * 2) - system.viewportWidth) / 2
  }

  onResize()
}

export function normalizeStreetWidth (width) {
  if (width < MIN_CUSTOM_STREET_WIDTH) {
    width = MIN_CUSTOM_STREET_WIDTH
  } else if (width > MAX_CUSTOM_STREET_WIDTH) {
    width = MAX_CUSTOM_STREET_WIDTH
  }

  var resolution = getSegmentWidthResolution()
  width = Math.round(width / resolution) * resolution

  return width
}

export function recalculateOccupiedWidth () {
  const street = store.getState().street
  let occupiedWidth = 0

  for (var i in street.segments) {
    let segment = street.segments[i]

    occupiedWidth += segment.width
  }

  let remainingWidth = street.width - occupiedWidth
  // Rounding problems :·(
  if (Math.abs(remainingWidth) < WIDTH_ROUNDING) {
    remainingWidth = 0
  }
  store.dispatch(updateOccupiedWidth(occupiedWidth, remainingWidth))
  // updateStreetMetadata(street)
}

export function recalculateWidth () {
  recalculateOccupiedWidth()

  const street = store.getState().street
  var position = (street.width / 2) - (street.occupiedWidth / 2)

  const segments = []
  for (var i in street.segments) {
    var segment = street.segments[i]
    const variantInfo = getSegmentVariantInfo(segment.type, segment.variantString)

    if (segment.el) {
      if ((street.remainingWidth < 0) &&
        ((position < 0) || ((position + segment.width) > street.width))) {
        segment.warnings[SEGMENT_WARNING_OUTSIDE] = true
      } else {
        segment.warnings[SEGMENT_WARNING_OUTSIDE] = false
      }

      if (variantInfo.minWidth && (segment.width < variantInfo.minWidth)) {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_SMALL] = true
      } else {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_SMALL] = false
      }

      if (variantInfo.maxWidth && (segment.width > variantInfo.maxWidth)) {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_LARGE] = true
      } else {
        segment.warnings[SEGMENT_WARNING_WIDTH_TOO_LARGE] = false
      }
    }

    segments.push(segment)
    position += street.segments[i].width
  }

  store.dispatch(updateSegments(segments))
}
{'fraction_non_alphanumeric': 0.107559926244622, 'fraction_numerical': 0.006607252612169637, 'mean_word_length': 3.8647234678624813, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, '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': '1532070', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2069, 'n_words': 417}