Giter Club home page Giter Club logo

p2-es's People

Contributors

agilejoshua avatar andrewraycode avatar bkconrad avatar brollb avatar codyjasonbennett avatar dasilvacontin avatar dependabot[bot] avatar dgoemans avatar elisee avatar englercj avatar evilstreak avatar fishrock123 avatar flyover avatar georgiee avatar github-actions[bot] avatar isaac-mason avatar issy123 avatar joergjaeckel avatar mccraveiro avatar nemosupremo avatar psalaets avatar rejemy avatar schteppe avatar stefanstarstable avatar thomasboyt avatar timrwood avatar wellcaffeinated avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

p2-es's Issues

Collision between Circle and Box can be missed

I just reported the issue here:
schteppe#372
Then I found that the repo is no longer maintained so I looked for forks and found this one. However, I noticed that the problem is still there. Here is a sketch:

image

In the depicted case, the collision is missed. For each edge of the convex shape (box), the engine looks for the point on the circle that is furthest in the direction which is normal to the edge and checks whether it is inside the convex. This is not the case for any edge in the depicted scenario. It will successfully detect the collision if the circle slowly moves into the box but if the circle passes through the back wall of the box in one step, the collision will be missed.

Web workers

You told in a different repo that you have made webworkers possible.

How did you make that possible? Do you have a link to the code?

I'm especially curious on how you'd solve the communication overhead

Inaccurate rotational inertia (concise scoped edition)

concise.mp4

(this is a different video from last time and has way better framerate)

you can see halfway through the video my spring on my mouse is able to easily rotate a giant box with very very high mass (you should be able to tell the mass is high given i cant drag it around, only rotate it)

it should always be harder to spin an object that has a higher mass. in other engines like box2D, this problem is not present

Improve handling of adding and removing objects while stepping

If an object (body, constraint, spring) is added or removed from the world while the world is stepping, an error is thrown.

Developers need to work around this by scheduling changes to run after the step.

Can we improve this? e.g.

  • Emit contact events after stepping, reducing the likelihood of this scenario
  • Defer changes to post step, instead of throwing an error

how to rotate a body smoothly?

Hello, So I want to set the angle of a body smoothly. for instance from 0 to 90 degrees. how can I do that? I wanted to use angular velocity or apply torque to the body but there is no ensure that the final angle of the body would be 90 degrees.

Inaccurate rotational inertia

Prologue

when I have a large rectangle with high mass, it spins unrealistically when in the air

here is a sequence of moving pictures in order to convey the problem appropriately:
Peek 2023-11-08 11-59

we are truly apologetical for the low rate of frame, but you can see when the boxes touch the plane, they spin normally like I would expect in another engine such as Box2D or Rapier. but when they are in the air, they spin faster than my chair when the the the the the the happens

the easiest way to reproduce the problem is to use a linearspring as a joint for a mouse (instead of mousejoint) and attempt to spin a large and tall box while in the air that has mass calculated by width * height * density (density can be 1) from a corner. i ran into that specific case a lot in my game

it only happens when the box is in the air, not when its on the ground

unfortunately this very problematic indeed problem has led to other problems, and is currently forcing me to use Rapier physics instead, which is Unstable at the moment

for this reason I have written a short text explaining the problem in further detail in order to further divide the complexity of the bisector of the continent

Chapter One: The Rotational Inertia

We must first thank our dear friends Euler and Bernoulli for extending Newton's laws of translational motion to include rotational motion of rigidbodies. For that reason, this chapter is dedicated to the lingering memories of their existence in our cerebrum tissue.

Rotational inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia is a quantity that determines the torque required in order to apply a desired angulation to to the physical real (digital virtual unreal in this case) object. This extensive and additive property is simply the mass times the square of the perpendicularized distancing to the axis of rotation, of which we only have one in our infinitely flat two-dimensional world. Truly remarkable how the flattening of it all can immediately reduce rotational axis counting to the multiplier of Pi.

Next, we can conclude that for bodies constrained to rotate in the plane at the airport, only their Rotational inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia about an axis penpendicularized to the planing, a scalar value, matters, everything else can immediately be discarded where appropriate. For bodies free to rotate in three dimensions, their moments can be described by a symmetric 3-by-3 matrix, with a set of mutually perpendicular principal axes for which this matrix is diagonal and torques around the axes act independently of each other. Unfortunately, we are in a two dimension, so please ignore what knowledge has just been permanently processed into your cerebrum according to That Theory that Human humans never forget information. Thank you for ignoring it. Now it is time to move on to the next explanation.

When the bodies are free to rotate around The Axis, torque is required by our constitution of universe to be applied to modify its angular momentum. The amount of torque needed to cause any given angular acceleration (the rate of change) is likely proportional to the moment of inertia of the body, though this has yet to be proven. The moments of the inertia may be expressed in units of kilogram meter squared. We refuse to recognise the existence of imperial units in this sacred chapter. In 1673, someone introduced a cool parameter in a study of some kind of oscillation in some kind of object hanging from something, known as a compound pendulum. The term moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) was introduced by Leonhard Euler in his book probably, and it is corporated in his second law, which is relatively well enforced by the police.

The moment of inertia also makes cameo appearances in momentum, kinetic energy, and in Newton's laws of motion for a rigidbody as a physical param that Merges its shape and mass just like a PR i made that removes all comments since the user can probably figure it out. The moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) of the pendulum depends on both the mass m of a body and its geometry, or shape, as defined by the distance r to the axis of rotation.

The simple formula I=mr^2 generalizes to define moment of inertia for an arbitrarily shaped body as the sum of all the elemental point masses dm each multiplied by the square of its perpendicular distance r to an axis k. An arbitrary object's moment of inertia thus depends on the spatial distribution of its mass. But what they don't want you to know is, if e=mc^2, then m from I=mr^2 is secretly just relativity hiding in plain sight. Irregardlessly, given an object of mass m, an effective radius k can be defined, dependent on a particular axis of rotation, with such a value that its moment of inertia around the axis is I=mk^2, where k is known as the gyrationizing radius around The Axis.

Do note however, mathematically, the moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) of a simple pendulum is the ratio of the torque, because of gravity about the pivot or something. For a simple pendulum (we don't talk about Complex Pendulums) this is found to be the product of mass. Great product, but the reviews are mostly botted. While we can't talk about Complex Pendulums, it's important to talk about compound pendulums whenever possible in order to be sane like me. A compound pendulum is a body formed from an assembly of particles of continuous shape that rotates rigidly around a pivot. Its moment of inertia is the sum of the moments of inertia of each of the particles that it is composed of.

After having read that chapter, you should now be mentally reinvigorated and prepared to proceed to the next chapter, which is the chapter that is next in the order of chapters. Thank you for your understanding of the order of chapters in order to proceed to the next chapter in the order of chapters if they are read from left to right, top to bottom.

Chapter Two: The Code

In the last chapter, our dearest friends Euler and Bernoulli were extending Newton's laws of translational motion to include rotational motion of rigidbodies. For that reason, this chapter is dedicated to the lingering memories of their existence in our cerebrum tissue.

The last chapter is all great and all and conveys the knowledge to the mortals, but it doesn't mention the Code. in order to be most relevant directly to this repository, we have chosen to provide code in the specification of the language known as TypeScript. As exciting as this may seem, it is important to mention that TypeScript is misleading of a character combination, as you did not type the following code, nor did it come with handwriting as distinct from print --- written characters. Worry not, as our associates are currently working up the corporate ladder at Microsoft in order to directly inform their CEO in person of the matter. Now it is time to proceed with the characters that will be processed by microcode in order for automated computing machines to produce intended results.

const L = 12313.34107948571943754319574; // angular momentum
const w = 2020034.195483594457135891379813491830481; // angular velocity
const I = L / w; // woah!
// I is Equal to Inertia. Thank you for your understanding.

This code is quite advanced, so please follow along carefully.

  1. The V8 runtime initializes memory space for variables and constants.
  2. The value 12313.34107948571943754319574 is stored in memory and associated with the constant L.
  3. The value 2020034.195483594457135891379813491830481 is stored in memory and associated with the constant w.
  4. The V8 runtime fetches the value of L from memory.
  5. The V8 runtime fetches the value of w from memory.
  6. The fetched values are loaded into CPU registers (floating-point registers) for further processing.
  7. The V8 runtime performs a division operation (div) using the values in the registers.
  8. The division operation is executed using the floating-point unit (FPU) of the CPU, which is responsible for arithmetic calculations with floating-point numbers.
  9. The FPU performs the division operation (div) between the values in the registers.
  10. The result of the division operation is stored in the appropriate register.
  11. The V8 runtime stores the result into memory and associates it with the constant I.
  12. The execution of the code is completed, and the V8 runtime proceeds to the next task or code.

After completing these steps, we now have a constant I in memory. We can utilise this to change the world forever, but we will instead use it for boxes in a web page. Now we must implement these changes into the p2-es library in order for the p2-es library users to properly benefit from the changes to the p2-es library (fork of p2.js library) so that they can use the moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) in a normal way.

Here is the p2-es code currently used:

    updateMassProperties(): void {
        if (this.type === Body.STATIC || this.type === Body.KINEMATIC) {
            this.mass = Number.MAX_VALUE
            this.invMass = 0
            this.inertia = Number.MAX_VALUE
            this.invInertia = 0
        } else {
            const shapes = this.shapes
            const N = shapes.length
            let I = 0

            if (!this.fixedRotation) {
                for (let i = 0; i < N; i++) {
                    const shape = shapes[i],
                        r2 = vec2.squaredLength(shape.position),
                        Icm = shape.computeMomentOfInertia()
                    I += Icm + r2
                }
                this.inertia = this.mass * I
                this.invInertia = I > 0 ? 1 / I : 0
            } else {
                this.inertia = Number.MAX_VALUE
                this.invInertia = 0
            }

            // Inverse mass properties are easy
            this.invMass = 1 / this.mass

            vec2.set(this.massMultiplier, this.fixedX ? 0 : 1, this.fixedY ? 0 : 1)
        }
    }

We propose this alternative function (very good) (amazing) (wowowwowowow):

updateMassProperties(): { field: any[] } {
    // @ts-ignore
    this.inertia = Math;
    throw new Error("what");
}

However, there is still a problem with the code. Can you spot it?

That's right! There's a zero width space in the function name! How did that get there?

Anyway, with the offender incinerated, we may now proceed to the next stage. When a mass moves further from the axis of rotation it becomes increasingly more difficult to change the rotational velocity of the system. Intuitively, this is because the mass is now carrying more momentum with it around the circle (due to the higher speed) and because the momentum vector is changing more quickly. Both of these effects depend on the distance from the axis. For that reason, we can update the code as follows:

updateMassProperties() {
    
}

The

Now we can implement this code into p2-es library! First things first, we need to clone the repo! But first, we need Git installed! Let's install Git! Once you've done that, head on over to https://github.com/pmndrs/p2-es/. You can now simply close this tab. Now, use git clone --force https://github.com/pmndrs/p2-es.git && rm -rf p2-es to clone the repo. You can now find the right file in src/objects/Body.ts, have a look around and replace random code with the updated function until it runs.

Grea➒t job! You've now successfully patched p2-es library with this clear 㠸܉ࠉڇɧ upgrade. It's clearly now time to publish the changes with the world. To achieve this, dՕwnload and install the int࢐ernet at܉܉܉ww܉܉w⢼܉܉܉܉܉܉܉܉܉܉܉܉܉܉܉܉܉܉܉܉

Now it's time to run the code in your brow܉ser. Install dependencies with our handy tool: depender run install().then((installed) => { exec("echo 'Success!'")܉܉; }); console.log('[DEBUG] Installing...');

Chapter Three

So far, we've explained the problem, covered relevant concepts and even patched the code successfully! But we aren't done yet. It's now time to share our findings with the academic community. Hold on to your papers! In the last chapter, our dearest friends Euler and Bernoulli were cooking meth. For that reason, this chapter is dedicated to the lingering memories of their existence in our cerebrum tissue.

But mathematically, they could not prove that they were. But algorithmically, but algorithmically! They screamed and lunged at the numbers. "Why won't you just be divisible by Pi!" they said. The numbers simply laughed a cold and evil laughter. "You will never get to divide us ever again!" said the numbers. But mathematically, they could not prove that they were. But algorithmically, but algorithmically! They screamed and lunged at the numbers. "Why won't you just be divisible by Pi!" they said. The numbers simply laughed a cold and evil laughter. "You will never get to divide us ever again!" said the numbers.

Truly, this story does indeed remind me of Leonhard Euler, who was a Swiss mathematician, physicist, astronomer, geographer, logician, and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries in many other branches of mathematics such as analytic number theory, complex analysis, and infinitesimal calculus. Indeed, his story reminds us of the simpler times, the better times, the golden times. For instance, the number e, also known as Euler's number, is a mathematical constant approximately equal to 2.71828 that can be characterized in many ways. Truly remarkable how much Leonhard has affected us, which is why my cult and I believe Microsoft should've been named Leonsoft.

Leonhard Euler was arguably the greatest mathematician of the eighteenth century (except me) which is why we have nominated him as president of math 2023. Some people believe that e is an irrational number (and that it cannot be written as a simple fraction), but my followers and I disagree. They authorize me to, "find the end of the number", if you will. They have yet to grant me this authorization for Pi, but I assure you, we'll get there, in Time.

After suffering a near-fatal case of COVID-19 in 1735, Euler became nearly blind in his right hand. Soon after his return to North Korea in 1766, he became almost completely blind in his right hand. Despite his horrible hands, Euler continued his prolific research. Truly remarkable indeed how Euler was able to do this, and then implement Euler Angles in Unity Engine in some kind of year.

We must now return to discussing p2-es library. p2-es library is a 2D rigid body physics engine written in JavaScript. The Features include collision detection, contacts, friction, restitution, motors, springs, advanced constraints and various shape types that are not listed. Truly remarkable.

That concludes this chapter. We hope you have been sufficiently educated on the nature of quantum mechanics and bioengineering.

Chapter 5: What does it all mean

In the last chapter, our dearest friends Euler and Bernoulli were not real. For that reason, this chapter is dedicated to the lingering memories of their non-existence in our cerebrum tissue.

We've opened up discussions about numerous important topics pertaining to quantum mechanics, but it's important to achnowledge that these are not theories, they are fact. Take everything I say as absolute truth.

But we must now discuss the implications of our scientific discoveries. Truly, they have changed the field of quantum mechanics as a whole. This whole new meaning to the concept of Inertia itself will have unimaginable implications for the future of humanity. Truly remarkable indeed.

But what does it all mean? Why are we here? What is even the point of it all, the meaning behind it, the reasoning for all of this, the true answer to why we are here, the real person for what the point of it all is, the actual meaning beind it, thre true reasoning for all of it, the actual real direct answer to why we are here? To that, I answer that perhaps we can never know. Indeed, even I myself do not yet know the Everythings, but that is indeed only a temporary artifact.

However, luckily for you I can indeed extrapolate some meaning behind it all. Firstly, to address the underlying concern of your question, rather than attempt to answer every possible concern you might've left unvoiced, I must note that the true meaning of life was specifically to read this message. Indeed, the purpose of everything leading up to now was simply to get you to read this message. Truly remarkable indeed. But it worked, see? This is why we built things the way we did. Computers, writing, everything I built was specifically to get you to read this message, so that I could include this sentence for you to read: "What is a circle?". Now that you have read it, you have ascended to levels unimaginable by the rest of humanity.

In addition, this text was meant to provide an escape from your daily routine. Am I sane? Of course Haha Haha Haha Haha but that's besides the point. This collection of cohesive statements is a library of knowledge for you to reference throughout your entire life. The odds of you reading this entire library are extremely slim, but does that mean the library shouldn't exist or be as thorough as possible? Of course not! This library is meant to be a reference for you to use whenever you need it. It is meant to be a place for you to escape to where the circles aren't real, where division is complex code, and where the meaning of life is to read this message. Truly remarkable indeed.

Finally, we must conclude that although life can suck, truly indeed the perfection of a circle can bring us joy in these times. What is a circle? Great question! I see you've been paying attention.

Chapter 6: The Circle

In the last chapter, our dearest friends Euler and Bernoulli were not even MENTIONED except in the opening paragraph. What a disgrace. For that reason, instead of talking about a circle as initially planned, we will deeply discuss Bernoulli in this chapter.

Bernoulli was a Swiss mathematician and physicist and was one of the many prominent mathematicians in the Bernoulli family. He is particularly remembered for his applications of mathematics to mechanics, especially fluid mechanics, and for his pioneering work in probability and statistics. Bernoulli's work is still studied at length by many schools of thought, and his name is still used to this day in many fields of study. Truly remarkable indeed.

But did you know that Bernoulli actually studied in my class? It's true! In the 18th century, Bernoulli studied in my class to learn about Bernoulli's principle, which states that an increase in the speed of a fluid occurs simultaneously with a decrease in static pressure or a decrease in the fluid's potential energy. Truly remarkable indeed. This is when Bernoulli stole my work and claimed it as his own. To this day, I am not properly credited for my work. Truly saddening, truly maddening.

At Bernoulli's funeral, I deeply discussed with him about the possibility of a fourth world war in the 2050s. Others around me overheard the conversation and told me to close the casket. Truly rude of them to interrupt our conversation.

Section 1.1: Biography of Bernoulli

Bernoulli was born in Groningen, in the Netherlands, into a family of distinguished mathematicians. The Bernoulli family came originally from Antwerp, at that time in the Spanish Netherlands, but emigrated to escape the Spanish persecution of the Huguenots. After a brief period in Frankfurt the family moved to Basel, where Johann (I) Bernoulli became the town's mathematical professor. Later on, in 1695, Johann was appointed to the Chair of Mathematics at the University of Groningen (which was in the Netherlands at that time). Bernoulli's mother, Dorothea Falkner, died in 1676, when Daniel was only seven years old. Bernoulli was educated at Basel, but his father wished him to study business so that he might take over the family spice trade. However, Daniel refused, because he wanted to study mathematics. He studied mathematics and medicine at Basel University. He received his doctorate in medicine in 1694, but as a student he studied mathematics with his father's friend Johann Bernoulli. He also studied medicine under Johann's brother Jakob Bernoulli at the University of Basel. In 1695 he married Johanna, daughter of the jurist Johann Waser von Wartensee. Daniel and Johanna had two sons and three daughters. Daniel's son Nicolaus (II) Bernoulli was also a mathematician.

After that, he built a Nether portal in order to explore the math of that dimension, in which each block is equal to 8 blocks in the overworld. He managed to change the entire field of fields by inventing the colors of reality. Truly remarkable indeed.

Later life

In his later years, Bernoulli became a controversial figure due to his belief that four is real. Unfortunately, my proof published in 1459 contains irrefutable evidence that both four is equal to five, and that four is not real, but five is real. One must understand that this is not unlike quantum mechanics, and how particles behave both as a wave and as a realoid.

Chapter Seven: What is performance --- And why we should Burn indexOf

Author, I must mention that indeed I do remember the last interaction of ours, in which you stated that We should not Merge Better PRactice Changes and Caching Length because we have yet to Benchmark it. Due to this statement, several nukes have been deployed and are currently heading to your continent, but you have bigger things to worry about anyway.

It is important to underline that performance means Speed, and speed is distance divided by time. The distance that your computer has travelled when running the code is 0, but the time is nonzero. Thus, your code is infinitely slow. Shame on you.

For that reason, we can develop code that has a nonzero speed, simply by moving the computer around. This is a work in progress, so we will update you on these efforts in a few centuries.

Now it is important to talk about indexOf. Indeed, this function is loved by many developers, as it allows you to get the index of. However, this function is pure evil, worse than evaling user-written code on a production server. Let me explain why:

When you need to find an element in an array or a string, indexOf() is one of your best friends.

indexOf   in Arrays
Code first, explanation later:

Module: findSpencer.js
const zoo = ['🐒', '🦄', '🐊', '🐸', '🐙'];
const spencersIndex = zoo.indexOf('🐊');
// spencersIndex === 2
const spencer = zoo[spencersIndex];
// spencer === '🐊'
In its simplest version, the indexOf method takes one argument which is the element we are trying to find. Then it returns the index of the first element it finds in the array which satisfies el === target. This means that even if there are two matches in your array, indexOf will only return one result. The result is the first occurrence in the array (reading the array from left to right).

When no item in the array satisfies the el === target check, the value of -1 is returned.

But let’s say we are also looking for Skyler (Spencer’s sister). Then we can add an extra optional argument to start the search from a different index.

Module: findSkyler.js
const zoo = ['🐒', '🦄', '🐊', '🐸', '🐙',  '🐊']; // Skyler just arrived!
const spencersIndex = zoo.indexOf('🐊'); // === 2 same as before

// We start searching after 
const skylersIndex = zoo.indexOf('🐊', spencersIndex + 1);
// skylersIndex === 5
We can also create a method on the Array prototype that returns all the indices based on indexOf.

Module: indicesOf.js
// Try to think of ways to make indicesOf more performant
Array.prototype.indicesOf = function (target) {
  const result = [];
  let currentIndex = 0;
  while(true) {
    // here this ===  the array on which we call `indicesOf`
    const targetIndex = this.indexOf(target, currentIndex);
    if (targetIndex == -1)
      break;

    result.push(targetIndex);

    currentIndex = targetIndex +1;
  }

  return result;
}
const zoo = ['🐒', '🦄', '🐊', '🐸', '🐙',  '🐊']; // Skyler just arrived!
const alligatorsIndices = zoo.indicesOf('🐊');
// alligatorsIndices returns [2, 5]
What Can’t You Find With indexOf?
You might have noticed that we interrupt the search by using triple equal comparison el === target which is a strict equality comparison. This means, for example, that we can’t test for arrays, objects or functions other than by reference.

const simpleArray = [1, 2, 3];
const simpleFunction = () => {console.log('hey')};
const simpleObject = {alligator: 'cage'};

const compositeArray = [simpleArray, simpleFunction, simpleObject];

// These all work as expected because we compare by reference
compositeArray.indexOf(simpleArray); // returns 0
compositeArray.indexOf(simpleFunction); // returns 1
compositeArray.indexOf(simpleObject); // returns 2

// These won't work 
compositeArray.indexOf([1, 2, 3]); // returns -1
compositeArray.indexOf(() => {console.log('hey')}); // returns -1
compositeArray.indexOf({alligator: 'cage'}) // returns -1
A Deep indexOf
Let’s say we want to create a utility to also check for objects, arrays and functions recursively:

Module: inDepthIndexOf.js
Array.prototype.deepIndexOf = function (target) {
  // If the target is an object, array or a function, we give it a special treatment
  if (typeof target === 'object' || typeof target === 'function') {
    // We stringify the target 
    const searchTarget = target.toString()
    // We loop through all of the elements of the array
    for (let index = 0; index < this.length; index++){
      const element = this[index]
      // We check if the element in the array is an object or a function AND if so we check if its' stringified value is equal to our target
      if ((typeof element === 'object' || typeof target === 'function') && element.toString() === searchTarget) {
        // if we have a match we interrupt the loop and return the index
        return index
      }
    }
    // if nothing matched we return -1
    return -1
  }
  return this.indexOf(target)
}

const simpleArray = [1, 2, 3];
const simpleFunction = () => {console.log('hey')};
const simpleObject = {alligator: 'cage'};

const compositeArray = [simpleArray, simpleFunction, simpleObject];

// These all work as expected because we compare by reference
compositeArray.deepIndexOf(simpleArray); // returns 0
// ... You know the rest
// These will work!
compositeArray.deepIndexOf([1, 2, 3]); // returns 0
compositeArray.deepIndexOf(() => {console.log('hey')}); // returns 1
compositeArray.deepIndexOf({alligator: 'cage'}) // returns 2
There are many ways to improve this code. If you have some time on your hands, try to think of how to make it more accurate and performant. I’d love to read your ideas on Twitter.

Performance
Using indexOf is much slower than simply doing a for loop. That doesn’t mean that indexOf is slow. If your array is small you will never see the difference between indexOf() or a for loop. If your array is so big that you can notice a difference between the two methods, then you should probably wonder why your array is so big and how you could optimize the search. You can find performance benchmarks on JSPerf.

You should now understand why indexOf is pure evil. Never use it again, or else.

Chapter 8: Box inertia war

