<commit_before>import { SpriteWidth, SpriteHeight, SpriteRatioX, SpriteRatioY } from "../Constants.js";
import { Wall } from "../SpriteConstants";

class Room extends Phaser.Group {

  constructor(game, parent, name) {
    super(game, parent, name, false, false, Phaser.Physics.ARCADE);
  }

  createLineByTile(x1, y1, nbTilesX, nbTilesY) {
    this.createLine(x1, y1, nbTilesX * SpriteWidth + x1 , nbTilesY * SpriteHeight + y1);
  }

  createLine(x1, y1, x2, y2) {
    const xBegin = Math.min(x1, x2);
    const xEnd = Math.max(x1, x2);
    const yBegin = Math.min(y1, y2);
    const yEnd = Math.max(y1, y2);

    const xStep = (x2-x1);
    const yStep = (y2-y1);

    if (xStep === 0) {
      //x1 === x2
      return this.createVerticalLine(x1, yBegin, yEnd);
    }

    if (yStep === 0) {
      //y1 === y2
      return this.createHorizontalLine(xBegin, xEnd, y1);
    }

    let x = xBegin;
    let y = yBegin;
    while(x != xEnd || y != yEnd) {
      if(x < xEnd) {
        x += SpriteWidth;
      }
      if(y < yEnd) {
        y += SpriteHeight;
      }
      this.createSprite(x,y);
    }

  }

  createVerticalLine(x, y1, y2) {
    for(let y = y1; y < y2; y += SpriteHeight) {
      this.createSprite(x, y);
    }
  }

  createHorizontalLine(x1, x2, y) {
    for(let x = x1; x < x2; x += SpriteWidth) {
      this.createSprite(x, y);
    }
  }

  createSprite(x,y) {
    let sprite = this.create(x, y, Wall);
    sprite.scale.setTo(SpriteRatioX, SpriteRatioY);
  }

  ////
  //       ####
  //       #  #
  //       #  #
  //       #  #
  // (x,y) ####
  //
  ///
  createSquare(x, y, nbTilesBySide) {
    this.createLineByTile(x, y, nbTilesBySide, 0);
    this.createLineByTile(x, y + (nbTilesBySide - 1) * SpriteHeight, nbTilesBySide, 0);

    this.createLineByTile(x, y + SpriteHeight, 0, nbTilesBySide - 2);
    this.createLineByTile(x + (nbTilesBySide - 1) * SpriteWidth, y + SpriteHeight, 0, nbTilesBySide - 2);
  }
}

export default Room;<commit_msg>use an algo to improve tracing<commit_after>import { SpriteWidth, SpriteHeight, SpriteRatioX, SpriteRatioY } from "../Constants.js";
import { Wall } from "../SpriteConstants";

class Room extends Phaser.Group {

  constructor(game, parent, name) {
    super(game, parent, name, false, false, Phaser.Physics.ARCADE);
  }

  createRandomLine(x1, y1, x2, y2, division = 2) {

  }

  createLineByTile(x1, y1, nbTilesX, nbTilesY) {
    if(nbTilesX < 0 ) {
      throw `createLineByTile ${nbTilesX} is negative`;
    }
    if(nbTilesY < 0 ) {
      throw `createLineByTile ${nbTilesY} is negative`;
    }
    this.createLine(x1, y1, (nbTilesX-1) * SpriteWidth + x1 , (nbTilesY-1) * SpriteHeight + y1);
  }

  // //Brasenhem algorithm
  createLine(x1,y1, x2, y2) {
    const dx = Math.abs(x2 - x1);
    const sx = x1 < x2 ? SpriteWidth : -SpriteWidth;
    const dy = Math.abs(y2 - y1);
    const sy = y1 < y2 ? SpriteHeight : -SpriteHeight;
    var err = (dx > dy ? dx : -dy) / 2;

    let x = x1;
    let y = y1;

    while (true) {
      this.createSprite(x,y);
      debugger
      if (x >= x2 && y >= y2) break;
      let e2 = err;
      if (e2 > - dx) {
        err -= dy;
        x += sx;
      }
      if (e2 < dy) {
        err += dx;
        y += sy;
      }
    }
  }

  createSprite(x,y) {
    let sprite = this.create(x, y, Wall);
    sprite.scale.setTo(SpriteRatioX, SpriteRatioY);
  }

  ////
  //       ####
  //       #  #
  //       #  #
  //       #  #
  // (x,y) ####
  //
  ///
  createSquare(x, y, nbTilesBySide) {
    this.createLineByTile(x, y, nbTilesBySide, 0);
    this.createLineByTile(x, y + (nbTilesBySide - 1) * SpriteHeight, nbTilesBySide, 0);

    this.createLineByTile(x, y + SpriteHeight, 0, nbTilesBySide - 2);
    this.createLineByTile(x + (nbTilesBySide - 1) * SpriteWidth, y + SpriteHeight, 0, nbTilesBySide - 2);
  }
}

export default Room;
{'fraction_non_alphanumeric': 0.15833333333333333, 'fraction_numerical': 0.023177083333333334, 'mean_word_length': 2.3112068965517243, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 7, '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': '3056590', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1548, 'n_words': 330}