<commit_before>#include "FileTypeHandler.h"

#include <Graph.h>
#include <glm/glm.hpp>
#include <sstream>

using namespace std;

FileTypeHandler::FileTypeHandler(const string & _description, bool _can_write) : description(_description), can_write(_can_write) {

}

#if 0
glm::dvec2
FileTypeHandler:compute2DPolygonCentroid(const Point2D* vertices, int vertexCount) {
  glm::dvec2 centroid;
  double signedArea = 0.0;
  double x0 = 0.0; // Current vertex X
  double y0 = 0.0; // Current vertex Y
  double x1 = 0.0; // Next vertex X
  double y1 = 0.0; // Next vertex Y
  double a = 0.0;  // Partial signed area
  
  // For all vertices except last
  int i = 0;
  for (i = 0; i < vertexCount - 1; ++i) {
    x0 = vertices[i].x;
    y0 = vertices[i].y;
    x1 = vertices[i+1].x;
    y1 = vertices[i+1].y;
    a = x0*y1 - x1*y0;
    signedArea += a;
    centroid.x += (x0 + x1)*a;
    centroid.y += (y0 + y1)*a;
  }
  
  // Do last vertex
  x0 = vertices[i].x;
  y0 = vertices[i].y;
  x1 = vertices[0].x;
  y1 = vertices[0].y;
  a = x0*y1 - x1*y0;
  signedArea += a;
  centroid.x += (x0 + x1)*a;
  centroid.y += (y0 + y1)*a;
  
  signedArea *= 0.5;
  centroid.x /= (6.0*signedArea);
  centroid.y /= (6.0*signedArea);
  
  return centroid;
}
#endif

int
FileTypeHandler::createNode(Graph & graph, map<string, int> & nodes, double x, double y, double z, float nx, float ny, float nz) {
  ostringstream key;
  key << x << "/" << y << '/' << z;
  map<string, int>::iterator it = nodes.find(key.str());
  if (it != nodes.end()) {
    return it->second;
  } else {
    int node_id = nodes[key.str()] = graph.addNode();
    graph.setPosition(node_id, glm::vec3(x, y, z));
    graph.setNormal(node_id, glm::vec4(nx, ny, nz, 1.0f));
    return node_id;  
  }
}

pair<int, int>
FileTypeHandler::createNodesForArc(const ArcData & arc, Graph & graph, map<string, int> & nodes, bool rev) {
  assert(arc.data.size() >= 2);
  const glm::dvec3 & v1 = arc.data.front(), v2 = arc.data.back();
  ostringstream key1, key2;
  key1 << <KEY>;
  key2 << <KEY>;
  int node1, node2;
  map<string, int>::iterator it = nodes.find(key1.str());
  if (it != nodes.end()) {
    node1 = it->second;
  } else {
    nodes[key1.str()] = node1 = graph.addNode();
    graph.setPosition(node1, glm::vec3(v1.x, v1.y, v1.z));
  }
  it = nodes.find(key2.str());
  if (it != nodes.end()) {
    node2 = it->second;
  } else {
    nodes[key2.str()] = node2 = graph.addNode();
    graph.setPosition(node2, glm::vec3(v2.x, v2.y, v2.z));<commit_msg>rename ArcData to ArcData2D, and drop z component<commit_after>#include "FileTypeHandler.h"

#include <Graph.h>
#include <glm/glm.hpp>
#include <sstream>

using namespace std;

FileTypeHandler::FileTypeHandler(const string & _description, bool _can_write) : description(_description), can_write(_can_write) {

}

#if 0
glm::dvec2
FileTypeHandler:compute2DPolygonCentroid(const Point2D* vertices, int vertexCount) {
  glm::dvec2 centroid;
  double signedArea = 0.0;
  double x0 = 0.0; // Current vertex X
  double y0 = 0.0; // Current vertex Y
  double x1 = 0.0; // Next vertex X
  double y1 = 0.0; // Next vertex Y
  double a = 0.0;  // Partial signed area
  
  // For all vertices except last
  int i = 0;
  for (i = 0; i < vertexCount - 1; ++i) {
    x0 = vertices[i].x;
    y0 = vertices[i].y;
    x1 = vertices[i+1].x;
    y1 = vertices[i+1].y;
    a = x0*y1 - x1*y0;
    signedArea += a;
    centroid.x += (x0 + x1)*a;
    centroid.y += (y0 + y1)*a;
  }
  
  // Do last vertex
  x0 = vertices[i].x;
  y0 = vertices[i].y;
  x1 = vertices[0].x;
  y1 = vertices[0].y;
  a = x0*y1 - x1*y0;
  signedArea += a;
  centroid.x += (x0 + x1)*a;
  centroid.y += (y0 + y1)*a;
  
  signedArea *= 0.5;
  centroid.x /= (6.0*signedArea);
  centroid.y /= (6.0*signedArea);
  
  return centroid;
}
#endif

int
FileTypeHandler::createNode(Graph & graph, map<string, int> & nodes, double x, double y, double z, float nx, float ny, float nz) {
  ostringstream key;
  key << <KEY>
  map<string, int>::iterator it = nodes.find(key.str());
  if (it != nodes.end()) {
    return it->second;
  } else {
    int node_id = nodes[key.str()] = graph.addNode();
    graph.setPosition(node_id, glm::vec3(x, y, z));
    graph.setNormal(node_id, glm::vec4(nx, ny, nz, 1.0f));
    return node_id;  
  }
}

pair<int, int>
FileTypeHandler::createNodesForArc(const ArcData2D & arc, Graph & graph, map<string, int> & nodes, bool rev) {
  assert(arc.data.size() >= 2);
  auto & v1 = arc.data.front();
  auto & v2 = arc.data.back();
  ostringstream key1, key2;
  key1 << <KEY>;
  key2 << <KEY>;
  int node1, node2;
  map<string, int>::iterator it = nodes.find(key1.str());
  if (it != nodes.end()) {
    node1 = it->second;
  } else {
    nodes[key1.str()] = node1 = graph.addNode();
    graph.setPosition(node1, glm::vec3(v1.x, v1.y, 0.0f));
  }
  it = nodes.find(key2.str());
  if (it != nodes.end()) {
    node2 = it->second;
  } else {
    nodes[key2.str()] = node2 = graph.addNode();
    graph.setPosition(node2, glm::vec3(v2.x, v2.y, 0.0f));
{'fraction_non_alphanumeric': 0.18038353975229723, 'fraction_numerical': 0.036556132640831004, 'mean_word_length': 3.175979983319433, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 32, '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': '6165642', 'n_tokens_mistral': 2070, 'n_tokens_neox': 2036, 'n_words': 478}