Code Monkey home page Code Monkey logo

Comments (5)

novialriptide avatar novialriptide commented on May 22, 2024

I thought we settled for using directions?

from pygame-geometry.

itzpr3d4t0r avatar itzpr3d4t0r commented on May 22, 2024

I don't like this as it's sub-optimal to go trough 2 lists just to get the origin and end positions so this

@overload
def multiraycast(
    origin_positions: Sequence[Coordinate],
    end_positions: Sequence[Coordinate],
    colliders: Sequence[Rect, Circle, Line],
) -> Sequence[Optional[Tuple[float, float]]]: ...

Is a No-No for me.

I was thinking of something more like the pygame.Surface.blits() function, in that you pass it a list of containers that represent the surface, where you wanna blit it etc.

Basically i was thinking of a very compact approach that accepts a list of tuples that represent a ray, and that ray can be interpreted in various ways

@overload
def multiraycast(
    rays: Sequence[Ray],
    colliders: Sequence[Rect, Circle, Line],
) -> Sequence[Optional[Tuple[float, float]]]: ...

Where Ray can be either of the following:

  • Tuple (origin_pos, end_pos, max_dist)
  • Tuple (origin_pos, angle, max_dist)
  • Tuple (origin_pos, direction, max_dist)
  • Line

Would also be interesting to have an additional parameter that dictates whether None objects are appended to the return list if no intersection is found, so something like:

@overload
def multiraycast(
    rays: Sequence[Ray],
    colliders: Sequence[Rect, Circle, Line],
    include_miss: bool,
) -> Sequence[Optional[Tuple[float, float]]]: ...

And also, given that the majority of the times people will either use a batch of rays with infinite max_dist or all with the same max_dist, could be an efficiency fix to add another parameter that applies the same max_distance to each ray so that you don't have to specify a max_dist for each ray and we don't need to exract them:

@overload
def multiraycast(
    rays: Sequence[Ray],
    colliders: Sequence[Rect, Circle, Line],
    include_miss: bool,
    global_max_dist: float,
) -> Sequence[Optional[Tuple[float, float]]]: ...

And with that, given that it's possible that someone might want to set global_max_dist and not include_miss, i'd suggest we make this one a kwargs function.

from pygame-geometry.

novialriptide avatar novialriptide commented on May 22, 2024

It seems that @itzpr3d4t0r has the right idea about optimizing this even further. I just want to be clear that we will not be creating a new Ray object.

I think adding None to the returned list is a good idea so that users can index the results better, I don't see how else they'll be able to do so.

from pygame-geometry.

novialriptide avatar novialriptide commented on May 22, 2024

This also must not be worked on until #127 is fixed and #126 is merged.

from pygame-geometry.

itzpr3d4t0r avatar itzpr3d4t0r commented on May 22, 2024

I propose to work on this one after #126 is merged, which is pretty close anyway...

from pygame-geometry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.