<commit_before>
class SceneView
  constructor: (@canvas) ->
    @id = _.uniqueId 'view'
    throw new Error "A Canvas is required" if not @canvas
    @context = @canvas.getContext("2d")
    throw new Error "Could not retrieve Canvas context" if not @context
    @context.webkitImageSmoothingEnabled = false
    @context.mozImageSmoothingEnabled = false

  # Convert a Rect/Point/Number from world coordinates (game units) to
  # screen coordinates (pixels)
  worldToScreen: (value,scale=1) ->
    if value instanceof Rect
      return new Rect(value).scale (Screen.UNIT * scale)
    else if value instanceof Point
      return new Point(value).multiply (Screen.UNIT * scale)
    value * (Screen.UNIT * scale)

  # Convert a Rect/Point/Number from screen coordinates (pixels) to
  # game world coordinates (game unit sizes)
  screenToWorld: (value,scale=1) ->
    if value instanceof Rect
      return new Rect(value).scale 1 / (Screen.UNIT * scale)
    else if value instanceof Point
      return new Point(value).multiply 1 / (Screen.UNIT * scale)
    value * (1 / (Screen.UNIT * scale))


  # Convert a mouse event on the canvas into coordinates that are relative
  # to it, rather than to the DOM.
  canvasMousePosition: (event) ->
    canoffset = $(event.currentTarget).offset();
    x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - Math.floor(canoffset.left);
    y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop - Math.floor(canoffset.top);
    new Point x, y

  # Render the scene
  render: (scene) ->

  debugRender: (scene) ->
    # MSPF Counter debug
    @context.save()
    @context.fillStyle = "rgba(255,255,255,0.7)";
    @context.font = "bold 16px Arial";
    @context.fillText("MSPF: #{@scene.mspf}",12,25);
    @context.fillText("FPS: #{@scene.fps.toFixed(0)}",12,40);
    @context.restore()<commit_msg>Make sure debugRender doesn't crash if a view has no context.<commit_after>
class SceneView
  constructor: (@canvas) ->
    @id = _.uniqueId 'view'
    throw new Error "A Canvas is required" if not @canvas
    @context = @canvas.getContext("2d")
    throw new Error "Could not retrieve Canvas context" if not @context
    @context.webkitImageSmoothingEnabled = false
    @context.mozImageSmoothingEnabled = false

  # Convert a Rect/Point/Number from world coordinates (game units) to
  # screen coordinates (pixels)
  worldToScreen: (value,scale=1) ->
    if value instanceof Rect
      return new Rect(value).scale (Screen.UNIT * scale)
    else if value instanceof Point
      return new Point(value).multiply (Screen.UNIT * scale)
    value * (Screen.UNIT * scale)

  # Convert a Rect/Point/Number from screen coordinates (pixels) to
  # game world coordinates (game unit sizes)
  screenToWorld: (value,scale=1) ->
    if value instanceof Rect
      return new Rect(value).scale 1 / (Screen.UNIT * scale)
    else if value instanceof Point
      return new Point(value).multiply 1 / (Screen.UNIT * scale)
    value * (1 / (Screen.UNIT * scale))


  # Convert a mouse event on the canvas into coordinates that are relative
  # to it, rather than to the DOM.
  canvasMousePosition: (event) ->
    canoffset = $(event.currentTarget).offset();
    x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - Math.floor(canoffset.left);
    y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop - Math.floor(canoffset.top);
    new Point x, y

  # Render the scene
  render: (scene) ->

  debugRender: (scene) ->
    return false if not @context
    # MSPF Counter debug
    @context.save()
    @context.fillStyle = "rgba(255,255,255,0.7)";
    @context.font = "bold 16px Arial";
    @context.fillText("MSPF: #{@scene.mspf}",12,25);
    @context.fillText("FPS: #{@scene.fps.toFixed(0)}",12,40);
    @context.restore()
{'fraction_non_alphanumeric': 0.11750972762645914, 'fraction_numerical': 0.014526588845654994, 'mean_word_length': 3.541813898704358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '211371', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1150, 'n_words': 356}