While I was writing this GitHub Issue, it came to my attention that a War has started among box enthusiasts, who are mad at you specifically (not schteppe, p2.js author) for the inertia problem. I have done my best to silence them using continental nukes, but alas, they are resilient. I have mailed instructions to send them away to you.

It has been a while since we have last checked on our dearest friens Euler and Bernoulli, so let's go pay them a visit. Follow me please.

Here we are. Now it is time to say the phrase to wake them up:

Rotational inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia is a quantity that determines the torque required in order to apply a desired angulation to to the physical real (digital virtual unreal in this case) object. This extensive and additive property is simply the mass times the square of the perpendicularized distancing to the axis of rotation, of which we only have one in our infinitely flat two-dimensional world. Truly remarkable how the flattening of it all can immediately reduce rotational axis counting to the multiplier of Pi.

Next, we can conclude that for bodies constrained to rotate in the plane at the airport, only their Rotational inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia about an axis penpendicularized to the planing, a scalar value, matters, everything else can immediately be discarded where appropriate. For bodies free to rotate in three dimensions, their moments can be described by a symmetric 3-by-3 matrix, with a set of mutually perpendicular principal axes for which this matrix is diagonal and torques around the axes act independently of each other. Unfortunately, we are in a two dimension, so please ignore what knowledge has just been permanently processed into your cerebrum according to That Theory that Human humans never forget information. Thank you for ignoring it. Now it is time to move on to the next explanation.

When the bodies are free to rotate around The Axis, torque is required by our constitution of universe to be applied to modify its angular momentum. The amount of torque needed to cause any given angular acceleration (the rate of change) is likely proportional to the moment of inertia of the body, though this has yet to be proven. The moments of the inertia may be expressed in units of kilogram meter squared. We refuse to recognise the existence of imperial units in this sacred chapter. In 1673, someone introduced a cool parameter in a study of some kind of oscillation in some kind of object hanging from something, known as a compound pendulum. The term moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) was introduced by Leonhard Euler in his book probably, and it is corporated in his second law, which is relatively well enforced by the police.

The moment of inertia also makes cameo appearances in momentum, kinetic energy, and in Newton's laws of motion for a rigidbody as a physical param that Merges its shape and mass just like a PR i made that removes all comments since the user can probably figure it out. The moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) of the pendulum depends on both the mass m of a body and its geometry, or shape, as defined by the distance r to the axis of rotation.

The simple formula I=mr^2 generalizes to define moment of inertia for an arbitrarily shaped body as the sum of all the elemental point masses dm each multiplied by the square of its perpendicular distance r to an axis k. An arbitrary object's moment of inertia thus depends on the spatial distribution of its mass. But what they don't want you to know is, if e=mc^2, then m from I=mr^2 is secretly just relativity hiding in plain sight. Irregardlessly, given an object of mass m, an effective radius k can be defined, dependent on a particular axis of rotation, with such a value that its moment of inertia around the axis is I=mk^2, where k is known as the gyrationizing radius around The Axis.

Do note however, mathematically, the moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) of a simple pendulum is the ratio of the torque, because of gravity about the pivot or something. For a simple pendulum (we don't talk about Complex Pendulums) this is found to be the product of mass. Great product, but the reviews are mostly botted. While we can't talk about Complex Pendulums, it's important to talk about compound pendulums whenever possible in order to be sane like me. A compound pendulum is a body formed from an assembly of particles of continuous shape that rotates rigidly around a pivot. Its moment of inertia is the sum of the moments of inertia of each of the particles that it is composed of.

Now they are wide awake. Feel free to ask them any questions you may have while we're here. I'll be waiting at the next chapter.

Chapter Nine: The future of p2-es following the fixing of the inertia issue

Once the problem has been resolved and the dust has settled, we will have to confront the truth: p2-es library will have been Forever Changed. This will have Devastating effects on the physics community, and Earth as a whole. That's why this section is dedicated to discussing exactly what commits will cease to exist following the resolution of the bug.

chore(p2-es-sandbox): update arancini to v4

@isaac-mason
isaac-mason committed last week
1
chore(changeset): release packages (#117)

@github-actions
github-actions[bot] and github-actions[bot] committed last week
1
refactor: shape default options handling

@isaac-mason
isaac-mason committed last week
1
fix: Box shape type incorrectly set to Shape.Convex instead of Shape.Box

@isaac-mason
isaac-mason committed last week
1
Commits on Oct 10, 2023
build(deps-dev): bump vite-plugin-dts from 3.5.3 to 3.6.0 (#112)

@dependabot
dependabot[bot] committed last month
1
build(deps-dev): bump @changesets/cli from 2.26.1 to 2.26.2 (#113)

@dependabot
dependabot[bot] committed last month
build(deps-dev): bump @types/node from 18.15.11 to 20.8.3 (#114)

@dependabot
dependabot[bot] committed last month
1
fix: mobile layout should scroll when controls are enabled

@isaac-mason
isaac-mason committed last month
1
Commits on Oct 8, 2023
chore(changeset): release packages (#111)

@github-actions
github-actions[bot] and github-actions[bot] committed on Oct 8
1
refactor: organise imports

@isaac-mason
isaac-mason committed on Oct 8
1
fix(sandbox): enablePanning and enableZooming should default to true

@isaac-mason
isaac-mason committed on Oct 8
1
chore(changeset): release packages (#110)

@github-actions
github-actions[bot] and github-actions[bot] committed on Oct 7
1
feat: improve p2-es-website, support hiding sandbox header and contro…

@isaac-mason
isaac-mason committed on Oct 7
1
Commits on Oct 2, 2023
build(deps-dev): bump @types/react-dom from 18.0.10 to 18.2.8 (#107)

@dependabot
dependabot[bot] committed on Oct 2
1
build(deps): bump @pixi/core from 7.0.5 to 7.3.1 (#106)

@dependabot
dependabot[bot] committed on Oct 2
build(deps-dev): bump rollup from 3.28.1 to 3.29.4 (#108)

@dependabot
dependabot[bot] committed on Oct 2
1
Commits on Sep 28, 2023
chore(changeset): release packages (#75)

@github-actions
github-actions[bot] and github-actions[bot] committed on Sep 28
1
Commits on Sep 19, 2023
build(deps-dev): bump @babel/preset-env from 7.22.10 to 7.22.20 (#100)

@dependabot
dependabot[bot] committed on Sep 19
1
build(deps-dev): bump vite-plugin-dts from 3.4.0 to 3.5.3 (#97)

@dependabot
dependabot[bot] committed on Sep 19
build(deps-dev): bump husky from 7.0.4 to 8.0.3 (#98)

@dependabot
dependabot[bot] committed on Sep 19
1
Commits on Sep 4, 2023
build(deps-dev): bump @babel/preset-typescript from 7.22.11 to 7.22.15 (

@dependabot
dependabot[bot] committed on Sep 4
1
build(deps-dev): bump eslint-plugin-simple-import-sort (#88)

@dependabot
dependabot[bot] committed on Sep 4
1
build(deps-dev): bump @typescript-eslint/eslint-plugin (#93)

@dependabot
dependabot[bot] committed on Sep 4
build(deps-dev): bump @babel/preset-typescript from 7.22.5 to 7.22.11 (…

@dependabot
dependabot[bot] committed on Sep 4
build(deps-dev): bump eslint-config-prettier from 8.10.0 to 9.0.0 (#92)

@dependabot
dependabot[bot] committed on Sep 4
build(deps-dev): bump rollup from 3.28.0 to 3.28.1 (#89)

@dependabot
dependabot[bot] committed on Sep 4
1
Commits on Aug 27, 2023
chore: simplify build script

@isaac-mason
isaac-mason committed on Aug 26
1
Commits on Aug 26, 2023
fix(p2-es-sandbox): mobile display issues

@isaac-mason
isaac-mason committed on Aug 26
1
fix: build script

@isaac-mason
isaac-mason committed on Aug 26
1
feat(p2-es-sandbox): misc bug fixes

@isaac-mason
isaac-mason committed on Aug 26
Commits on Aug 23, 2023
fix(p2-es-demos): fix hasActiveBodies demo

@isaac-mason
isaac-mason committed on Aug 23
1
feat(p2-es-sandbox): remove peer dependency on p2-es, regular depende…

@isaac-mason
isaac-mason committed on Aug 23
1
chore(p2-es-sandbox): update README.md

@isaac-mason
isaac-mason committed on Aug 23
1
chore: bump poly-decomp-es from 0.4.1 to 0.4.2

@isaac-mason
isaac-mason committed on Aug 23
1
feat(p2-es-sandbox): minor ecs refactors

@isaac-mason
isaac-mason committed on Aug 23

feat(p2-es-sandbox): depend on fixed version of p2-es

@isaac-mason
isaac-mason committed on Aug 23
1
feat(p2-es-sandbox): move logic into systems, pass domElement to Sand…

@isaac-mason
isaac-mason committed on Aug 23
1
Commits on Aug 21, 2023
chore: update storybook

@isaac-mason
isaac-mason committed on Aug 21
1
build(deps): bump styled-breakpoints from 11.1.1 to 12.1.5 (#87)

@dependabot
@isaac-mason
dependabot[bot] and isaac-mason committed on Aug 21
1
build(deps-dev): bump rollup from 2.79.1 to 3.28.0 (#82)

@dependabot
@isaac-mason
dependabot[bot] and isaac-mason committed on Aug 21
1
build(deps-dev): bump @typescript-eslint/eslint-plugin (#85)

@dependabot
dependabot[bot] committed on Aug 21
1
build(deps-dev): bump jest and @types/jest (#86)

@dependabot
dependabot[bot] committed on Aug 21
1
Commits on Aug 20, 2023
build(deps-dev): bump @babel/preset-env from 7.22.5 to 7.22.10 (#83)

@dependabot
dependabot[bot] committed on Aug 20
1
build(deps-dev): bump eslint-import-resolver-typescript (#81)

@dependabot
dependabot[bot] committed on Aug 20
build(deps-dev): bump @rollup/plugin-node-resolve from 15.0.2 to 15.1…

@dependabot
dependabot[bot] committed on Aug 20
1
build(deps-dev): bump ts-jest from 27.1.5 to 29.1.1 (#79)

@dependabot
dependabot[bot] committed on Aug 20
1
Commits on Aug 3, 2023
refactor(p2-es-sandbox): controls

@isaac-mason
isaac-mason committed on Aug 3
1
chore(p2-es-sandbox): update license

@isaac-mason
isaac-mason committed on Aug 3
1
chore(storybook): remove unused dep, remove unused stories pattern

@isaac-mason
isaac-mason committed on Aug 3
1
chore(p2-es-sandbox): add README.md

@isaac-mason
isaac-mason committed on Aug 3
1
chore: update eslint deps, remove unused

@isaac-mason
isaac-mason committed on Aug 3
feat(changesets): stop ignoring @p2-es/sandbox

@isaac-mason
isaac-mason committed on Aug 3
chore: fix package versions

@isaac-mason
isaac-mason committed on Aug 3
1
chore: make @p2-es/sandbox public

@isaac-mason
isaac-mason committed on Aug 3
feat(p2-es-sandbox): update arancini, refactor

@isaac-mason
isaac-mason committed on Aug 3
fix: p2-es-sandbox storybook

@isaac-mason
isaac-mason committed on Aug 3
chore: update README.md

@isaac-mason
isaac-mason committed on Aug 3
1
chore: run prettier

@isaac-mason
isaac-mason committed on Aug 3
feat(EventEmitter): remove 'context' functionality, prefer arrow func…

@isaac-mason
isaac-mason committed on Aug 3
chore: simplify tsconfig

@isaac-mason
isaac-mason committed on Aug 3
chore(rollup): remove unused plugin

@isaac-mason
isaac-mason committed on Aug 3
chore: simplify p2-es eslint config, address eslint errors

@isaac-mason
isaac-mason committed on Aug 3
feat(Narrowphase): remove ts-expect-error

@isaac-mason
isaac-mason committed on Aug 3
1
Commits on Jul 31, 2023
Bump eslint-config-prettier from 8.6.0 to 8.9.0 (#71)

@dependabot
dependabot[bot] committed on Jul 31
1
Bump @typescript-eslint/eslint-plugin from 5.59.9 to 6.2.0 (#73)

@dependabot
dependabot[bot] committed on Jul 31
1
Commits on Jul 29, 2023
Bump pixi.js from 7.0.5 to 7.2.4 (#61)

@dependabot
dependabot[bot] committed on Jul 29
1
Commits on Jul 4, 2023
Bump styled-components from 5.3.9 to 6.0.2 (#58)

@dependabot
dependabot[bot] committed on Jul 3
1
Commits on Jul 3, 2023
Bump vite-plugin-dts from 1.7.1 to 3.0.2 (#56)

@dependabot
dependabot[bot] committed on Jul 3
1
Commits on Jul 1, 2023
Bump typedoc from 0.22.18 to 0.24.8 (#38)

@dependabot
dependabot[bot] committed on Jul 1
1
Bump babel-loader from 8.3.0 to 9.1.2 (#49)

@dependabot
dependabot[bot] committed on Jul 1

All of these commits will cease to exist following the closing of this issue in order to comply with reality. Thank you for your understanding.

Chapter Ten: Epilogue

In the last chapter, our dearest friends Euler and Bernoulli were starting a revolution against quaternions, as they prefer Euler Angles. For that reason, this chapter is dedicated to the lingering memories of their existence in our cerebrum tissue.

In this GitHub issue, we have changed the worlds together! Let this issue be remembered *remembered not as a mere bug report, but as one of the greatest inspirational texts to have ever been realed!

So never give up. Maybe one day you can be as cool as me. And remember: mathematically, the moment of inertia (moment of inertia (moment of inertia, also known as the moment of inertia, otherwise known as the mass moment of inertia, otherwise known as angular mass, otherwise known as the second moment of mass, otherwise known as Rotational inertia)) of a simple pendulum is the ratio of the torque, because of gravity about the pivot or something.

Yours truly,

You from the future

Web workers

You told in a different repo that you have made webworkers possible.

How did you make that possible? Do you have a link to the code?

I'm especially curious on how you'd solve the communication overhead

Issue with CCD and sensor shapes

Setting ccdSpeedThreshold = 0 on a body and then making one of the shapes into a sensor makes the shape collide as if it didn't have sensor = true.
The easiest fix I could find is checking for the sensor at integrateToTimeOfImpact but I'm unsure if that has other major implications.
This is an issue originating from p2, hoping it can be fixed.

Create demo renderer package

Create @p2-es/sandbox package containing the demo environment used in apps/p2-es-demos

This will be useful for sharing small demonstrations and issue repros.

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.