<commit_before># distutils: language = c++
# -*- coding: utf-8 -*-

""" An implementation of quadtrees -- iterating on pairs of neighbouring items

A quadtree is a tree data structure in which each node has exactly four
children. It is a particularly efficient way to store elements when you need
to quickly find them according to their x-y coordinates.

A common problem with elements in quadtrees is to detect pairs of elements
which are closer than a definite threshold.

The proposed implementation efficiently addresses this problem.

"""

from libcpp cimport bool as cppbool
from libcpp.vector cimport vector
from cpython.ref cimport Py_INCREF, Py_DECREF

cdef extern from "quadtree.h":
    cdef cppclass Boundary:
        float norm_infty()
    cdef cppclass PolygonMask:
        PolygonMask(vector[float], vector[float], int)
    cdef cppclass SmartQuadtree:
        SmartQuadtree(float, float, float, float, unsigned int)
        void setXYFcts(float (*x)(void*), float (*y)(void*))
        void setLimitation(cppbool (*limit)(Boundary*))
        cppbool insert(void*)
        void iterate(cppbool (*fct)(void*))
        void iterate(void (*fct)(void*, void*))
        void iterate(PolygonMask, cppbool (*fct)(void*))

cdef object global_lbd, global_flag
cdef float size_limit
cdef object string

cdef float c_getx(void* p):
    cdef object o = <object> (p)
    assert ("get_x" in dir(o))
    return <float> o.get_x()

cdef float c_getidx0(void* p):
    cdef object o = <object> (p)
    assert (isinstance(o, tuple) or isinstance(o, list))
    return <float> o[0]

cdef float c_gety(void* p):
    cdef object o = <object> (p)
    assert ("get_y" in dir(o))
    return <float> o.get_y()

cdef float c_getidx1(void* p):
    cdef object o = <object> (p)
    assert (isinstance(o, tuple) or isinstance(o, list))
    return <float> o[1]


class movable_elt(object):
    """ Decorator for callbacks that modify x-y coordinates of elements. """

    def __init__(self, f):
        self.func = f

    def __call__(self, *args, **kwargs):
        return self.func(*args, **kwargs)

    def __repr__(self):
        return self.func.__doc__


class static_elt(object):
    """ Decorator for callbacks that do not modify x-y coordinates of elements. """

    def __init__(self, f):
        self.func = f

    def __call__(self, *args, **kwargs):
        return self.func(*args, **kwargs)

    def __repr__(self):
        return self.func.__doc__


cdef cppbool apply_lambda(void* p):
    global global_lbd, global_flag
    global_lbd(<object> (p))
    return (<bint> global_flag)

cdef void apply_lambda_pair(void* p1, void* p2):
    global global_lbd
    global_lbd(<object> (p1), <object> (p2))
    return

cdef cppbool decref_all(void* p):
    Py_DECREF(<object> p)
    return <bint> False

cdef cppbool limitation(Boundary* b):
    global size_limit
    cdef float sq_size = b.norm_infty();
    return <bint> (sq_size < size_limit)

cdef class Quadtree(object):
    """ Main class for quadtrees
    You must provide x-y coordinates for a center, x-y dimensions for width
    and height of the quadtree and a maximum depth for subdivisions.

    For a quadtree centered on (0, 0) and ranging on [-10, 10]:
    >>> q = Quadtree(0., 0., 10., 10., 16)

    All methods attached to the Quadtree class are detailed below.
    """
    cdef PolygonMask* p
    cdef SmartQuadtree* q
    cdef object is_tuple_or_list
    cdef long count

    def __cinit__(self, x0, y0, dim_x, dim_y, depth):
        self.p = NULL
        self.q = new SmartQuadtree(x0, y0, dim_x, dim_y, depth)<commit_msg>Fix a typo in pyx file (silent on most Cython versions)<commit_after># distutils: language = c++
# -*- coding: utf-8 -*-

