<commit_before>//
//  Mesh2.make.cpp
//  OpenGLEditor
//
//  Created by <NAME> on 19.06.11.
//  For license see LICENSE.TXT
//

#include "Mesh2.h"
#include <algorithm>

VertexNode *Mesh2::addVertex(const Vector3D &position)
{
    return _vertices.add(position);
}

TriangleNode *Mesh2::connectVerticesNearPosition(const Vector3D &position)
{
    vector<VertexNode *> vertices;
    
    for (uint i = 0; i < 4; i++)
    {
        vertices.push_back(findNearestVertex(position, vertices));
    }
    
    TriangleNode *quad = addQuad(vertices[0], vertices[1], vertices[2], vertices[3]);
    
    makeEdges();
    <commit_msg>Improved connectVertices.<commit_after>//
//  Mesh2.make.cpp
//  OpenGLEditor
//
//  Created by <NAME> on 19.06.11.
//  For license see LICENSE.TXT
//

#include "Mesh2.h"
#include <algorithm>

VertexNode *Mesh2::addVertex(const Vector3D &position)
{
    return _vertices.add(position);
}

TriangleNode *Mesh2::connectVerticesNearPosition(const Vector3D &position)
{
    vector<VertexNode *> vertices;
    Vector3D center = Vector3D();
    
    for (uint i = 0; i < 4; i++)
    {
        VertexNode *nearestVertex = findNearestVertex(position, vertices);
        vertices.push_back(nearestVertex);
        center += nearestVertex->data().position;
    }
    
    center /= 4.0f;
    
    Vector3D v0_center = vertices[0]->data().position - center;
    uint oppositeIndex_v0 = UINT_MAX;
    float smallestAngle = 0.0f;
    
    for (uint i = 1; i < 4; i++)
    {
        Vector3D v0_vi = vertices[0]->data().position - vertices[i]->data().position;
        float angle = fabsf(v0_vi.GetAngle(v0_center));
        if (oppositeIndex_v0 == UINT_MAX || smallestAngle > angle)
        {
            smallestAngle = angle;
            oppositeIndex_v0 = i;
        }
    }
    
    TriangleNode *quad = NULL;
    
    switch (oppositeIndex_v0)
    {
        case 1:
            quad = addQuad(vertices[0], vertices[3], vertices[1], vertices[2]);
            break;
        case 3:
            quad = addQuad(vertices[0], vertices[1], vertices[3], vertices[2]);
            break;
        case 2:
            quad = addQuad(vertices[0], vertices[1], vertices[2], vertices[3]);
            break;
    }
    
    makeEdges();
    
{'fraction_non_alphanumeric': 0.13648528099910795, 'fraction_numerical': 0.029884032114183764, 'mean_word_length': 2.5156739811912225, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, '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': '4763432', 'n_tokens_mistral': 777, 'n_tokens_neox': 753, 'n_words': 155}