<commit_before>#include "common.h"

// Includes
#include <cstdio>
#include <cstdlib>

using namespace v8;
using namespace node;

#include <iostream>
using namespace std;

namespace glu {

    /* GLFW initialization, termination and version querying */

    JS_METHOD(Init) {
        HandleScope scope;
        return scope.Close(Undefined());
    }

    JS_METHOD(newNurbsRenderer) {
        HandleScope scope;
        return scope.Close(External::New((void *)gluNewNurbsRenderer()));
    }

    JS_METHOD(newQuadric) {
        HandleScope scope;
        return scope.Close(External::New((void *)gluNewQuadric()));
    }

    JS_METHOD(newTess) {
        HandleScope scope;
        return scope.Close(External::New(gluNewTess()));
    }

    JS_METHOD(beginCurve) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluBeginCurve(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(beginPolygon) {
        HandleScope scope;
        GLUtesselator *ptr = (GLUtesselator *)External::Unwrap(args[0]);
        gluBeginPolygon(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(beginSurface) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluBeginSurface(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(beginTrim) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluBeginTrim(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endCurve) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluEndCurve(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endPolygon) {
        HandleScope scope;
        GLUtesselator *ptr = (GLUtesselator *)External::Unwrap(args[0]);
        gluEndPolygon(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endSurface) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluEndSurface(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endTrim) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluEndTrim(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(deleteNurbsRenderer) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluDeleteNurbsRenderer(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(deleteQuadric) {
        HandleScope scope;
        GLUquadric *ptr = (GLUquadric *)External::Unwrap(args[0]);
        gluDeleteQuadric(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(deleteTess) {
        HandleScope scope;
        GLUtesselator *ptr = (GLUtesselator *)External::Unwrap(args[0]);
        gluDeleteTess(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(cylinder) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble base = (GLdouble) args[1]->NumberValue();
        GLdouble top = (GLdouble) args[2]->NumberValue();
        GLdouble height = (GLdouble) args[3]->NumberValue();
        GLint slices = (GLint) args[4]->Int32Value();
        GLint loops = (GLint) args[5]->Int32Value();
        gluCylinder(quad, base, top, height, slices, loops);
        return scope.Close(Undefined());
    }

    JS_METHOD(disk) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble inner = (GLdouble) args[1]->NumberValue();
        GLdouble outer = (GLdouble) args[2]->NumberValue();
        GLint slices = (GLint) args[3]->Int32Value();
        GLint loops = (GLint) args[4]->Int32Value();
        gluDisk(quad, inner, outer, slices, loops);
        return scope.Close(Undefined());
    }

    JS_METHOD(partialDisk) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble inner = (GLdouble) args[1]->NumberValue();
        GLdouble outer = (GLdouble) args[2]->NumberValue();
        GLint slices = (GLint) args[3]->Int32Value();
        GLint loops = (GLint) args[4]->Int32Value();
        GLdouble start = (GLdouble) args[5]->NumberValue();
        GLdouble sweep = (GLdouble) args[2]->NumberValue();
        gluPartialDisk(quad, inner, outer, slices, loops, start, sweep);
        return scope.Close(Undefined());
    }

    JS_METHOD(sphere) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble radius = (GLdouble) args[1]->NumberValue();
        GLint slices = (GLint) args[2]->Int32Value();
        GLint stacks = (GLint) args[3]->Int32Value();
        gluSphere(quad, radius, slices, stacks);
        return scope.Close(Undefined());
    }

    JS_METHOD(perspective) {
        HandleScope scope;
        GLdouble fovy = (GLdouble) args[0]->NumberValue();
        GLdouble aspect = (GLdouble) args[1]->NumberValue();
        GLdouble zNear = (GLdouble) args[2]->NumberValue();
        GLdouble zFar = (GLdouble) args[3]->NumberValue();
        gluPerspective(fovy, aspect, zNear, zFar);
        return scope.Close(Undefined());
    }

    JS_METHOD(ortho2D) {
        HandleScope scope;
        GLdouble left = (GLdouble) args[0]->NumberValue();
        GLdouble right = (GLdouble) args[1]->NumberValue();
        GLdouble bottom = (GLdouble) args[2]->NumberValue();
        GLdouble top = (GLdouble) args[3]->NumberValue();
        gluOrtho2D(left, right, bottom, top);
        return scope.Close(Undefined());
    }

    JS_METHOD(lookAt) {
        HandleScope scope;
        GLdouble eyeX = (GLdouble) args[0]->NumberValue();
        GLdouble eyeY = (GLdouble) args[1]->NumberValue();
        GLdouble eyeZ = (GLdouble) args[2]->NumberValue();
        GLdouble centerX = (GLdouble) args[3]->NumberValue();
        GLdouble centerY = (GLdouble) args[4]->NumberValue();
        GLdouble centerZ = (GLdouble) args[5]->NumberValue();
        GLdouble upX = (GLdouble) args[6]->NumberValue();
        GLdouble upY = (GLdouble) args[7]->NumberValue();
        GLdouble upZ = (GLdouble) args[8]->NumberValue();
        gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
        return scope.Close(Undefined());
    }

    JS_METHOD(nextContour) {
        HandleScope scope;
        GLUtesselator *tess = (GLUtesselator *)External::Unwrap(args[0]);
        GLenum type = (GLenum) args[1]->Int32Value();
        gluNextContour(tess, type);
        return scope.Close(Undefined());
    }

    // make sure we close everything when we exit
    void AtExit() {
    }

} // namespace glfw

///////////////////////////////////////////////////////////////////////////////
//
// bindings
//
///////////////////////////////////////////////////////////////////////////////
#define JS_GLU_CONSTANT(name) target->Set(JS_STR( #name ), JS_INT(GLU_ ## name))
#define JS_GLU_SET_METHOD(name) NODE_SET_METHOD(target, #name , glu::name);

extern "C" {
    void init(Handle<Object> target) {
        atexit(glu::AtExit);

        HandleScope scope;

        /* GLFW initialization, termination and version querying */
        JS_GLU_SET_METHOD(Init);

        JS_GLU_SET_METHOD(newNurbsRenderer);
        JS_GLU_SET_METHOD(newQuadric);
        JS_GLU_SET_METHOD(newTess);

        JS_GLU_SET_METHOD(beginCurve);
        JS_GLU_SET_METHOD(beginPolygon);
        JS_GLU_SET_METHOD(beginSurface);
        JS_GLU_SET_METHOD(beginTrim);

        JS_GLU_SET_METHOD(endCurve);
        JS_GLU_SET_METHOD(endPolygon);
        JS_GLU_SET_METHOD(endSurface);
        JS_GLU_SET_METHOD(endTrim);

        JS_GLU_SET_METHOD(deleteNurbsRenderer);
        JS_GLU_SET_METHOD(deleteQuadric);
        JS_GLU_SET_METHOD(deleteTess);

        JS_GLU_SET_METHOD(cylinder);
        JS_GLU_SET_METHOD(disk);
        JS_GLU_SET_METHOD(partialDisk);
        JS_GLU_SET_METHOD(sphere);

        JS_GLU_SET_METHOD(ortho2D);
        JS_GLU_SET_METHOD(perspective);
        JS_GLU_SET_METHOD(lookAt);

        /*************************************************************************
         * GLFW version
         *************************************************************************/

        JS_GLU_CONSTANT(EXT_object_space_tess);
        JS_GLU_CONSTANT(EXT_nurbs_tessellator);
        JS_GLU_CONSTANT(FALSE);
        JS_GLU_CONSTANT(TRUE);
        JS_GLU_CONSTANT(VERSION_1_1);<commit_msg>added build2DMipmaps<commit_after>#include "common.h"

// Includes
#include <cstdio>
#include <cstdlib>

using namespace v8;
using namespace node;

#include <iostream>
using namespace std;

namespace glu {

    inline void *getImageData(Local<Value> arg) {
        void *pixels = NULL;
        if (!arg->IsNull()) {
            Local<Object> obj = Local<Object>::Cast(arg);
            if (!obj->IsObject())
                ThrowException(JS_STR("Bad texture argument"));

            pixels = obj->GetIndexedPropertiesExternalArrayData();
        }
        return pixels;
    }


    /* GLFW initialization, termination and version querying */

    JS_METHOD(Init) {
        HandleScope scope;
        return scope.Close(Undefined());
    }

    JS_METHOD(newNurbsRenderer) {
        HandleScope scope;
        return scope.Close(External::New((void *)gluNewNurbsRenderer()));
    }

    JS_METHOD(newQuadric) {
        HandleScope scope;
        return scope.Close(External::New((void *)gluNewQuadric()));
    }

    JS_METHOD(newTess) {
        HandleScope scope;
        return scope.Close(External::New(gluNewTess()));
    }

    JS_METHOD(beginCurve) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluBeginCurve(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(beginPolygon) {
        HandleScope scope;
        GLUtesselator *ptr = (GLUtesselator *)External::Unwrap(args[0]);
        gluBeginPolygon(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(beginSurface) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluBeginSurface(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(beginTrim) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluBeginTrim(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endCurve) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluEndCurve(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endPolygon) {
        HandleScope scope;
        GLUtesselator *ptr = (GLUtesselator *)External::Unwrap(args[0]);
        gluEndPolygon(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endSurface) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluEndSurface(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(endTrim) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluEndTrim(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(deleteNurbsRenderer) {
        HandleScope scope;
        GLUnurbs *ptr = (GLUnurbs *)External::Unwrap(args[0]);
        gluDeleteNurbsRenderer(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(deleteQuadric) {
        HandleScope scope;
        GLUquadric *ptr = (GLUquadric *)External::Unwrap(args[0]);
        gluDeleteQuadric(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(deleteTess) {
        HandleScope scope;
        GLUtesselator *ptr = (GLUtesselator *)External::Unwrap(args[0]);
        gluDeleteTess(ptr);
        return scope.Close(Undefined());
    }

    JS_METHOD(cylinder) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble base = (GLdouble) args[1]->NumberValue();
        GLdouble top = (GLdouble) args[2]->NumberValue();
        GLdouble height = (GLdouble) args[3]->NumberValue();
        GLint slices = (GLint) args[4]->Int32Value();
        GLint loops = (GLint) args[5]->Int32Value();
        gluCylinder(quad, base, top, height, slices, loops);
        return scope.Close(Undefined());
    }

    JS_METHOD(disk) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble inner = (GLdouble) args[1]->NumberValue();
        GLdouble outer = (GLdouble) args[2]->NumberValue();
        GLint slices = (GLint) args[3]->Int32Value();
        GLint loops = (GLint) args[4]->Int32Value();
        gluDisk(quad, inner, outer, slices, loops);
        return scope.Close(Undefined());
    }

    JS_METHOD(partialDisk) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble inner = (GLdouble) args[1]->NumberValue();
        GLdouble outer = (GLdouble) args[2]->NumberValue();
        GLint slices = (GLint) args[3]->Int32Value();
        GLint loops = (GLint) args[4]->Int32Value();
        GLdouble start = (GLdouble) args[5]->NumberValue();
        GLdouble sweep = (GLdouble) args[2]->NumberValue();
        gluPartialDisk(quad, inner, outer, slices, loops, start, sweep);
        return scope.Close(Undefined());
    }

    JS_METHOD(sphere) {
        HandleScope scope;
        GLUquadric *quad = (GLUquadric *)External::Unwrap(args[0]);
        GLdouble radius = (GLdouble) args[1]->NumberValue();
        GLint slices = (GLint) args[2]->Int32Value();
        GLint stacks = (GLint) args[3]->Int32Value();
        gluSphere(quad, radius, slices, stacks);
        return scope.Close(Undefined());
    }

    JS_METHOD(perspective) {
        HandleScope scope;
        GLdouble fovy = (GLdouble) args[0]->NumberValue();
        GLdouble aspect = (GLdouble) args[1]->NumberValue();
        GLdouble zNear = (GLdouble) args[2]->NumberValue();
        GLdouble zFar = (GLdouble) args[3]->NumberValue();
        gluPerspective(fovy, aspect, zNear, zFar);
        return scope.Close(Undefined());
    }

    JS_METHOD(ortho2D) {
        HandleScope scope;
        GLdouble left = (GLdouble) args[0]->NumberValue();
        GLdouble right = (GLdouble) args[1]->NumberValue();
        GLdouble bottom = (GLdouble) args[2]->NumberValue();
        GLdouble top = (GLdouble) args[3]->NumberValue();
        gluOrtho2D(left, right, bottom, top);
        return scope.Close(Undefined());
    }

    JS_METHOD(lookAt) {
        HandleScope scope;
        GLdouble eyeX = (GLdouble) args[0]->NumberValue();
        GLdouble eyeY = (GLdouble) args[1]->NumberValue();
        GLdouble eyeZ = (GLdouble) args[2]->NumberValue();
        GLdouble centerX = (GLdouble) args[3]->NumberValue();
        GLdouble centerY = (GLdouble) args[4]->NumberValue();
        GLdouble centerZ = (GLdouble) args[5]->NumberValue();
        GLdouble upX = (GLdouble) args[6]->NumberValue();
        GLdouble upY = (GLdouble) args[7]->NumberValue();
        GLdouble upZ = (GLdouble) args[8]->NumberValue();
        gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
        return scope.Close(Undefined());
    }

    JS_METHOD(nextContour) {
        HandleScope scope;
        GLUtesselator *tess = (GLUtesselator *)External::Unwrap(args[0]);
        GLenum type = (GLenum) args[1]->Int32Value();
        gluNextContour(tess, type);
        return scope.Close(Undefined());
    }

    JS_METHOD(build2DMipmaps) {
        HandleScope scope;

        int target = args[0]->Int32Value();
        int internalformat = args[1]->Int32Value();
        int width = args[2]->Int32Value();
        int height = args[3]->Int32Value();
        int format = args[4]->Int32Value();
        int type = args[5]->Int32Value();
        void *pixels = getImageData(args[6]);

        gluBuild2DMipmaps(target, internalformat, width, height, format, type, pixels);

        return scope.Close(Undefined());
    }


    // make sure we close everything when we exit
    void AtExit() {
    }

} // namespace glfw

///////////////////////////////////////////////////////////////////////////////
//
// bindings
//
///////////////////////////////////////////////////////////////////////////////
#define JS_GLU_CONSTANT(name) target->Set(JS_STR( #name ), JS_INT(GLU_ ## name))
#define JS_GLU_SET_METHOD(name) NODE_SET_METHOD(target, #name , glu::name);

extern "C" {
    void init(Handle<Object> target) {
        atexit(glu::AtExit);

        HandleScope scope;

        /* GLFW initialization, termination and version querying */
        JS_GLU_SET_METHOD(Init);

        JS_GLU_SET_METHOD(newNurbsRenderer);
        JS_GLU_SET_METHOD(newQuadric);
        JS_GLU_SET_METHOD(newTess);

        JS_GLU_SET_METHOD(beginCurve);
        JS_GLU_SET_METHOD(beginPolygon);
        JS_GLU_SET_METHOD(beginSurface);
        JS_GLU_SET_METHOD(beginTrim);

        JS_GLU_SET_METHOD(endCurve);
        JS_GLU_SET_METHOD(endPolygon);
        JS_GLU_SET_METHOD(endSurface);
        JS_GLU_SET_METHOD(endTrim);

        JS_GLU_SET_METHOD(deleteNurbsRenderer);
        JS_GLU_SET_METHOD(deleteQuadric);
        JS_GLU_SET_METHOD(deleteTess);

        JS_GLU_SET_METHOD(cylinder);
        JS_GLU_SET_METHOD(disk);
        JS_GLU_SET_METHOD(partialDisk);
        JS_GLU_SET_METHOD(sphere);

        JS_GLU_SET_METHOD(ortho2D);
        JS_GLU_SET_METHOD(perspective);
        JS_GLU_SET_METHOD(lookAt);
        JS_GLU_SET_METHOD(build2DMipmaps);

        /*************************************************************************
         * GLFW version
         *************************************************************************/

        JS_GLU_CONSTANT(EXT_object_space_tess);
        JS_GLU_CONSTANT(EXT_nurbs_tessellator);
        JS_GLU_CONSTANT(FALSE);
        JS_GLU_CONSTANT(TRUE);
        JS_GLU_CONSTANT(VERSION_1_1);
{'fraction_non_alphanumeric': 0.16207165978345797, 'fraction_numerical': 0.009766715035160174, 'mean_word_length': 2.70916994411095, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 97, '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': '2295078', 'n_tokens_mistral': 5748, 'n_tokens_neox': 5516, 'n_words': 995}