Ejemplo n.º 1
0
        if p[i].y < p[minIndex].y:
            minIndex = i

    p[n] = p[minIndex]
    th = 0.0

    for m in range(n):
        p[m], p[minIndex] = p[minIndex], p[m]
        minIndex = n
        v = th
        th = 360.0
        for i in range(m+1, n+1):
            if theta(p[m], p[i]) > v:
                if theta(p[m], p[i]) < th:
                    minIndex = i
                    th = theta(p[m], p[minIndex])

        if minIndex == n:
            return m

N = 16
p = []

for i in range(N):
    p.append(g.point(g.x_value[i], g.y_value[i], g.c_value[i]))

p.append(g.point(None, None, None))
M = packageWraaping(p, N)

for i in range(M+1):
    print(p[i].c, end =' ')
Ejemplo n.º 2
0
 def __init__(self):
     self.p = g.point(max, max, '')
     self.next = None
Ejemplo n.º 3
0
class Range:
    dummy = g.point(0, 0, None)

    class node:
        p = g.point
        l = None
        r = None

        def __init__(self, pp, ll, rr):
            self.p = pp
            self.l = ll
            self.r = rr

    z = node(dummy, 0, 0)
    z.l = z
    z.r = z
    head = node(dummy, 0, z)

    def insert(self, p):
        d = True
        f = self.node
        t = self.head
        while t != self.z:
            if d:
                td = p.x < t.p.x
            else:
                td = p.y < t.p.y
            f = t
            if td:
                t = t.l
            else:
                t = t.r
            d = not d
        t = self.node(self.dummy, 0, 0)
        t.p = p
        t.l = self.z
        t.r = self.z
        if td:
            f.l = t
        else:
            f.r = t

    def search(self, t_range):
        return self.searchr(self.head.r, t_range, 0)

    def searchr(self, t, t_range, d):
        count = 0
        if t == self.z:
            return 0
        tx1 = t_range.x1 < t.p.x

        tx2 = t.p.x <= t_range.x2
        ty1 = t_range.y1 < t.p.y
        ty2 = t.p.y <= t_range.y2
        if d:
            t1 = tx1
            t2 = tx2
        else:
            t1 = ty1
            t2 = ty2

        if t1:
            count += self.searchr(t.l, t_range, not d)
        if insideReact(t.p, t_range):
            count += 1
        if t2:
            count += self.searchr(t.r, t_range, not d)

        return count
Ejemplo n.º 4
0
    h = p
    for i in range(N):
        t = node()
        t.p.x = g.x_value[i]
        t.p.y = g.y_value[i]
        t.p.c = g.c_value[i]

        p.next = t
        p = p.next

    p.next = z
    return h

N = 8
max = 1000
cp1 = g.point(max, max, '')
cp2 = g.point(max, max, '')
min = max

z = node()
z.p.x = max
z.p.y = max
z.next = z

h = node()
h.next = readlist()

t_pass = 1
h.next = sort(h.next, N)
t_pass = 2
h.next = sort(h.next, N)
Ejemplo n.º 5
0
        else:
            t1 = ty1
            t2 = ty2

        if t1:
            count += self.searchr(t.l, t_range, not d)
        if insideReact(t.p, t_range):
            count += 1
        if t2:
            count += self.searchr(t.r, t_range, not d)

        return count


N = 16
r = Range()
t_range = rect()
p = []
for i in range(N):
    p.append(g.point(g.x_value[i], g.y_value[i], g.c_value[i]))

for i in range(N):
    r.insert(p[i])

t_range.x1 = 7
t_range.y1 = 10
t_range.x2 = 11
t_range.y2 = 16

result = r.search(t_range)
print("범위 내에 있는 점의 개수 : ", result)