Skip to content

would you consider changing the API of segseg to reduce memory garbage? #2

@mreinstein

Description

@mreinstein

Proposals:

Have an out parameter somewhere in the argument list that gets the intersection point copied into it. e.g.,

function segseg (out, pos1, pos2, pos3, pos4) { ... } // returns boolean

I'd also propose using gl-matrix's vec2 convention (an array of 2 numbers): [ x, y ]

benefits:

  • not generating a new array object every time this function is invoked will result in less garbage collection. (not a big deal for a few calls to this function, but for a game/simulation which can call this thousands of times per second this can make a big difference
  • making the return object of segseg always a boolean rather than a mixed type makes it easier for the vm to optimize
  • this format of having an out field first matches very closely what gl-matrix does, moving us torwards slightly better interoperability
  • easier to read

cons:

  • forms an opinion on vec2/point representation on behalf of the user (the [ x, y ] vs { x, y } data representation debate)
  • breaking API change requiring major version bump

thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions