Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorio intersection functions #9753

Closed
wants to merge 9 commits into from

Conversation

FoamyGuy
Copy link
Collaborator

Replaces: #9483 that branch accidentally got some unintended changes to files that were unrelated and I could not figure out how to properly revert those changes so I've just made a new branch and PR.

This adds functions to vectorio for testing intersection between the 3 different supported shapes.

Testing was performed on the PyGamer and Pimoroni PicoSystem with this test code and some variations of it to call the different various functions inside the main loop.

import time

import board
import displayio
import vectorio
from game_controls import game_controls

display = board.DISPLAY

main_group = displayio.Group()

palette = displayio.Palette(4)
palette[0] = 0xffffff
palette[1] = 0x125690
palette[2] = 0xbb4444
palette[3] = 0x44bb44

# static_rect = vectorio.Rectangle(pixel_shader=palette, width=40, height=30, x=55, y=45)
# main_group.append(static_rect)

static_polygon = vectorio.Polygon(pixel_shader=palette, points=[
    (-25, -25), (25, -25),
    (45, 25), (-45, 25)
], x=display.width // 2, y=display.height // 2)

moving_rect = vectorio.Rectangle(pixel_shader=palette, width=10, height=10, x=0, y=0)
moving_rect.color_index = 1
main_group.append(moving_rect)

# moving_circle = vectorio.Circle(pixel_shader=palette, radius=7, x=15, y=15)
# moving_circle.color_index = 1
# main_group.append(moving_circle)

display.root_group = main_group
while True:
    cur_state = game_controls.button

    if (cur_state['up']):
        moving_rect.y -= 1
        # moving_circle.y -= 1

    if (cur_state['down']):
        moving_rect.y += 1
        # moving_circle.y += 1

    if (cur_state['right']):
        moving_rect.x += 1
        # moving_circle.x += 1

    if (cur_state['left']):
        moving_rect.x -= 1
        # moving_circle.x -= 1
        
    if vectorio.polygon_rectangle_intersects(
            static_polygon.points, static_polygon.x, static_polygon.y,
            moving_rect.x, moving_rect.y, moving_rect.width, moving_rect.height):

        static_polygon.color_index = 3
    else:
        static_polygon.color_index = 2

    time.sleep(0.01)

@FoamyGuy FoamyGuy mentioned this pull request Oct 23, 2024
@FoamyGuy
Copy link
Collaborator Author

The latest commits update the new code to work under the unix port and add an initial very basic test of the intersection functionality. I've also disabled vectorio on a few more devices which overflowed the build since the previous time I worked on this.

@dhalbert
Copy link
Collaborator

@FoamyGuy What are your thoughts about this for now? It does require turning off vectorio on a number of boards.

@FoamyGuy
Copy link
Collaborator Author

@dhalbert I would still love to have access to at least the most basic of these intersection checks on devices where it will fit. I'd like to use them to make simple arcade / physics style games. A version of breakout was my initial reason for starting this effort.

It is a shame that it has overflowed so many boards, in particular the m4 express devices would be great to have. I even did a good chunk of the testing on some of them but a few languages overflowed.

I would propose the following options:

  • Pare this down to just the basics either just circle x rect, or maybe the 4 permutations of circle and rect. Cutting out the Polygon tests will remove a good chunk of the code and some helper functions that were implemented for them specifically iirc.
  • Move it into a different module instead of vectorio that can be disabled on boards where it won't fit separately. That way they still get drawing capabilities and don't lose anything they currently have access to. I have pondered down this train of thought a few times. I searched around for some analogous module in CPython that I could implement but never ended up finding one that seemed like a good fit.

All of that being said I do understand if it's too much firmware space and too niche of a use-case.

@dhalbert dhalbert marked this pull request as draft November 19, 2024 22:41
@FoamyGuy
Copy link
Collaborator Author

FoamyGuy commented Dec 2, 2024

I will close this for now. In #9851 I added only a few lines to to vectorio fix an off by 1 issue and even that overflowed a few devices. Seeing that, I'm afraid even a pared down version of this is likely going to be to big for some of these. If I return to this I'll plan to move it to it's own module so that it can be disabled independently from the rest of vectorio.

@FoamyGuy FoamyGuy closed this Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants