Pixi.js: More basic Math for PIXI [SUGGEST]

Created on 18 Sep 2019  ·  8Comments  ·  Source: pixijs/pixi.js

I do not know if the subject has already been discussed, but it would be great to see a little more native math method for pixijs.

Some basic feature like substrac, add ,merge divide, multiply.

Example some useful case.
instead of this

var a = from.getGlobalPosition();
var b = target.getGlobalPosition();
var ab = {x:a.x-b.x,y:a.y-b.y};

just one line readable.

var diff  = from.getGlobalPosition().substrac( target.getGlobalPosition() );

is this are already thinking or in todo list of your team? Maybe low priority ?

Stale

Most helpful comment

Recently, we introduced a package called @pixi/unsafe-eval, which supports environments that block new Function via CSP. While this package lives in the monorepo, it is _not_ included in the default bundles (pixi.js & pixi.js-legacy), nor is it a dependency of any of the other sub-packages.

I believe we could add new math package, possibly called @pixi/math-extras, which would not be a default bundled package (like unsafe-eval), but devs could opt-in to a bunch of math stuff that is intentionally excluded by default to avoid bloat. I'd definitely be open to this. I don't think it's a huge overhead, because many of the math functions that have been proposed are pretty straightforward and unlikely to change.

Clearly there's a desire to have a first-class plugin for common math utilities and no one has stepped up to manage/create their own project.

Thoughts?

All 8 comments

This has come up a few times:

And each time we basically landed on "we don't want to support a math library that pixi doesn't need".

If you want to create subtract/add functions that operate on pixi matrix objects, you can do that as a function outside the class (subtract(a, b) instead of a.subtract(b)). Couple that with the fact that people are going to use their own math libs anyway, means I don't see a strong reason for putting it in pixi itself

What I've been more interested in as been a way for users to inject their own math lib into pixi, since everyone will have their own anyway.

thank for your answer,
i don't like subtract(a, b) this need to be used from global, i prefer local call.

I asked to know if it was worth it for me to overload with my own methods, which I will did.
i just need basic math for pixi.Point, nothing really advance.

Recently, we introduced a package called @pixi/unsafe-eval, which supports environments that block new Function via CSP. While this package lives in the monorepo, it is _not_ included in the default bundles (pixi.js & pixi.js-legacy), nor is it a dependency of any of the other sub-packages.

I believe we could add new math package, possibly called @pixi/math-extras, which would not be a default bundled package (like unsafe-eval), but devs could opt-in to a bunch of math stuff that is intentionally excluded by default to avoid bloat. I'd definitely be open to this. I don't think it's a huge overhead, because many of the math functions that have been proposed are pretty straightforward and unlikely to change.

Clearly there's a desire to have a first-class plugin for common math utilities and no one has stepped up to manage/create their own project.

Thoughts?

@pixi/math-extras concept sound very good for me!
I understand pixi is mostly thinking for be optimized in a web browser environment and avoid surcharge all thing.
for me, save some KO or Mo in memory does not matter to my desktop project.
For sure it would be wonderful to see one day a math plugin PIXI-Math thats can manage and add a lot of cool math method for all PIXI class needed.
ObservablePoint,Matrix,Point...
I do not know all objects that handle values in pixi, but in my case a mostly use Point local and global for easy animations.

This would be low priority for the core team at the moment, because we have other projects that are currently in-flight. If someone wants to take up this task (maybe you @djmisterjon!), I would be happy to work with you to get the package working with the build/publishing system.

sure why not, I'll come back to you maybe next week, I'll be happy to start a basic concept and idea.
Especially if it can be useful for my PIXI project, I'm also a little overloaded with work.
I do not master easily all deployment technologie like you, but I can easily lay something good. :)

If you're looking for an example package to imitate, check out the mixin-* packages or something like canvas-particles. These extend the prototype of existing classes. Also, check out those old issues @englercj posted. They have some great suggestions for Rectangle, Point, etc.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings