<commit_before># -*- coding: utf-8 -*-
from pygame import transform, font, mask, Surface, Rect, SRCALPHA
from pygame.sprite import Group, Sprite, collide_mask
from random import randint
import colorsys
import pygame

TAG_PADDING = 12
STEP_SIZE = 3

LOWER_START = 0.45
UPPER_START = 0.55

UP = 0
DOWN = 1
LEFT = 2
RIGHT = 3

class Tag(Sprite):
    """
    Font tag sprite. Blit the font to a surface to correct the font padding
    """
    def __init__(self, tag, initial_position, rotation=0, fontname='fonts/Arial.ttf', fontzoom=5):
        Sprite.__init__(self)
        self._tag = tag
        fonter = font.Font(fontname, int(tag['size'] * fontzoom)).render(tag['tag'], True, tag['color'])
        self._tag['size'] *= fontzoom
        fonter = transform.rotate(fonter, rotation)
        frect = fonter.get_bounding_rect()
        frect.x = -frect.x
        frect.y = -frect.y        
        self._fontoffset = (-frect.x, -frect.y)
        font_sf = Surface((frect.width, frect.height), pygame.SRCALPHA, 32)
        font_sf.blit(fonter, frect)        
        self.image = font_sf
        self.rect = font_sf.get_rect()
        self.rect.width += TAG_PADDING
        self.rect.height += TAG_PADDING
        self.rect.x = initial_position[0]
        self.rect.y = initial_position[1]
        self.mask = mask.from_surface(self.image)
        msize = self.mask.get_size()
        self.mask = self.mask.scale(((msize[0] + TAG_PADDING), (msize[1] + TAG_PADDING)))

    def get_tag(self):
        return self._tag
    tag = property(get_tag)
    
    def get_fontoffset(self):
        return self._fontoffset
    fontoffset = property(get_fontoffset)
        
def _do_collide(sprite, group):
    """<commit_msg>correct padding of mask using convolve<commit_after># -*- coding: utf-8 -*-
from pygame import transform, font, mask, Surface, Rect, SRCALPHA, draw
from pygame.sprite import Group, Sprite, collide_mask
from random import randint
import colorsys
import pygame

TAG_PADDING = 5
STEP_SIZE = 3

LOWER_START = 0.45
UPPER_START = 0.55

UP = 0
DOWN = 1
LEFT = 2
RIGHT = 3

convsurf = Surface((2*TAG_PADDING, 2*TAG_PADDING))
convsurf.fill((255,0,255))
convsurf.set_colorkey((255,0,255))
draw.circle(convsurf, (0, 0, 0),(TAG_PADDING, TAG_PADDING), TAG_PADDING)
convmask = mask.from_surface(convsurf)

class Tag(Sprite):
    """
    Font tag sprite. Blit the font to a surface to correct the font padding
    """
    def __init__(self, tag, initial_position, rotation=0, fontname='fonts/Arial.ttf', fontzoom=5):
        Sprite.__init__(self)
        self._tag = tag
        fonter = font.Font(fontname, int(tag['size'] * fontzoom)).render(tag['tag'], True, tag['color'])
        self._tag['size'] *= fontzoom
        fonter = transform.rotate(fonter, rotation)
        frect = fonter.get_bounding_rect()
        frect.x = -frect.x
        frect.y = -frect.y        
        self._fontoffset = (-frect.x, -frect.y)
        font_sf = Surface((frect.width, frect.height), pygame.SRCALPHA, 32)
        font_sf.blit(fonter, frect)        
        self.image = font_sf
        self.rect = font_sf.get_rect()
        self.rect.width += TAG_PADDING
        self.rect.height += TAG_PADDING
        self.rect.x = initial_position[0]
        self.rect.y = initial_position[1]
        self.mask = mask.from_surface(self.image)
        self.mask = self.mask.convolve(convmask, None, (TAG_PADDING, TAG_PADDING))

    def get_tag(self):
        return self._tag
    tag = property(get_tag)
    
    def get_fontoffset(self):
        return self._fontoffset
    fontoffset = property(get_fontoffset)
        
def _do_collide(sprite, group):
    """
{'fraction_non_alphanumeric': 0.12252202643171806, 'fraction_numerical': 0.016519823788546256, 'mean_word_length': 2.8403805496828753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6170885', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1248, 'n_words': 279}