# Path: sc8pr/geom.py
# def sigma(*args):
#     "Sum one or more vectors"
#     return tuple(sum(x[i] for x in args) for i in range(len(args[0])))
# 
# def delta(v2, v1=None, mag=None):
#     "v2 - v1, rescaled to specified magnitude"
#     if v1:
#         x = v2[0] - v1[0]
#         y = v2[1] - v1[1]
#     else: x, y = v2
#     if mag is not None:
#         r = hypot(x, y)
#         if r:
#             mag /= r
#             x *= mag
#             y *= mag
#     return x, y


import sys, pygame
from random import randint
from traceback import format_exc
from zipfile import ZipFile
from pathlib import Path
from sc8pr.geom import sigma, delta
    else: x, y, w, h = r
    ver = (x, y, weight, h), (x + w - weight, y, weight, h)
    w -= 2 * weight
    x += weight
    hor = (x, y, w, weight), (x, y + h - weight, w, weight)
    clip = srf.get_clip()
    sides = [pygame.Rect(s).clip(clip) for s in (ver + hor)]
    for s in sides:
        if s: srf.subsurface(s).fill(color)

def tile(srf, tile=0, cols=1, rows=1, padding=0):
    "Return a tile subsurface"
    w, h = srf.get_size()
    n = cols * rows
    if tile < 0: tile += n
    if tile >= n or tile < 0: raise IndexError("tile index is out of range")
    w = w // cols
    h = h // rows
    x = tile % cols * w + padding
    y = tile // cols * h + padding
    padding *= 2
    return srf.subsurface(x, y, w - padding, h - padding)

def ondrag(gr, ev):
    "Move a Graphic instance while dragging"
    gr.pos = sigma(gr.pos, ev.rel)

def dragDrop(gr, ev):
    "Drag a Graphic, possibly into a different canvas"
    gr.hoverable = False

# Path: sc8pr/geom.py
# def sigma(*args):
#     "Sum one or more vectors"
#     return tuple(sum(x[i] for x in args) for i in range(len(args[0])))
# 
# def delta(v2, v1=None, mag=None):
#     "v2 - v1, rescaled to specified magnitude"
#     if v1:
#         x = v2[0] - v1[0]
#         y = v2[1] - v1[1]
#     else: x, y = v2
#     if mag is not None:
#         r = hypot(x, y)
#         if r:
#             mag /= r
#             x *= mag
#             y *= mag
#     return x, y


# Path: sc8pr/util.py
import sys, pygame
from random import randint
from traceback import format_exc
from zipfile import ZipFile
from pathlib import Path
from sc8pr.geom import sigma, delta

    else: x, y, w, h = r
    ver = (x, y, weight, h), (x + w - weight, y, weight, h)
    w -= 2 * weight
    x += weight
    hor = (x, y, w, weight), (x, y + h - weight, w, weight)
    clip = srf.get_clip()
    sides = [pygame.Rect(s).clip(clip) for s in (ver + hor)]
    for s in sides:
        if s: srf.subsurface(s).fill(color)

def tile(srf, tile=0, cols=1, rows=1, padding=0):
    "Return a tile subsurface"
    w, h = srf.get_size()
    n = cols * rows
    if tile < 0: tile += n
    if tile >= n or tile < 0: raise IndexError("tile index is out of range")
    w = w // cols
    h = h // rows
    x = tile % cols * w + padding
    y = tile // cols * h + padding
    padding *= 2
    return srf.subsurface(x, y, w - padding, h - padding)

def ondrag(gr, ev):
    "Move a Graphic instance while dragging"
    gr.pos = sigma(gr.pos, ev.rel)

def dragDrop(gr, ev):
    "Drag a Graphic, possibly into a different canvas"
    gr.hoverable = False

    pos = sigma(gr.pos, ev.rel)