Esempio n. 1
0
    def draw(self, dt, display):
        super().draw(dt, display)

        for i in range(1, 3):
            Line(
                self.position - Point((i - 1) * self.radius,
                                      abs(i - 2) * self.radius),
                self.position + Point((i - 1) * self.radius,
                                      abs(i - 2) * self.radius), self.color,
                self.stored_thickness).draw(dt, display)
Esempio n. 2
0
    def __init__(self):
        circle = CrossedCircle(Point(150, 150), 150, (255, ) * 3, (0, ) * 3, 3)
        super().__init__(circle.diameter + 100, circle.diameter + 100)
        pygame.display.set_caption(self.TITLE, self.ICONTITLE)

        mouse_args = (
            (255, 0, 255),
            3,
            circle.radius,
            lambda: circle.pos,
            lambda: Point(*pygame.mouse.get_pos()),
        )

        self.mouse_pointing_line = FixedLengthLine(*mouse_args)

        self.crossed_circle = circle
        self.font = pygame.font.SysFont("monospace", 15)

        text_supplier = lambda: angle_text(
            self.mouse_pointing_line.angle_in_rads, self.delta_pos_for_label())
        self.angle_label = Label(Point(30, 30 + circle.diameter), self.font,
                                 (50, 255, 100), text_supplier)

        trig_funcs_supp = lambda: trig_fucs_text(
            self.mouse_pointing_line.angle_in_rads, self.delta_pos_for_label())
        self.trig_funcs_label = Label(Point(30,
                                            60 + circle.diameter), self.font,
                                      (50, 255, 100), trig_funcs_supp)

        self.updatables = [
            self.mouse_pointing_line, self.angle_label, self.trig_funcs_label
        ]

        self.drawables = [
            DisplayClearer((0, ) * 3), self.crossed_circle,
            self.mouse_pointing_line, self.angle_label, self.trig_funcs_label
        ]
Esempio n. 3
0
def demo():
    width = 800
    height = 600
    border = 20

    x1, y1, x2, y2 = border, border, width - border, height - border

    rect = Rectangle(x1, y1, x2, y2)
    qt = QuadTree(rect, 4)

    for _ in range(1000):
        qt.insert(Point(random.randrange(x1, x2), random.randrange(y1, y2)))

    print('data ', qt.getLoadAndCapacity())

    win = GraphWin('Quadtree', width, height, autoflush=False)
    print(qt)
    qt.show(win)
    mrect = None

    while True:
        mouse = win.checkMouse()

        if mouse is not None:
            if mouse.x >= border and mouse.x <= width - border and mouse.y >= border and mouse.y <= width - border:
                for item in win.items[:]:
                    item.undraw()

                mrect = gRectangle(gPoint(mouse.x - border, mouse.y - border),
                                   gPoint(mouse.x + border, mouse.y + border))
                mrect.draw(win)

                boundary = Rectangle(mrect.p1.getX(), mrect.p1.getY(),
                                     mrect.p2.getX(), mrect.p2.getY())

                hits = qt.query(boundary)

                # ToDo: optimize to send list instead, because the points are close
                for hit in hits:
                    qt.remove(hit)

                qt.show(win)
                win.update()

    win.close()
    def test_creation(self):
        color = None
        thickness = None
        length = 5
        spos_supp = lambda: Point(0, 0)
        epos_supp = lambda: Point(5, 0)
        line = subject.FixedLengthLine(color, thickness, length, spos_supp,
                                       epos_supp)

        line.update()
        self.assertEqual(line.length, 5)
        self.assertEqual(line.starting_position, Point(0, 0))
        self.assertEqual(line.ending_position, Point(5, 0))

        line.epos_supp = lambda: Point(3, 0)
        line.update()
        self.assertEqual(line.length, 5)
        self.assertEqual(line.starting_position, Point(0, 0))
        self.assertNotEqual(line.ending_position, Point(0, 0))
 def fix_length(self):
     delta_pos = self.ending_position - self.starting_position
     alpha = self.angle_in_rads
     x = self.length * math.cos(alpha)
     y = self.length * math.sin(alpha)
     self.ending_position = Point(x, y) + self.starting_position
