<commit_before>#include "ofxQuadSurface.h"

ofxQuadSurface::ofxQuadSurface()
{
	cout << "ofxQuadSurface constructor." << endl;
    setup();
}

ofxQuadSurface::~ofxQuadSurface()
{
	cout << "ofxQuadSurface destructor." << endl;
}

void ofxQuadSurface::setup()
{
    // Create 4 points for the 2 triangles
    ofVec2f p1 = ofVec2f(0, 0);
    ofVec2f p2 = ofVec2f(0, ofGetHeight());
    ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight());
    ofVec2f p4 = ofVec2f(ofGetWidth(), 0);

    // Create 4 point for the texture coordinates
    ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f));
    ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f));
    ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f));
    ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f));

    setup( p1, p2, p3, p4, t1, t2, t3, t4, texture );
}

void ofxQuadSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, 
                            ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofTexture* texturePtr )
{
    // Assign texture
    texture = texturePtr;
    
    // Clear mesh
    mesh.clear();
    
    // Create a surface with the points
    mesh.addVertex( p1 );
    mesh.addVertex( p2 );
    mesh.addVertex( p3 );
    mesh.addVertex( p4 );

    // Add 2 triangles
    mesh.addTriangle(0, 2, 3);
    mesh.addTriangle(0, 1, 2);

    // Add texture coordinates
    mesh.addTexCoord(t1);
    mesh.addTexCoord(t2);
    mesh.addTexCoord(t3);
    mesh.addTexCoord(t4);
    
    // Pure GL setup
    // indices
    quadIndices[0] = 0;
    quadIndices[1] = 1;
    quadIndices[2] = 2;
    quadIndices[3] = 0;
    quadIndices[4] = 2;
    quadIndices[5] = 3;
    //tex coords (those are alway 0)
    quadTexCoordinates[2] = 0;
    quadTexCoordinates[6] = 0;
    quadTexCoordinates[10] = 0;
    quadTexCoordinates[14] = 0;
    
    calculate4dTextureCoords();
}

void ofxQuadSurface::draw()
{
    if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){
        calculate4dTextureCoords();
    }
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(4, GL_FLOAT, 0, quadTexCoordinates);
    glVertexPointer(3, GL_FLOAT, 0, quadVertices);
    
    texture->bind();
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, quadIndices);
    texture->unbind();
}

void ofxQuadSurface::setVertex(int index, ofVec2f p)
{
    if ( index > 3 ) {
        ofLog() << "Vertex with this index does not exist: " << index << endl;
        return;
    }
    
    mesh.setVertex(index, p);
}

void ofxQuadSurface::setTexCoord(int index, ofVec2f t)
{
    if ( index > 3 ) {
        ofLog() << "Texture coordinate with this index does not exist: " << index << endl;
        return;
    }
    
    mesh.setTexCoord(index, t);
}

int ofxQuadSurface::getType()
{
    return ofxSurfaceType::QUAD_SURFACE;
}

bool ofxQuadSurface::hitTest(ofVec2f p)
{
    // Construct ofPolyline from vertices
    ofPolyline line = getHitArea();
    
    if ( line.inside(p.x, p.y) ) {
        return true;
    } else {
        return false;
    }
}

ofVec2f ofxQuadSurface::getVertex(int index)
{
    if ( index > 3 ) {
        ofLog() << "Vertex with this index does not exist: " << index << endl;
        throw std::runtime_error("Vertex index out of bounds.");
    }
    
    ofVec3f vert = mesh.getVertex(index);
    return ofVec2f(vert.x, vert.y);
}<commit_msg>only recalculate on setVertex and SetTexCoord<commit_after>#include "ofxQuadSurface.h"

ofxQuadSurface::ofxQuadSurface()
{
	cout << "ofxQuadSurface constructor." << endl;
    setup();
}

ofxQuadSurface::~ofxQuadSurface()
{
	cout << "ofxQuadSurface destructor." << endl;
}

void ofxQuadSurface::setup()
{
    // Create 4 points for the 2 triangles
    ofVec2f p1 = ofVec2f(0, 0);
    ofVec2f p2 = ofVec2f(0, ofGetHeight());
    ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight());
    ofVec2f p4 = ofVec2f(ofGetWidth(), 0);

    // Create 4 point for the texture coordinates
    ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f));
    ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f));
    ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f));
    ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f));

    setup( p1, p2, p3, p4, t1, t2, t3, t4, texture );
}

void ofxQuadSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, 
                            ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofTexture* texturePtr )
{
    // Assign texture
    texture = texturePtr;
    
    // Clear mesh
    mesh.clear();
    
    // Create a surface with the points
    mesh.addVertex( p1 );
    mesh.addVertex( p2 );
    mesh.addVertex( p3 );
    mesh.addVertex( p4 );

    // Add 2 triangles
    mesh.addTriangle(0, 2, 3);
    mesh.addTriangle(0, 1, 2);

    // Add texture coordinates
    mesh.addTexCoord(t1);
    mesh.addTexCoord(t2);
    mesh.addTexCoord(t3);
    mesh.addTexCoord(t4);
    
    // Pure GL setup
    // indices
    quadIndices[0] = 0;
    quadIndices[1] = 1;
    quadIndices[2] = 2;
    quadIndices[3] = 0;
    quadIndices[4] = 2;
    quadIndices[5] = 3;
    //tex coords (those are alway 0)
    quadTexCoordinates[2] = 0;
    quadTexCoordinates[6] = 0;
    quadTexCoordinates[10] = 0;
    quadTexCoordinates[14] = 0;
    
    calculate4dTextureCoords();
}

void ofxQuadSurface::draw()
{
    /*if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){
        calculate4dTextureCoords();
    }*/
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(4, GL_FLOAT, 0, quadTexCoordinates);
    glVertexPointer(3, GL_FLOAT, 0, quadVertices);
    
    texture->bind();
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, quadIndices);
    texture->unbind();
}

void ofxQuadSurface::setVertex(int index, ofVec2f p)
{
    if ( index > 3 ) {
        ofLog() << "Vertex with this index does not exist: " << index << endl;
        return;
    }
    
    mesh.setVertex(index, p);
    calculate4dTextureCoords();
}

void ofxQuadSurface::setTexCoord(int index, ofVec2f t)
{
    if ( index > 3 ) {
        ofLog() << "Texture coordinate with this index does not exist: " << index << endl;
        return;
    }
    
    mesh.setTexCoord(index, t);
    calculate4dTextureCoords();
}

int ofxQuadSurface::getType()
{
    return ofxSurfaceType::QUAD_SURFACE;
}

bool ofxQuadSurface::hitTest(ofVec2f p)
{
    // Construct ofPolyline from vertices
    ofPolyline line = getHitArea();
    
    if ( line.inside(p.x, p.y) ) {
        return true;
    } else {
        return false;
    }
}

ofVec2f ofxQuadSurface::getVertex(int index)
{
    if ( index > 3 ) {
        ofLog() << "Vertex with this index does not exist: " << index << endl;
        throw std::runtime_error("Vertex index out of bounds.");
    }
    
    ofVec3f vert = mesh.getVertex(index);
    return ofVec2f(vert.x, vert.y);
}
{'fraction_non_alphanumeric': 0.1332133213321332, 'fraction_numerical': 0.039003900390039, 'mean_word_length': 2.862688296639629, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6778033', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2542, 'n_words': 551}