<commit_before>// See LICENSE file for copyright and license details.

#include <cassert>
#include <stdexcept>
#include "visualizer/vertexArray.hpp"

VertexArray::VertexArray(PrimitiveType primitiveType)
  : mVertices(),
    mTextureCoordinates(),
    mColors(),
    mTextureID(0),
    mPrimitiveType(primitiveType),
    mColor(1.0f, 1.0f, 1.0f),
    mHaveColor(false)
{
}

VertexArray::VertexArray(const Color& color, PrimitiveType primitiveType)
  : mVertices(),
    mTextureCoordinates(),
    mColors(),
    mTextureID(0),
    mPrimitiveType(primitiveType),
    mColor(color),
    mHaveColor(true)
{
}

void VertexArray::setTextureID(GLuint textureID) {
  mTextureID = textureID;
}

void VertexArray::addVertex(
    const V3f& meshCoordinate,
    const V2f& textureCoordinate,
    const Color3u& color)
{
  addCoord(meshCoordinate);
  addTextureCoord(textureCoordinate);
  addColor(color);
}

void VertexArray::addVertex(
    const V3f& meshCoordinate, const V2f& textureCoordinate)
{
  addCoord(meshCoordinate);
  addTextureCoord(textureCoordinate);
}

void VertexArray::addVertex(const V3f& meshCoordinate, const Color3u& color) {
  addCoord(meshCoordinate);
  addColor(color);
}

void VertexArray::addVertex(const V3f& meshCoordinate) {
  addCoord(meshCoordinate);
}

void VertexArray::addColor(const Color3u &color) {
  mColors.push_back(color.red());
  mColors.push_back(color.green());
  mColors.push_back(color.blue());
}

void VertexArray::addTextureCoord(const V2f& vertex) {
  mTextureCoordinates.push_back(vertex.x());
  mTextureCoordinates.push_back(vertex.y());
}

void VertexArray::addCoord(const V3f& vertex) {
  mVertices.push_back(vertex.x());
  mVertices.push_back(vertex.y());
  mVertices.push_back(vertex.z());
}

void VertexArray::draw() {
  // enable everything
  {
    if (!mTextureCoordinates.empty()) {
      glEnable(GL_TEXTURE_2D);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
      glBindTexture(GL_TEXTURE_2D, mTextureID);
      glTexCoordPointer(2, GL_FLOAT, 0, mTextureCoordinates.data());
    }
    if (!mVertices.empty()) {
      glEnableClientState(GL_VERTEX_ARRAY);
    }
    if (!mColors.empty()) {
      glEnableClientState(GL_COLOR_ARRAY);
      glColorPointer(3, GL_UNSIGNED_BYTE, 0, mColors.data());
    }
    if (mHaveColor) {
      glColor3f(mColor.red(), mColor.green(), mColor.blue());
    } else {
      glColor3f(1.0f, 1.0f, 1.0f);
    }
  }
  // draw
  {
    glVertexPointer(3, GL_FLOAT, 0, mVertices.data());
    switch (mPrimitiveType) {
    case PrimitiveType::Triangles:
      glDrawArrays(GL_TRIANGLES, 0, mVertices.size() / 3);
      break;
    case PrimitiveType::Lines:
      glDrawArrays(GL_LINES, 0, mVertices.size() / 3);
      break;
    default:
      throw std::logic_error("default case");
    }
  }
  // disable everything
  {
    if (!mTextureCoordinates.empty()) {
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);
      glDisable(GL_TEXTURE_2D);
    }
    if (!mVertices.empty()) {
      glDisableClientState(GL_VERTEX_ARRAY);
    }
    if (!mColors.empty()) {
      glDisableClientState(GL_COLOR_ARRAY);
    }
  }
}

void appendV3f(std::vector<float>* vertices, const V3f& vertex) {
  assert(vertices);
  vertices->push_back(vertex.x());
  vertices->push_back(vertex.y());
  vertices->push_back(vertex.z());
}<commit_msg>VertexArray: Removed appendV3f(..) implementation<commit_after>// See LICENSE file for copyright and license details.

