magnusmaynard / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
0 stars 0 forks source link

Sweep: Add a new function to Vector3 to non-linearly interpolate between two vectors #7

Open magnusmaynard opened 9 months ago

magnusmaynard commented 9 months ago

Details

Modify Vector3.js to add a new function similar to lerp, where it takes another vector. But this new function should be a non-linear interpolation. This function should have an additional parameter to control the strength/power of the curve. There should be a unit test to confirm the function produces the right outputs, testing the variety of strength values.

Checklist - [X] Modify `src/math/Vector3.js` ✓ https://github.com/magnusmaynard/three.js/commit/571390b42c2a4b88aa4a42042f2c4975103e01c9 [Edit](https://github.com/magnusmaynard/three.js/edit/sweep/add_a_new_function_to_vector3_to_nonline/src/math/Vector3.js#L4-L708) - [X] Running GitHub Actions for `src/math/Vector3.js` ✓ [Edit](https://github.com/magnusmaynard/three.js/edit/sweep/add_a_new_function_to_vector3_to_nonline/src/math/Vector3.js#L4-L708) - [X] Modify `test/unit/src/math/Vector3.tests.js` ✓ https://github.com/magnusmaynard/three.js/commit/4622016413711e0ee48c3e7e2c350b41280c57b3 [Edit](https://github.com/magnusmaynard/three.js/edit/sweep/add_a_new_function_to_vector3_to_nonline/test/unit/src/math/Vector3.tests.js#L19-L708) - [X] Running GitHub Actions for `test/unit/src/math/Vector3.tests.js` ✓ [Edit](https://github.com/magnusmaynard/three.js/edit/sweep/add_a_new_function_to_vector3_to_nonline/test/unit/src/math/Vector3.tests.js#L19-L708)
sweep-ai[bot] commented 9 months ago

🚀 Here's the PR! #8

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 4 GPT-4 tickets left for the month and 2 for the day. (tracking ID: 6cfc40a0d9)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

[!TIP] I'll email you at contact@magnus.co.uk when I complete this pull request!


Actions (click)

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 8145452
Checking src/math/Vector3.js for syntax errors... ✅ src/math/Vector3.js has no syntax errors! 1/1 ✓
Checking src/math/Vector3.js for syntax errors...
✅ src/math/Vector3.js has no syntax errors!

Sandbox passed on the latest dev, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/magnusmaynard/three.js/blob/81454522273f087bb63135a2f0ccbfd0feb45e6d/src/math/Vector3.js#L3-L708 https://github.com/magnusmaynard/three.js/blob/81454522273f087bb63135a2f0ccbfd0feb45e6d/test/unit/src/math/Vector3.tests.js#L19-L708

Step 2: ⌨️ Coding

--- 
+++ 
@@ -472,6 +472,16 @@

    }

+   nonLinearLerp(vector, alpha, strength) {
+       const invAlpha = 1 - alpha;
+       const powAlpha = Math.pow(alpha, strength);
+       const powInvAlpha = Math.pow(invAlpha, strength);
+       this.x = this.x * powInvAlpha + vector.x * powAlpha;
+       this.y = this.y * powInvAlpha + vector.y * powAlpha;
+       this.z = this.z * powInvAlpha + vector.z * powAlpha;
+       return this;
+   }
+
    cross( v ) {

        return this.crossVectors( this, v );

Ran GitHub Actions for 571390b42c2a4b88aa4a42042f2c4975103e01c9:

--- 
+++ 
@@ -745,6 +745,21 @@

        } );

+       QUnit.test( 'nonLinearLerp', ( assert ) => {
+       const a = new Vector3(0, 0, 0);
+       const b = new Vector3(10, -10, 10);
+       const result = new Vector3();
+
+       result.copy(a).nonLinearLerp(b, 0.5, 1); // Linear interpolation for comparison
+       assert.ok( result.equals(new Vector3(5, -5, 5)), 'Strength 1 (linear) works correctly' );
+
+       result.copy(a).nonLinearLerp(b, 0.5, 2); // Quadratic interpolation
+       assert.ok( result.equals(new Vector3(2.5, -2.5, 2.5)), 'Strength 2 (quadratic) works correctly' );
+
+       result.copy(a).nonLinearLerp(b, 0.5, 0.5); // Square root interpolation
+       assert.ok( result.equals(new Vector3(7.0710678118654755, -7.0710678118654755, 7.0710678118654755)), 'Strength 0.5 (square root) works correctly' );
+       });
+
        QUnit.test( 'fromArray', ( assert ) => {

            const a = new Vector3();

Ran GitHub Actions for 4622016413711e0ee48c3e7e2c350b41280c57b3:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/add_a_new_function_to_vector3_to_nonline.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.