Example #1
0
def test_convex_hull():
    p = [
        Point(-5, -1),
        Point(-2, 1),
        Point(-2, -1),
        Point(-1, -3),
        Point(0, 0),
        Point(1, 1),
        Point(2, 2),
        Point(2, -1),
        Point(3, 1),
        Point(4, -1),
        Point(6, 2)
    ]
    ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
    #test handling of duplicate points
    p.append(p[3])

    #more than 3 collinear points
    another_p = [
        Point(-45, -85),
        Point(-45, 85),
        Point(-45, 26),
        Point(-45, -24)
    ]
    ch2 = Segment(another_p[0], another_p[1])

    assert convex_hull(another_p) == ch2
    assert convex_hull(p) == ch
    assert convex_hull(p[0]) == p[0]
    assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])
Example #2
0
def test_convex_hull():
    p = [Point(-5,-1), Point(-2,1), Point(-2,-1), Point(-1,-3), Point(0,0),
         Point(1,1), Point(2,2), Point(2,-1), Point(3,1), Point(4,-1), Point(6,2)]
    ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
    assert convex_hull(p) == ch
    assert convex_hull(p[0]) == p[0]
    assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])
Example #3
0
def test_convex_hull():
    raises(TypeError, lambda: convex_hull(Point(0, 0), 3))
    points = [(1, -1), (1, -2), (3, -1), (-5, -2), (15, -4)]
    assert convex_hull(*points, **dict(polygon=False)) == ([
        Point2D(-5, -2),
        Point2D(1, -1),
        Point2D(3, -1),
        Point2D(15, -4)
    ], [Point2D(-5, -2), Point2D(15, -4)])
Example #4
0
def test_convex_hull():
    p = [Point(-5,-1), Point(-2,1), Point(-2,-1), Point(-1,-3), Point(0,0),
         Point(1,1), Point(2,2), Point(2,-1), Point(3,1), Point(4,-1), Point(6,2)]
    ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
    #test handling of duplicate points
    p.append(p[3])

    #more than 3 collinear points
    another_p = [Point(-45, -85), Point(-45, 85), Point(-45,26),Point(-45,-24)]
    ch2 = Segment(another_p[0],another_p[1])

    assert convex_hull(another_p) == ch2
    assert convex_hull(p) == ch
    assert convex_hull(p[0]) == p[0]
    assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])
Example #5
0
def test_convex_hull():
    p = [
        Point(-5, -1),
        Point(-2, 1),
        Point(-2, -1),
        Point(-1, -3),
        Point(0, 0),
        Point(1, 1),
        Point(2, 2),
        Point(2, -1),
        Point(3, 1),
        Point(4, -1),
        Point(6, 2)
    ]
    ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
    assert convex_hull(p) == ch
    assert convex_hull(p[0]) == p[0]
    assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])
Example #6
0
def test_convex_hull():
    p = [
        Point(-5, -1),
        Point(-2, 1),
        Point(-2, -1),
        Point(-1, -3),
        Point(0, 0),
        Point(1, 1),
        Point(2, 2),
        Point(2, -1),
        Point(3, 1),
        Point(4, -1),
        Point(6, 2),
    ]
    ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
    # test handling of duplicate points
    p.append(p[3])

    # more than 3 collinear points
    another_p = [Point(-45, -85), Point(-45, 85), Point(-45, 26), Point(-45, -24)]
    ch2 = Segment(another_p[0], another_p[1])

    assert convex_hull(*another_p) == ch2
    assert convex_hull(*p) == ch
    assert convex_hull(p[0]) == p[0]
    assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])

    # no unique points
    assert convex_hull(*[p[-1]] * 3) == p[-1]

    # collection of items
    assert convex_hull(*[Point(0, 0), Segment(Point(1, 0), Point(1, 1)), RegularPolygon(Point(2, 0), 2, 4)]) == Polygon(
        Point(0, 0), Point(2, -2), Point(4, 0), Point(2, 2)
    )
Example #7
0
def test_convex_hull():
    p = [Point(-5, -1), Point(-2, 1), Point(-2, -1), Point(-1, -3), \
         Point(0, 0), Point(1, 1), Point(2, 2), Point(2, -1), Point(3, 1), \
         Point(4, -1), Point(6, 2)]
    ch = Polygon(p[0], p[3], p[9], p[10], p[6], p[1])
    #test handling of duplicate points
    p.append(p[3])

    #more than 3 collinear points
    another_p = [Point(-45, -85), Point(-45, 85), Point(-45, 26), \
                 Point(-45, -24)]
    ch2 = Segment(another_p[0], another_p[1])

    assert convex_hull(*another_p) == ch2
    assert convex_hull(*p) == ch
    assert convex_hull(p[0]) == p[0]
    assert convex_hull(p[0], p[1]) == Segment(p[0], p[1])

    # no unique points
    assert convex_hull(*[p[-1]]*3) == p[-1]

    # collection of items
    assert convex_hull(*[Point(0, 0), \
                        Segment(Point(1, 0), Point(1, 1)), \
                        RegularPolygon(Point(2, 0), 2, 4)]) == \
        Polygon(Point(0, 0), Point(2, -2), Point(4, 0), Point(2, 2))
Example #8
0
    def __init__(self, dim, polygon=None, point=None):
        """
        Construct OBB from either the polygon which represents the convex hull or from a list of point.
        :param polygon: the sympy.geometry.Polygon which represents the convex hull of a set of points.
        :param point: list of sympy,geometry.Point.
        :modify: if successful diagonal coordinates of OBB where
                 r[0]: x_min
                 r[1]: y_min
                 r[2]: x_max
                 r[3]: y_max.
        :error: if dim is not 2 or both polygon and point are None raise ValueError.
        """

        if dim != 2:
            raise ValueError('only 2D is supported.')
        if point is None and polygon is not None:
            for _ in range(2*dim):
                self.r.append(polygon.bounds[_])
        elif point is not None and polygon is None:
            symgeo.convex_hull(point)
        else:
            raise ValueError('both polygon and point are None.')
Example #9
0
def test_util():
    # coverage for some leftover functions in sympy.geometry.util
    assert intersection(Point(0, 0)) == []
    raises(ValueError, lambda: intersection(Point(0, 0), 3))
    raises(ValueError, lambda: convex_hull(Point(0, 0), 3))
Example #10
0
def test_convex_hull():
    raises(TypeError, lambda: convex_hull(Point(0, 0), 3))
    points = [(1, -1), (1, -2), (3, -1), (-5, -2), (15, -4)]
    assert convex_hull(*points, **dict(polygon=False)) == (
        [Point2D(-5, -2), Point2D(1, -1), Point2D(3, -1), Point2D(15, -4)],
        [Point2D(-5, -2), Point2D(15, -4)])
Example #11
0
def test_util():
    # coverage for some leftover functions in sympy.geometry.util
    assert intersection(Point(0, 0)) == []
    raises(ValueError, lambda: intersection(Point(0, 0), 3))
    raises(ValueError, lambda: convex_hull(Point(0, 0), 3))
Example #12
0
def getConvexHullFromPoint(ptList):
    if (len(ptList) < 4):
        return (ptList, Polygon(*ptList))
    hull = convex_hull(*[(v.x, v.y) for v in ptList])
    hullVerts = hull.vertices
    return ([model.getVertexByLocation(v.x, v.y) for v in hullVerts], hull)