""" An implementation of quadtrees -- iterating on pairs of neighbouring items

A quadtree is a tree data structure in which each node has exactly four
children. It is a particularly efficient way to store elements when you need
to quickly find them according to their x-y coordinates.

A common problem with elements in quadtrees is to detect pairs of elements
which are closer than a definite threshold.

The proposed implementation efficiently addresses this problem.

"""

from libcpp cimport bool as cppbool
from libcpp.vector cimport vector
from cpython.ref cimport Py_INCREF, Py_DECREF

cdef extern from "quadtree.h":
    cdef cppclass Boundary:
        float norm_infty()
    cdef cppclass PolygonMask:
        PolygonMask(vector[float], vector[float], int)
    cdef cppclass SmartQuadtree:
        SmartQuadtree(float, float, float, float, unsigned int)
        void setXYFcts(float (*x)(void*), float (*y)(void*))
        void setLimitation(cppbool (*limit)(Boundary*))
        cppbool insert(void*)
        void iterate(cppbool (*fct)(void*))
        void iterate(void (*fct)(void*, void*))
        void iterate(PolygonMask, cppbool (*fct)(void*))

cdef object global_lbd, global_flag
cdef float size_limit
cdef object string

cdef float c_getx(void* p):
    cdef object o = <object> (p)
    assert ("get_x" in dir(o))
    return <float> o.get_x()

cdef float c_getidx0(void* p):
    cdef object o = <object> (p)
    assert (isinstance(o, tuple) or isinstance(o, list))
    return <float> o[0]

cdef float c_gety(void* p):
    cdef object o = <object> (p)
    assert ("get_y" in dir(o))
    return <float> o.get_y()

cdef float c_getidx1(void* p):
    cdef object o = <object> (p)
    assert (isinstance(o, tuple) or isinstance(o, list))
    return <float> o[1]


class movable_elt(object):
    """ Decorator for callbacks that modify x-y coordinates of elements. """

    def __init__(self, f):
        self.func = f

    def __call__(self, *args, **kwargs):
        return self.func(*args, **kwargs)

    def __repr__(self):
        return self.func.__doc__


class static_elt(object):
    """ Decorator for callbacks that do not modify x-y coordinates of elements. """

    def __init__(self, f):
        self.func = f

    def __call__(self, *args, **kwargs):
        return self.func(*args, **kwargs)

    def __repr__(self):
        return self.func.__doc__


cdef cppbool apply_lambda(void* p):
    global global_lbd, global_flag
    global_lbd(<object> (p))
    return (<bint> global_flag)

cdef void apply_lambda_pair(void* p1, void* p2):
    global global_lbd
    global_lbd(<object> (p1), <object> (p2))
    return

cdef cppbool decref_all(void* p):
    Py_DECREF(<object> p)
    return <bint> False

cdef cppbool limitation(Boundary* b):
    global size_limit
    cdef float sq_size = b.norm_infty()
    return <bint> (sq_size < size_limit)

cdef class Quadtree(object):
    """ Main class for quadtrees
    You must provide x-y coordinates for a center, x-y dimensions for width
    and height of the quadtree and a maximum depth for subdivisions.

    For a quadtree centered on (0, 0) and ranging on [-10, 10]:
    >>> q = Quadtree(0., 0., 10., 10., 16)

    All methods attached to the Quadtree class are detailed below.
    """
    cdef PolygonMask* p
    cdef SmartQuadtree* q
    cdef object is_tuple_or_list
    cdef long count

    def __cinit__(self, x0, y0, dim_x, dim_y, depth):
        self.p = NULL
        self.q = new SmartQuadtree(x0, y0, dim_x, dim_y, depth)
{'fraction_non_alphanumeric': 0.1051242882932926, 'fraction_numerical': 0.007498958477989168, 'mean_word_length': 3.3464091732045866, 'pattern_counts': {'":': 2, '<': 35, '<?xml version=': 0, '>': 39, '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': '2310488', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2330, 'n_words': 823}