Esempio n. 6
0
 def setUp(self):
     self.rectangle1 = Rectangle(100, 100, 200, 200)
     self.rectangle2 = Rectangle(150, 150, 250, 250)
     self.rectangle3 = Rectangle(0, 0, 50, 50)
     self.point = Point(150, 150)
Esempio n. 7
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('aircrafts_data',
                    'aircraft_code',
                    existing_type=sa.CHAR(length=3),
                    comment=None,
                    existing_comment='Aircraft code, IATA')
    op.alter_column('aircrafts_data',
                    'model',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    comment=None,
                    existing_comment='Aircraft model',
                    existing_nullable=False)
    op.alter_column('aircrafts_data',
                    'rrange',
                    existing_type=sa.INTEGER(),
                    comment=None,
                    existing_comment='Maximal flying distance, km',
                    existing_nullable=False)
    op.drop_table_comment('aircrafts_data',
                          existing_comment='Aircrafts (internal data)',
                          schema=None)
    op.alter_column('airports_data',
                    'airport_code',
                    existing_type=sa.CHAR(length=3),
                    comment=None,
                    existing_comment='Airport code')
    op.alter_column('airports_data',
                    'airport_name',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    comment=None,
                    existing_comment='Airport name',
                    existing_nullable=False)
    op.alter_column('airports_data',
                    'city',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    comment=None,
                    existing_comment='City',
                    existing_nullable=False)
    op.alter_column(
        'airports_data',
        'coordinates',
        existing_type=Point(),
        comment=None,
        existing_comment='Airport coordinates (longitude and latitude)',
        existing_nullable=False)
    op.alter_column('airports_data',
                    'timezone',
                    existing_type=sa.TEXT(),
                    comment=None,
                    existing_comment='Airport time zone',
                    existing_nullable=False)
    op.drop_table_comment('airports_data',
                          existing_comment='Airports (internal data)',
                          schema=None)
    op.alter_column('boarding_passes',
                    'boarding_no',
                    existing_type=sa.INTEGER(),
                    comment=None,
                    existing_comment='Boarding pass number',
                    existing_nullable=False)
    op.alter_column('boarding_passes',
                    'flight_id',
                    existing_type=sa.INTEGER(),
                    comment=None,
                    existing_comment='Flight ID')
    op.alter_column('boarding_passes',
                    'seat_no',
                    existing_type=sa.VARCHAR(length=4),
                    comment=None,
                    existing_comment='Seat number',
                    existing_nullable=False)
    op.alter_column('boarding_passes',
                    'ticket_no',
                    existing_type=sa.CHAR(length=13),
                    comment=None,
                    existing_comment='Ticket number')
    op.drop_table_comment('boarding_passes',
                          existing_comment='Boarding passes',
                          schema=None)
    op.alter_column('bookings',
                    'book_date',
                    existing_type=postgresql.TIMESTAMP(timezone=True),
                    comment=None,
                    existing_comment='Booking date',
                    existing_nullable=False)
    op.alter_column('bookings',
                    'book_ref',
                    existing_type=sa.CHAR(length=6),
                    comment=None,
                    existing_comment='Booking number')
    op.alter_column('bookings',
                    'total_amount',
                    existing_type=sa.NUMERIC(precision=10, scale=2),
                    comment=None,
                    existing_comment='Total booking cost',
                    existing_nullable=False)
    op.drop_table_comment('bookings', existing_comment='Bookings', schema=None)
    op.alter_column('flights',
                    'actual_arrival',
                    existing_type=postgresql.TIMESTAMP(timezone=True),
                    comment=None,
                    existing_comment='Actual arrival time',
                    existing_nullable=True)
    op.alter_column('flights',
                    'actual_departure',
                    existing_type=postgresql.TIMESTAMP(timezone=True),
                    comment=None,
                    existing_comment='Actual departure time',
                    existing_nullable=True)
    op.alter_column('flights',
                    'aircraft_code',
                    existing_type=sa.CHAR(length=3),
                    comment=None,
                    existing_comment='Aircraft code, IATA',
                    existing_nullable=False)
    op.alter_column('flights',
                    'arrival_airport',
                    existing_type=sa.CHAR(length=3),
                    comment=None,
                    existing_comment='Airport of arrival',
                    existing_nullable=False)
    op.alter_column('flights',
                    'departure_airport',
                    existing_type=sa.CHAR(length=3),
                    comment=None,
                    existing_comment='Airport of departure',
                    existing_nullable=False)
    op.alter_column('flights',
                    'flight_id',
                    existing_type=sa.INTEGER(),
                    comment=None,
                    existing_comment='Flight ID',
                    autoincrement=True)
    op.alter_column('flights',
                    'flight_no',
                    existing_type=sa.CHAR(length=6),
                    comment=None,
                    existing_comment='Flight number',
                    existing_nullable=False)
    op.alter_column('flights',
                    'scheduled_arrival',
                    existing_type=postgresql.TIMESTAMP(timezone=True),
                    comment=None,
                    existing_comment='Scheduled arrival time',
                    existing_nullable=False)
    op.alter_column('flights',
                    'scheduled_departure',
                    existing_type=postgresql.TIMESTAMP(timezone=True),
                    comment=None,
                    existing_comment='Scheduled departure time',
                    existing_nullable=False)
    op.alter_column('flights',
                    'status',
                    existing_type=sa.VARCHAR(length=20),
                    comment=None,
                    existing_comment='Flight status',
                    existing_nullable=False)
    op.drop_table_comment('flights', existing_comment='Flights', schema=None)
    op.alter_column('seats',
                    'aircraft_code',
                    existing_type=sa.CHAR(length=3),
                    comment=None,
                    existing_comment='Aircraft code, IATA')
    op.alter_column('seats',
                    'fare_conditions',
                    existing_type=sa.VARCHAR(length=10),
                    comment=None,
                    existing_comment='Travel class',
                    existing_nullable=False)
    op.alter_column('seats',
                    'seat_no',
                    existing_type=sa.VARCHAR(length=4),
                    comment=None,
                    existing_comment='Seat number')
    op.drop_constraint('seats_aircraft_code_fkey', 'seats', type_='foreignkey')
    op.create_foreign_key('boarding_passes_ticket_no_fkey', 'seats',
                          'aircrafts_data', ['aircraft_code'],
                          ['aircraft_code'])
    op.drop_table_comment('seats', existing_comment='Seats', schema=None)
    op.alter_column('ticket_flights',
                    'amount',
                    existing_type=sa.NUMERIC(precision=10, scale=2),
                    comment=None,
                    existing_comment='Travel cost',
                    existing_nullable=False)
    op.alter_column('ticket_flights',
                    'fare_conditions',
                    existing_type=sa.VARCHAR(length=10),
                    comment=None,
                    existing_comment='Travel class',
                    existing_nullable=False)
    op.alter_column('ticket_flights',
                    'flight_id',
                    existing_type=sa.INTEGER(),
                    comment=None,
                    existing_comment='Flight ID')
    op.alter_column('ticket_flights',
                    'ticket_no',
                    existing_type=sa.CHAR(length=13),
                    comment=None,
                    existing_comment='Ticket number')
    op.drop_table_comment('ticket_flights',
                          existing_comment='Flight segment',
                          schema=None)
    op.alter_column('tickets',
                    'book_ref',
                    existing_type=sa.CHAR(length=6),
                    comment=None,
                    existing_comment='Booking number',
                    existing_nullable=False)
    op.alter_column('tickets',
                    'contact_data',
                    existing_type=postgresql.JSONB(astext_type=sa.Text()),
                    comment=None,
                    existing_comment='Passenger contact information',
                    existing_nullable=True)
    op.alter_column('tickets',
                    'passenger_id',
                    existing_type=sa.VARCHAR(length=20),
                    comment=None,
                    existing_comment='Passenger ID',
                    existing_nullable=False)
    op.alter_column('tickets',
                    'passenger_name',
                    existing_type=sa.TEXT(),
                    comment=None,
                    existing_comment='Passenger name',
                    existing_nullable=False)
    op.alter_column('tickets',
                    'ticket_no',
                    existing_type=sa.CHAR(length=13),
                    comment=None,
                    existing_comment='Ticket number')
    op.drop_table_comment('tickets', existing_comment='Tickets', schema=None)