<commit_before>#!/usr/bin/env python
###############################################################################
##
## Copyright (C) 2010  Thammi
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
###############################################################################

import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *

import time
import sys
from math import cos, sin, pi

def list_render(render_fun):
    gl_list = glGenLists(1)

    glNewList(gl_list, GL_COMPILE)
    render_fun()
    glEndList()

    return gl_list

class Vector:

    def __init__(self, *data):
        if len(data) == 1:
            self.data = list(data[0])
        else:
            self.data = list(data)

    def len_check(self, size):
        if len(self) != size:
            print len(self)
            raise NotImplementedError

    def __repr__(self):
        return "Vector(%s)" % ', '.join(str(v) for v in self.data)

    def __len__(self):
        return len(self.data)

    def __iter__(self):
        return self.data.__iter__()
    
    def __getitem__(self, index):
        return self.data[index]

    def __setitem__(self, index, value):
        self.data[index] = value

    def __add__(self, other):
        return Vector(a + b for a, b in zip(self, other))

    def __sub__(self, other):
        return Vector(a - b for a, b in zip(self, other))

    def cross(self, other):
        self.len_check(3)

        a = self
        b = other

        return Vector(a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0])

    def __mul__(self, factor):
        if isinstance(factor, Vector):
            return Vector(v * f for v, f in zip(self, factor))
        else:
            return Vector(v * factor for v in self)

    def __rmul__(self, factor):
        return self.__mul__(factor)
    
    def __imul__(self, factor):
        # TODO: ugly ...
        v = self.__mul__(factor)
        self.data = v.data
        return self

    def size(self):
        self.len_check(3)

        return sum(v*v for v in self.data) ** 0.5
    
    def normalize(self):
        self *= 1. / self.size()

class PolyPackage:

    def __init__(self, color=(1, 0, 1)):
        self.polygons = []
        self.color = color

    def add(self, a, b, c):
        self.polygons.append([a, b, c])

    def gl_init(self):
        self.gl_list = list_render(self.raw_render)

    def raw_render(self):
        glColor(*self.color)

        glBegin(GL_TRIANGLES)

        for polygon in self.polygons:
            ab = polygon[1] - polygon[0]
            ac = polygon[2] - polygon[0]
            n = ab.cross(ac)<commit_msg>Enabling PolyPackages to assimilate others<commit_after>#!/usr/bin/env python
###############################################################################
##
## Copyright (C) 2010  Thammi
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
###############################################################################

import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *

import time
import sys
from math import cos, sin, pi

def list_render(render_fun):
    gl_list = glGenLists(1)

    glNewList(gl_list, GL_COMPILE)
    render_fun()
    glEndList()

    return gl_list

class Vector:

    def __init__(self, *data):
        if len(data) == 1:
            self.data = list(data[0])
        else:
            self.data = list(data)

    def len_check(self, size):
        if len(self) != size:
            print len(self)
            raise NotImplementedError

    def __repr__(self):
        return "Vector(%s)" % ', '.join(str(v) for v in self.data)

    def __len__(self):
        return len(self.data)

    def __iter__(self):
        return self.data.__iter__()
    
    def __getitem__(self, index):
        return self.data[index]

    def __setitem__(self, index, value):
        self.data[index] = value

    def __add__(self, other):
        return Vector(a + b for a, b in zip(self, other))

    def __sub__(self, other):
        return Vector(a - b for a, b in zip(self, other))

    def cross(self, other):
        self.len_check(3)

        a = self
        b = other

        return Vector(a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0])

    def __mul__(self, factor):
        if isinstance(factor, Vector):
            return Vector(v * f for v, f in zip(self, factor))
        else:
            return Vector(v * factor for v in self)

    def __rmul__(self, factor):
        return self.__mul__(factor)
    
    def __imul__(self, factor):
        # TODO: ugly ...
        v = self.__mul__(factor)
        self.data = v.data
        return self

    def size(self):
        self.len_check(3)

        return sum(v*v for v in self.data) ** 0.5
    
    def normalize(self):
        self *= 1. / self.size()

class PolyPackage:

    def __init__(self, color=(1, 0, 1)):
        self.polygons = []
        self.color = color

    def add(self, a, b, c):
        self.polygons.append([a, b, c])

    def assimilate(self, obj):
        self.polygons.extend(obj.polygons)

    def gl_init(self):
        self.gl_list = list_render(self.raw_render)

    def raw_render(self):
        glColor(*self.color)

        glBegin(GL_TRIANGLES)

        for polygon in self.polygons:
            ab = polygon[1] - polygon[0]
            ac = polygon[2] - polygon[0]
            n = ab.cross(ac)
{'fraction_non_alphanumeric': 0.15829825616355983, 'fraction_numerical': 0.009621166566446182, 'mean_word_length': 2.559657570893526, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '542623', 'n_tokens_mistral': 2112, 'n_tokens_neox': 2011, 'n_words': 643}