Open magnusmaynard opened 9 months ago
6cfc40a0d9
)[!TIP] I'll email you at contact@magnus.co.uk when I complete this pull request!
Here are the GitHub Actions logs prior to making any changes:
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.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/math/Vector3.js
✓ https://github.com/magnusmaynard/three.js/commit/571390b42c2a4b88aa4a42042f2c4975103e01c9 Edit
Modify src/math/Vector3.js with contents:
• Add a new method `nonLinearLerp(vector, alpha, strength)` to the `Vector3` class after the existing `lerp` method. This method will perform a non-linear interpolation between the current vector and the provided `vector` parameter, based on the `alpha` and `strength` parameters. The `alpha` parameter controls the interpolation factor, and the `strength` parameter controls the curvature of the interpolation.
• The mathematical formula for non-linear interpolation can vary, but a simple approach is to use a power function to adjust the interpolation curve. The method could look something like this: ```javascript 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; } ```
• This implementation assumes a symmetric non-linear interpolation. The `strength` parameter allows control over how sharply or smoothly the interpolation transitions from one vector to the other.
--- +++ @@ -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 );
src/math/Vector3.js
✓ Edit
Check src/math/Vector3.js with contents:
Ran GitHub Actions for 571390b42c2a4b88aa4a42042f2c4975103e01c9:
[X] Modify test/unit/src/math/Vector3.tests.js
✓ https://github.com/magnusmaynard/three.js/commit/4622016413711e0ee48c3e7e2c350b41280c57b3 Edit
Modify test/unit/src/math/Vector3.tests.js with contents:
• Add a new unit test for the `nonLinearLerp` method within the `Vector3` test suite. This test should verify that the method correctly interpolates between two vectors for various `alpha` and `strength` values.
• The test could be structured as follows: ```javascript 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' ); }); ```
• This test checks the `nonLinearLerp` method against three different strength values: 1 (linear interpolation), 2 (quadratic interpolation), and 0.5 (square root interpolation), ensuring that the method behaves as expected for different non-linear curves.
--- +++ @@ -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();
test/unit/src/math/Vector3.tests.js
✓ Edit
Check test/unit/src/math/Vector3.tests.js with contents:
Ran GitHub Actions for 4622016413711e0ee48c3e7e2c350b41280c57b3:
I have finished reviewing the code for completeness. I did not find errors for sweep/add_a_new_function_to_vector3_to_nonline
.
💡 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.
Details
Modify
Vector3.js
to add a new function similar tolerp
, 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)