def __init__(self, size=(0, 0)):
     self.name = __name__.split('.')[-1]
     self.vertices = [
         Vec2d(size[0] / (-2), size[1] / (-2)),  # bottom left
         Vec2d(size[0] / 2, size[1] / (-2)),  # bottom right
         Vec2d(size[0] / 2, size[1] / 2),  # top right
         Vec2d(size[0] / (-2), size[1] / 2)
     ]  # top left
     self.transformed_vertices = [None] * len(self.vertices)
     self.overlap = False
     self.is_dirty = True
     self.r_squared = (size[0] / 2)**2 + (size[1] / 2)**2
Пример #2
0
    def __init__(self, *args):
        super().__init__(*args)

        self.current_curve = None
        ":type: Curve"

        self.curves_list = []
        ":type: list[Curve]"

        self.detectors = KATA_I
        ":type: list[LineDetector]"

        self.aabb = AABB(Vec2d(130, 1), Vec2d(330, 200))
        self.create_curve()
Пример #3
0
    def tabletEvent(self, event):
        pressure = event.pressure()
        pos = Vec2d.from_qt(event.posF())
        print('Tablet!', pos, pressure)
        if not self.current_curve and pressure == 0:
            print('  ignoring empty dot without pressure')
            return
        self.current_curve.add_point(pos, pressure)
        self.aabb.extend(pos)
        if pressure == 0:
            print('  finished with', len(self.current_curve.points), 'points')
            if len(self.detectors) == len(self.curves_list):
                for curve, detector in zip(self.curves_list, self.detectors):
                    print('detector %s: match %s' % (detector, detector.is_matched_line(curve, self.aabb)))
            self.create_curve()

        event.accept()
        self.update()
Пример #4
0
    def tabletEvent(self, event):
        pressure = event.pressure()
        pos = Vec2d.from_qt(event.posF())
        print('Tablet!', pos, pressure)
        if not self.current_curve and pressure == 0:
            print('  ignoring empty dot without pressure')
            return
        self.current_curve.add_point(pos, pressure)
        self.aabb.extend(pos)
        if pressure == 0:
            print('  finished with', len(self.current_curve.points), 'points')
            if len(self.detectors) == len(self.curves_list):
                for curve, detector in zip(self.curves_list, self.detectors):
                    print(
                        'detector %s: match %s' %
                        (detector, detector.is_matched_line(curve, self.aabb)))
            self.create_curve()

        event.accept()
        self.update()
Пример #5
0
 def create_curve(self):
     self.aabb = AABB(Vec2d(130, 1), Vec2d(330, 200))
     self.current_curve = Curve()
     self.curves_list.append(self.current_curve)
Пример #6
0
 def from_row(self, curve_row):
     self.points = []
     for pos_x, pos_y, pressure in curve_row:
         self.add_point(Vec2d(pos_x, pos_y), pressure)
Пример #7
0
# encoding: utf-8
import ast

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QPainterPath
from PyQt5.QtWidgets import QWidget

from detectors.bbox import AABB
from detectors.line import LineDetector
from utils import Vec2d

KATA_I = [
    LineDetector(3, Vec2d(2, 0), Vec2d(0, 1.5)),
    LineDetector(3, Vec2d(1, 1), Vec2d(1, 2)),
]


class Curve:
    def __init__(self):
        self.points = []
        """list[tuple[Vec2d, float]]"""

    def add_point(self, pos, pressure):
        self.points.append((pos, pressure))

    def paint_to(self, painter):
        if len(self.points) > 1:
            painter.setPen(Qt.red)
            paint_path = QPainterPath()
            paint_path.moveTo(*self.points[0][0])
            for pos, _ in self.points[1:]:
Пример #8
0
def normalize_vec(v, aabb):
    x = aabb.x
    y = aabb.y
    w = aabb.w
    h = aabb.h
    return Vec2d((v.x - x)/w, (v.y - y)/h)
Пример #9
0
def denormalize_vec(v, aabb):
    x = aabb.x
    y = aabb.y
    w = aabb.w
    h = aabb.h
    return Vec2d(v.x*w + x, v.y*h + y)
 def __init__(self, vel=Vec2d(0, 0), force=Vec2d(0, 0), mass=None):
     self.vel = vel
     self.force = force
     self.inverse_mass = 0
     if mass:
         self.inverse_mass = 1 / mass
 def __init__(self, pos=Vec2d(0, 0), orient=Vec2d(1, 0), z=0):
     self.orient = orient
     self.pos = pos
     self.z = z
Пример #12
0
def _make_aabb(grid_size, cell_indices):
    return AABB(*[Vec2d(*[(i + d) / grid_size for i in cell_indices]) for d in range(2)])