#include <cassert>
#include <stdexcept>
#include "visualizer/vertexArray.hpp"

VertexArray::VertexArray(PrimitiveType primitiveType)
  : mVertices(),
    mTextureCoordinates(),
    mColors(),
    mTextureID(0),
    mPrimitiveType(primitiveType),
    mColor(1.0f, 1.0f, 1.0f),
    mHaveColor(false)
{
}

VertexArray::VertexArray(const Color& color, PrimitiveType primitiveType)
  : mVertices(),
    mTextureCoordinates(),
    mColors(),
    mTextureID(0),
    mPrimitiveType(primitiveType),
    mColor(color),
    mHaveColor(true)
{
}

void VertexArray::setTextureID(GLuint textureID) {
  mTextureID = textureID;
}

void VertexArray::addVertex(
    const V3f& meshCoordinate,
    const V2f& textureCoordinate,
    const Color3u& color)
{
  addCoord(meshCoordinate);
  addTextureCoord(textureCoordinate);
  addColor(color);
}

void VertexArray::addVertex(
    const V3f& meshCoordinate, const V2f& textureCoordinate)
{
  addCoord(meshCoordinate);
  addTextureCoord(textureCoordinate);
}

void VertexArray::addVertex(const V3f& meshCoordinate, const Color3u& color) {
  addCoord(meshCoordinate);
  addColor(color);
}

void VertexArray::addVertex(const V3f& meshCoordinate) {
  addCoord(meshCoordinate);
}

void VertexArray::addColor(const Color3u &color) {
  mColors.push_back(color.red());
  mColors.push_back(color.green());
  mColors.push_back(color.blue());
}

void VertexArray::addTextureCoord(const V2f& vertex) {
  mTextureCoordinates.push_back(vertex.x());
  mTextureCoordinates.push_back(vertex.y());
}

void VertexArray::addCoord(const V3f& vertex) {
  mVertices.push_back(vertex.x());
  mVertices.push_back(vertex.y());
  mVertices.push_back(vertex.z());
}

void VertexArray::draw() {
  // enable everything
  {
    if (!mTextureCoordinates.empty()) {
      glEnable(GL_TEXTURE_2D);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
      glBindTexture(GL_TEXTURE_2D, mTextureID);
      glTexCoordPointer(2, GL_FLOAT, 0, mTextureCoordinates.data());
    }
    if (!mVertices.empty()) {
      glEnableClientState(GL_VERTEX_ARRAY);
    }
    if (!mColors.empty()) {
      glEnableClientState(GL_COLOR_ARRAY);
      glColorPointer(3, GL_UNSIGNED_BYTE, 0, mColors.data());
    }
    if (mHaveColor) {
      glColor3f(mColor.red(), mColor.green(), mColor.blue());
    } else {
      glColor3f(1.0f, 1.0f, 1.0f);
    }
  }
  // draw
  {
    glVertexPointer(3, GL_FLOAT, 0, mVertices.data());
    switch (mPrimitiveType) {
    case PrimitiveType::Triangles:
      glDrawArrays(GL_TRIANGLES, 0, mVertices.size() / 3);
      break;
    case PrimitiveType::Lines:
      glDrawArrays(GL_LINES, 0, mVertices.size() / 3);
      break;
    default:
      throw std::logic_error("default case");
    }
  }
  // disable everything
  {
    if (!mTextureCoordinates.empty()) {
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);
      glDisable(GL_TEXTURE_2D);
    }
    if (!mVertices.empty()) {
      glDisableClientState(GL_VERTEX_ARRAY);
    }
    if (!mColors.empty()) {
      glDisableClientState(GL_COLOR_ARRAY);
    }
  }
}
{'fraction_non_alphanumeric': 0.13400621118012424, 'fraction_numerical': 0.012888198757763975, 'mean_word_length': 4.249388753056235, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, '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': '4596023', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2282, 'n_words': 355}