polylabel 0.1.11

A Rust implementation of the Polylabel algorithm
Documentation
from ctypes import POINTER, c_double, c_size_t, c_void_p, Structure, cast
import numpy as np
import ipdb

class External(Structure):

    _fields_ = [("data", c_void_p),
                ("length", c_size_t)]
    @classmethod
    def from_param(cls, seq):
        return seq if isinstance(seq, cls) else cls(seq)

    def __init__(self, seq):
        self.ptr = cast(
            np.array(seq, dtype=np.float64).ctypes.data_as(POINTER(c_double)),
            c_void_p
        )
        self.data = self.ptr
        self.length = len(seq)
        # recreate array from void pointer
        # shows the correct values
        # shape = self.length, 2
        # ptr = cast(self.data, POINTER(c_double))
        # array = np.ctypeslib.as_array(ptr, shape)
        # print "Correct array", array.tolist()

if __name__ == "__main__":
    interiors = [
            [[3.5, 3.5], [4.4, 2.0], [2.6, 2.0], [3.5, 3.5]],
            [[4.0, 3.0], [4.0, 3.2], [4.5, 3.2], [4.0, 3.0]],
            # [[4.0, 3.0], [4.0, 3.2], [4.0, 3.2], [4.0, 3.2], [4.0, 3.2], [4.0, 3.0]]
            ]
    wrong = [External(s) for s in interiors]
    for w in wrong:
        # perform same cast back to array as before
        shape = w.length, 2
        ptr = cast(w.data, POINTER(c_double))
        ipdb.set_trace()
        array = np.ctypeslib.as_array(ptr, shape)
        print "Wrong array", array.tolist()