def split(self, polygon, co_front, co_back, front, back):
        COPLANAR = 0
        FRONT = 1
        BACK = 2
        BOTH = 3
        EPS = 1e-5
        polygon_type = 0
        vertex_types = []
        for vertex in polygon.vertices:
            w = self.normal.dot(vertex.position) - self.w
            t = COPLANAR
            if w < -EPS:
                t = BACK
            if w > EPS:
                t = FRONT
            polygon_type |= t
            vertex_types.append(t)
        if polygon_type == COPLANAR:
            if self.normal.dot(polygon.plane.normal) > 0:
                co_front.append(polygon)
            else:
                co_back.append(polygon)
        elif polygon_type == FRONT:
            front.append(polygon)
        elif polygon_type == BACK:
            back.append(polygon)
        else:
            f = []
            b = []
            for i in xrange(len(polygon.vertices)):
                j = (i + 1) % len(polygon.vertices)
                v1 = polygon.vertices[i]
                v2 = polygon.vertices[j]
                t1 = vertex_types[i]
                t2 = vertex_types[j]
                if t1 != BACK:
                    f.append(v1)
                if t1 != FRONT:
                    if t1 != BACK:
                        b.append(v1.clone())
                    else:
                        b.append(v1)
                if (t1 | t2) == BOTH:
                    n = self.w - self.normal.dot(v1.position)
                    d = self.normal.dot(v2.position.subtract(v1.position))
                    v = v1.interpolate(v2, n / d)
                    f.append(v)
                    b.append(v.clone())
            if len(f) >= 3:
                front.append(Polygon(f, polygon.shared))
            if len(b) >= 3:
                back.append(Polygon(b, polygon.shared))
dataset/ETHPy150Open fogleman/pg/pg/csg.py/Plane.split/original