<commit_before>import Three from 'three';
import {createSingleWindow} from './window-creator';
import {createDoor} from './door-creator';

export default function createShapeWall(vertex0, vertex1, height, thickness, holes,
                                        bevelRadius, isSelected, textureA, textureB) {

  if (vertex0.x > vertex1.x) {
    let app = vertex0;
    vertex0 = vertex1;
    vertex1 = app;
  }

  let distance = Math.sqrt(Math.pow(vertex0.x - vertex1.x, 2) + Math.pow(vertex0.y - vertex1.y, 2));

  //TODO: REMOVE WORKAROUND BEVELING
  distance += bevelRadius;

  let wallCoord = buildShapeCoordinates({x: 0, y: 0}, {x: distance, y: 0}, height); // TODO: Clean Code!!

  // let alpha = Math.asin((vertex1.y - vertex0.y) / distance);
  let alpha = Math.asin((vertex1.y - vertex0.y) / (distance - bevelRadius)); //TODO: REMOVE WORKAROUND BEVELING

  let pivot = new Three.Object3D();

  let rectShape = createShape(wallCoord);

  holes.forEach(hole => {
    let holeCoords = createHoleShape(vertex0,
      vertex1,
      hole.properties.get('width'),
      hole.properties.get('height'),
      hole.offset,
      hole.properties.get('altitude') + 0.00001,
      bevelRadius);
    let holeShape = createShape(holeCoords);
    rectShape.holes.push(holeShape);

    // Create Windows
    if (hole.properties.get('altitude') !== 0) {
      let window3D = createSingleWindow(
        hole.properties.get('width'),
        hole.properties.get('height'),
        thickness,
        (distance - bevelRadius) * hole.offset,
        hole.properties.get('altitude') + hole.properties.get('height') / 2,
        0, false, 100);
      pivot.add(window3D);
    } else {
      let door3D = createDoor(
        hole.properties.get('width') - 0.1,
        hole.properties.get('height') - 0.1,
        thickness,
        (distance - bevelRadius) * hole.offset,
        hole.properties.get('altitude') + hole.properties.get('height') / 2,
        0,
        100);
      pivot.add(door3D)
    }
  });


  let lineGeometry = new Three.ShapeGeometry(rectShape);
  lineGeometry.computeVertexNormals();


  let wallColor = new Three.Color(1, 1, 1);
  if (isSelected) {
    wallColor = new Three.Color(1, 0.76, 0);
  }

  let wallMaterial1 = new Three.MeshPhongMaterial({
    side: Three.DoubleSide,
    color: wallColor
  });

  let wallMaterial2 = new Three.MeshPhongMaterial({
    side: Three.DoubleSide,
    color: wallColor
  });


  if (alpha < 0) {
    applyTexture(wallMaterial1, textureA);
    applyTexture(wallMaterial2, textureB);
  } else {
    applyTexture(wallMaterial1, textureB);
    applyTexture(wallMaterial2, textureA);
  }

  let wall1 = new Three.Mesh(lineGeometry, wallMaterial1);
  let wall2 = new Three.Mesh(lineGeometry, wallMaterial2);
  
  wall1.position.z -= thickness / 2 + 0.001;
  wall2.position.z += thickness / 2 + 0.001;

  wall1.position.x -= bevelRadius / 2 + 0.001; //TODO: REMOVE WORKAROUND BEVELING
  wall2.position.x -= bevelRadius / 2 + 0.001; //TODO: REMOVE WORKAROUND BEVELING

  pivot.rotation.y = alpha;
  pivot.position.x += vertex0.x;
  pivot.position.z -= vertex0.y;

  // pivot.position.x -= thickness;

  pivot.add(wall1);
  pivot.add(wall2);

  // Build closures for wall

  // buildShapeCoordinates({x: 0, y: 0}, {x: distance, y: 0}, height);
  let closures = buildShapeClosures({x: 0, y: 0}, {x: distance, y: 0}, height, thickness);<commit_msg>change window/door detection on 3D view<commit_after>import Three from 'three';
import {createSingleWindow} from './window-creator';
import {createDoor} from './door-creator';

export default function createShapeWall(vertex0, vertex1, height, thickness, holes,
                                        bevelRadius, isSelected, textureA, textureB) {

  if (vertex0.x > vertex1.x) {
    let app = vertex0;
    vertex0 = vertex1;
    vertex1 = app;
  }

  let distance = Math.sqrt(Math.pow(vertex0.x - vertex1.x, 2) + Math.pow(vertex0.y - vertex1.y, 2));

  //TODO: REMOVE WORKAROUND BEVELING
  distance += bevelRadius;

  let wallCoord = buildShapeCoordinates({x: 0, y: 0}, {x: distance, y: 0}, height); // TODO: Clean Code!!

  // let alpha = Math.asin((vertex1.y - vertex0.y) / distance);
  let alpha = Math.asin((vertex1.y - vertex0.y) / (distance - bevelRadius)); //TODO: REMOVE WORKAROUND BEVELING

  let pivot = new Three.Object3D();

  let rectShape = createShape(wallCoord);

  holes.forEach(hole => {
    let holeCoords = createHoleShape(vertex0,
      vertex1,
      hole.properties.get('width'),
      hole.properties.get('height'),
      hole.offset,
      hole.properties.get('altitude') + 0.00001,
      bevelRadius);
    let holeShape = createShape(holeCoords);
    rectShape.holes.push(holeShape);

    // Create Windows
    if (hole.type === 'windowGeneric') {
      let window3D = createSingleWindow(
        hole.properties.get('width'),
        hole.properties.get('height'),
        thickness,
        (distance - bevelRadius) * hole.offset,
        hole.properties.get('altitude') + hole.properties.get('height') / 2,
        0, false, 100);
      pivot.add(window3D);
    } else {
      let door3D = createDoor(
        hole.properties.get('width') - 0.1,
        hole.properties.get('height') - 0.1,
        thickness,
        (distance - bevelRadius) * hole.offset,
        hole.properties.get('altitude') + hole.properties.get('height') / 2,
        0,
        100);
      pivot.add(door3D)
    }
  });


  let lineGeometry = new Three.ShapeGeometry(rectShape);
  lineGeometry.computeVertexNormals();


  let wallColor = new Three.Color(1, 1, 1);
  if (isSelected) {
    wallColor = new Three.Color(1, 0.76, 0);
  }

  let wallMaterial1 = new Three.MeshPhongMaterial({
    side: Three.DoubleSide,
    color: wallColor
  });

  let wallMaterial2 = new Three.MeshPhongMaterial({
    side: Three.DoubleSide,
    color: wallColor
  });


  if (alpha < 0) {
    applyTexture(wallMaterial1, textureA);
    applyTexture(wallMaterial2, textureB);
  } else {
    applyTexture(wallMaterial1, textureB);
    applyTexture(wallMaterial2, textureA);
  }

  let wall1 = new Three.Mesh(lineGeometry, wallMaterial1);
  let wall2 = new Three.Mesh(lineGeometry, wallMaterial2);

  wall1.position.z -= thickness / 2 + 0.001;
  wall2.position.z += thickness / 2 + 0.001;

  wall1.position.x -= bevelRadius / 2 + 0.001; //TODO: REMOVE WORKAROUND BEVELING
  wall2.position.x -= bevelRadius / 2 + 0.001; //TODO: REMOVE WORKAROUND BEVELING

  pivot.rotation.y = alpha;
  pivot.position.x += vertex0.x;
  pivot.position.z -= vertex0.y;

  // pivot.position.x -= thickness;

  pivot.add(wall1);
  pivot.add(wall2);

  // Build closures for wall

  // buildShapeCoordinates({x: 0, y: 0}, {x: distance, y: 0}, height);
  let closures = buildShapeClosures({x: 0, y: 0}, {x: distance, y: 0}, height, thickness);
{'fraction_non_alphanumeric': 0.14138438880706922, 'fraction_numerical': 0.03004418262150221, 'mean_word_length': 2.9574592074592077, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4138822', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2224, 'n_words': 510}