Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle start size support curve mode #2568

Merged
merged 11 commits into from
Feb 28, 2025

Conversation

GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Feb 24, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

  • Now the operation functions of ParticleCompositeCurve and ParticleCurve do not consider forced normalization(Is it necessary to regulate in the future?)

Summary by CodeRabbit

  • New Features
    • Enhanced particle effects with more accurate timing through updated parameter handling in particle generation.
    • Introduced new evaluation modes for particle curves, allowing for more complex animations and transitions.
    • Added a method for evaluating particle positions along curves based on normalized age.
  • Tests
    • Added comprehensive tests to validate that particle effects behave reliably across various scenarios.

@GuoLei1990 GuoLei1990 marked this pull request as draft February 24, 2025 10:37
Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

This pull request updates particle-related modules to improve clarity and functionality. In the ParticleGenerator class, the parameter name has changed from time to playTime, and normalized emit age is computed for particle lifetime evaluation. The ParticleCompositeCurve class now supports new curve modes ("Curve" and "TwoCurves") that leverage curve evaluation. A new _evaluate method is added to the ParticleCurve class to perform linear interpolation over curve keys. Additionally, unit tests have been introduced for both curve classes using the vitest framework.

Changes

File(s) Change Summary
packages/core/.../ParticleGenerator.ts Renamed parameter from time to playTime in _emit and _addNewParticle; added logic for computing normalized emit age for particle lifetime evaluation.
packages/core/.../modules/ParticleCompositeCurve.ts Updated ParticleCompositeCurve.evaluate to handle new modes (Curve, TwoCurves) using the new _evaluate method.
packages/core/.../modules/ParticleCurve.ts Added _evaluate(normalizedAge: number): number method for linear interpolation based on normalized age.
tests/.../ParticleCurve.test.ts Introduced unit tests covering various initialization scenarios and evaluation cases for ParticleCompositeCurve and ParticleCurve classes with the vitest framework.

Sequence Diagram(s)

sequenceDiagram
    participant PG as ParticleGenerator
    participant SH as Shape

    PG->>SH: _generatePositionAndDirection(playTime)
    PG->>PG: _addNewParticle(..., playTime)
    PG->>PG: Compute normalizedEmitAge(playTime, main module duration)
Loading
sequenceDiagram
    participant PCC as ParticleCompositeCurve
    participant PC as ParticleCurve

    alt ParticleCurveMode.Curve
        PCC->>PC: _evaluate(normalizedAge)
    else ParticleCurveMode.TwoCurves
        PCC->>PC: _evaluate(normalizedAge) [curveMin]
        PCC->>PC: _evaluate(normalizedAge) [curveMax]
        PCC->>PCC: Lerp using lerpFactor
    end
Loading

Possibly related PRs

Suggested reviewers

  • MrKou47

Poem

I'm a hopping rabbit, coding with glee,
PlayTime now guides each particle free.
Curves and tests make the code dance tight,
With linear leaps through day and night.
A bunny’s cheer for changes so bright –
Carrots and code, what a delight!
🐰🌟

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@GuoLei1990 GuoLei1990 added enhancement New feature or request particle labels Feb 24, 2025
Copy link

codecov bot commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 84.61538% with 8 lines in your changes missing coverage. Please review.

Project coverage is 69.43%. Comparing base (9a28f37) to head (11b0228).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
packages/core/src/particle/ParticleGenerator.ts 70.58% 5 Missing ⚠️
...ore/src/particle/modules/ParticleCompositeCurve.ts 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2568      +/-   ##
==========================================
+ Coverage   68.93%   69.43%   +0.49%     
==========================================
  Files         961      961              
  Lines      100271   100298      +27     
  Branches     8655     8667      +12     
==========================================
+ Hits        69121    69637     +516     
+ Misses      30890    30401     -489     
  Partials      260      260              
Flag Coverage Δ
unittests 69.43% <84.61%> (+0.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GuoLei1990 GuoLei1990 marked this pull request as ready for review February 25, 2025 03:33
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/src/core/particle/ParticleCurve.test.ts (1)

1-54: Great test coverage for different curve scenarios.

The tests provide good coverage for the different constructor and evaluation scenarios. However, there are a few style issues with extra line breaks that should be addressed.

    expect(compositeCurve.evaluate(0.9, 0.0)).to.equal(0.7);
    expect(compositeCurve.evaluate(1.0, 0.0)).to.equal(0.7);

-

    expect(compositeCurve.evaluate(0.0, 1.0)).to.equal(0.5);
    expect(compositeCurve.evaluate(0.5, 1.0)).to.equal(0.55);
    expect(compositeCurve.evaluate(0.6, 1.0)).to.equal(0.6);
    expect(compositeCurve.evaluate(0.9, 1.0)).to.equal(0.75);
    expect(compositeCurve.evaluate(1.0, 1.0)).to.equal(0.8);

-

    expect(compositeCurve.evaluate(0.6, 0.5)).to.equal(0.6499999999999999);
🧰 Tools
🪛 ESLint

[error] 44-45: Delete

(prettier/prettier)


[error] 49-50: Delete

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a28f37 and daa9912.

📒 Files selected for processing (4)
  • packages/core/src/particle/ParticleGenerator.ts (7 hunks)
  • packages/core/src/particle/modules/ParticleCompositeCurve.ts (2 hunks)
  • packages/core/src/particle/modules/ParticleCurve.ts (1 hunks)
  • tests/src/core/particle/ParticleCurve.test.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/core/src/particle/modules/ParticleCompositeCurve.ts

[error] 181-181: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

🪛 GitHub Check: codecov/patch
packages/core/src/particle/modules/ParticleCompositeCurve.ts

[warning] 179-179: packages/core/src/particle/modules/ParticleCompositeCurve.ts#L179
Added line #L179 was not covered by tests


[warning] 181-182: packages/core/src/particle/modules/ParticleCompositeCurve.ts#L181-L182
Added lines #L181 - L182 were not covered by tests

packages/core/src/particle/ParticleGenerator.ts

[warning] 743-745: packages/core/src/particle/ParticleGenerator.ts#L743-L745
Added lines #L743 - L745 were not covered by tests


[warning] 814-814: packages/core/src/particle/ParticleGenerator.ts#L814
Added line #L814 was not covered by tests


[warning] 817-817: packages/core/src/particle/ParticleGenerator.ts#L817
Added line #L817 was not covered by tests

🪛 ESLint
tests/src/core/particle/ParticleCurve.test.ts

[error] 44-45: Delete

(prettier/prettier)


[error] 49-50: Delete

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (5)
packages/core/src/particle/modules/ParticleCurve.ts (1)

89-113: LGTM! The implementation of curve evaluation is well-structured.

The new _evaluate method accurately implements linear interpolation between curve keys. It properly handles edge cases:

  1. When the normalized age is before the first key
  2. When it falls between two keys (using linear interpolation)
  3. When it exceeds the last key's time

This will provide a smooth transition when evaluating curves for particle properties.

packages/core/src/particle/ParticleGenerator.ts (4)

240-241: LGTM! Renamed parameter for better clarity.

Renaming from time to playTime enhances code readability by making the parameter's purpose clearer.


253-254: Consistent parameter naming.

Updated the method call to use the renamed playTime parameter.


261-262: Consistent parameter naming.

Updated the method call to use the renamed playTime parameter.


672-750: Added normalized age calculation for curve-based particle size evaluation.

The implementation now properly calculates normalizedEmitAge based on the play time and duration, which is then used to evaluate the start size properties. This allows for time-dependent particle size variation.

Note that the PR objectives mentioned a question about forced normalization for ParticleCompositeCurve and ParticleCurve operations. The implementation here seems to address this by explicitly calculating and using normalized values.

Since these changes involve new functionality, consider adding specific test cases to verify the integration of the normalized age calculation with the particle size evaluation.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 743-745: packages/core/src/particle/ParticleGenerator.ts#L743-L745
Added lines #L743 - L745 were not covered by tests

const { length } = keys;

for (let i = 0; i < length; i++) {
const key = keys[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check if the keys array is empty here?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb6b1d and 0b0a16d.

📒 Files selected for processing (1)
  • tests/src/core/particle/ParticleCurve.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (5)
tests/src/core/particle/ParticleCurve.test.ts (5)

1-3: LGTM! Imports are properly defined.

The necessary imports from both the engine core and vitest testing framework are correctly included.


4-9: Test case well-structured with appropriate assertions.

This test case correctly validates that a ParticleCompositeCurve initialized with a single constant value uses the Constant mode and returns the expected value when evaluated.


11-17: Comprehensive testing of two-constant mode.

Good test coverage for the TwoConstants mode, testing boundary conditions (0.0, 1.0) and interpolation behavior (0.5).


19-30: Good validation of Curve mode behavior.

The test effectively validates both single-key and multi-key curve scenarios, covering different evaluation positions along the curve.


32-51: Thorough testing of TwoCurves mode with interpolation.

This test case provides excellent coverage of the TwoCurves mode, testing evaluation at multiple positions for both individual curves (min and max) and blended interpolation between them.

Comment on lines 53 to 59
it("Add and remove", () => {
const curve = new ParticleCurve(new CurveKey(0, 0.3), new CurveKey(0.6, 0.7));
curve.addKey(new CurveKey(0, 0.4));
curve.removeKey(2);
curve.removeKey(0);
curve.removeKey(0);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add assertions to verify key addition and removal.

While the code tests the add and remove functionality, it lacks assertions to verify that the operations worked as expected. Consider adding expectations to check the curve's state after each operation.

 it("Add and remove", () => {
   const curve = new ParticleCurve(new CurveKey(0, 0.3), new CurveKey(0.6, 0.7));
+  expect(curve.keys.length).to.equal(2);
+  
   curve.addKey(new CurveKey(0, 0.4));
+  expect(curve.keys.length).to.equal(3);
+  expect(curve.keys[0].value).to.equal(0.4);
+  
   curve.removeKey(2);
+  expect(curve.keys.length).to.equal(2);
+  
   curve.removeKey(0);
+  expect(curve.keys.length).to.equal(1);
+  expect(curve.keys[0].time).to.equal(0.6);
+  
   curve.removeKey(0);
+  expect(curve.keys.length).to.equal(0);
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("Add and remove", () => {
const curve = new ParticleCurve(new CurveKey(0, 0.3), new CurveKey(0.6, 0.7));
curve.addKey(new CurveKey(0, 0.4));
curve.removeKey(2);
curve.removeKey(0);
curve.removeKey(0);
});
it("Add and remove", () => {
const curve = new ParticleCurve(new CurveKey(0, 0.3), new CurveKey(0.6, 0.7));
expect(curve.keys.length).to.equal(2);
curve.addKey(new CurveKey(0, 0.4));
expect(curve.keys.length).to.equal(3);
expect(curve.keys[0].value).to.equal(0.4);
curve.removeKey(2);
expect(curve.keys.length).to.equal(2);
curve.removeKey(0);
expect(curve.keys.length).to.equal(1);
expect(curve.keys[0].time).to.equal(0.6);
curve.removeKey(0);
expect(curve.keys.length).to.equal(0);
});

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/src/core/particle/ParticleCurve.test.ts (1)

26-29: Consider using a delta for floating point comparisons.

Floating point comparisons are using exact values like 0.6333333333333333 which may lead to flaky tests on different platforms or compiler optimizations. Consider using expect(...).to.be.closeTo(expectedValue, delta) instead.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0a16d and 11b0228.

📒 Files selected for processing (1)
  • tests/src/core/particle/ParticleCurve.test.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
tests/src/core/particle/ParticleCurve.test.ts

[error] 55-55: Replace +·· with ···+

(prettier/prettier)


[error] 56-58: Replace +··⏎·⏎···· with ···+

(prettier/prettier)


[error] 59-59: Replace +·· with ···+

(prettier/prettier)


[error] 60-60: Replace +·· with ···+

(prettier/prettier)


[error] 61-62: Replace +·⏎···· with ···+

(prettier/prettier)


[error] 63-63: Replace +·· with ···+

(prettier/prettier)


[error] 64-65: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 66-67: Replace ····⏎·+·· with ⏎····+

(prettier/prettier)


[error] 68-68: Replace +·· with ···+

(prettier/prettier)


[error] 69-69: Replace +·· with ···+

(prettier/prettier)


[error] 70-71: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 72-72: Replace +·· with ···+

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e (22.x)
🔇 Additional comments (3)
tests/src/core/particle/ParticleCurve.test.ts (3)

1-74: Well-structured comprehensive test suite for particle curve functionality.

This test file properly covers the different initialization scenarios and behaviors of the ParticleCompositeCurve and ParticleCurve classes. The tests thoroughly verify the different curve modes and evaluation logic.

🧰 Tools
🪛 ESLint

[error] 55-55: Replace +·· with ···+

(prettier/prettier)


[error] 56-58: Replace +··⏎·⏎···· with ···+

(prettier/prettier)


[error] 59-59: Replace +·· with ···+

(prettier/prettier)


[error] 60-60: Replace +·· with ···+

(prettier/prettier)


[error] 61-62: Replace +·⏎···· with ···+

(prettier/prettier)


[error] 63-63: Replace +·· with ···+

(prettier/prettier)


[error] 64-65: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 66-67: Replace ····⏎·+·· with ⏎····+

(prettier/prettier)


[error] 68-68: Replace +·· with ···+

(prettier/prettier)


[error] 69-69: Replace +·· with ···+

(prettier/prettier)


[error] 70-71: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 72-72: Replace +·· with ···+

(prettier/prettier)


53-73: Addressed previous review comments.

The test now includes assertions to verify key addition and removal operations as requested in the previous review. However, there are still issues with the expectations as noted in other comments.

🧰 Tools
🪛 ESLint

[error] 55-55: Replace +·· with ···+

(prettier/prettier)


[error] 56-58: Replace +··⏎·⏎···· with ···+

(prettier/prettier)


[error] 59-59: Replace +·· with ···+

(prettier/prettier)


[error] 60-60: Replace +·· with ···+

(prettier/prettier)


[error] 61-62: Replace +·⏎···· with ···+

(prettier/prettier)


[error] 63-63: Replace +·· with ···+

(prettier/prettier)


[error] 64-65: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 66-67: Replace ····⏎·+·· with ⏎····+

(prettier/prettier)


[error] 68-68: Replace +·· with ···+

(prettier/prettier)


[error] 69-69: Replace +·· with ···+

(prettier/prettier)


[error] 70-71: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 72-72: Replace +·· with ···+

(prettier/prettier)


55-72: Fix formatting issues.

The static analysis tool indicates formatting issues with the indentation of the added lines. This appears to be related to the annotation process rather than the actual code, but please ensure that the final code follows the project's formatting guidelines.

🧰 Tools
🪛 ESLint

[error] 55-55: Replace +·· with ···+

(prettier/prettier)


[error] 56-58: Replace +··⏎·⏎···· with ···+

(prettier/prettier)


[error] 59-59: Replace +·· with ···+

(prettier/prettier)


[error] 60-60: Replace +·· with ···+

(prettier/prettier)


[error] 61-62: Replace +·⏎···· with ···+

(prettier/prettier)


[error] 63-63: Replace +·· with ···+

(prettier/prettier)


[error] 64-65: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 66-67: Replace ····⏎·+·· with ⏎····+

(prettier/prettier)


[error] 68-68: Replace +·· with ···+

(prettier/prettier)


[error] 69-69: Replace +·· with ···+

(prettier/prettier)


[error] 70-71: Replace +··⏎···· with ···+

(prettier/prettier)


[error] 72-72: Replace +·· with ···+

(prettier/prettier)

Comment on lines +59 to +61
+ expect(curve.keys.length).to.equal(3);
+ expect(curve.keys[0].value).to.equal(0.3);
+
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect assertion for key addition test.

The assertion is checking for curve.keys[0].value to equal 0.3, but this doesn't match the expected behavior after adding a new key with value 0.4. The new key should either replace the existing key at index 0 or be sorted into the proper position, depending on the implementation.

-  expect(curve.keys[0].value).to.equal(0.3);
+  // After adding a new key at time 0 with value 0.4, check that it's either:
+  // 1. At the correct position if keys are sorted by time
+  const keyAtTimeZero = curve.keys.find(key => key.time === 0);
+  expect(keyAtTimeZero?.value).to.equal(0.4);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
+ expect(curve.keys.length).to.equal(3);
+ expect(curve.keys[0].value).to.equal(0.3);
+
expect(curve.keys.length).to.equal(3);
- expect(curve.keys[0].value).to.equal(0.3);
+ // After adding a new key at time 0 with value 0.4, check that it's either:
+ // 1. At the correct position if keys are sorted by time
+ const keyAtTimeZero = curve.keys.find(key => key.time === 0);
+ expect(keyAtTimeZero?.value).to.equal(0.4);
🧰 Tools
🪛 ESLint

[error] 59-59: Replace +·· with ···+

(prettier/prettier)


[error] 60-60: Replace +·· with ···+

(prettier/prettier)

Comment on lines +67 to +69
+ expect(curve.keys.length).to.equal(1);
+ expect(curve.keys[0].time).to.equal(0.0);
+ expect(curve.keys[0].value).to.equal(0.4);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect assertions after key removal.

After removing the key at index 0, you're expecting the remaining key to have time 0.0 and value 0.4, but based on the initial setup and removal operations, I'd expect the remaining key to have time 0.0 (from the newly added key) and value 0.4.

Let's verify the expected behavior:

  1. Initial keys: time 0 with value 0.3, time 0.6 with value 0.7
  2. Add key at time 0 with value 0.4
  3. Remove key at index 2 (the key at time 0.6)
  4. Remove key at index 0 (one of the keys at time 0)
  5. The only remaining key should be at time 0 with value 0.4 (or 0.3, depending on how keys are ordered)
-  expect(curve.keys[0].time).to.equal(0.0);
-  expect(curve.keys[0].value).to.equal(0.4);
+  // After removing two keys, verify that:
+  // 1. Only one key remains
+  // 2. That key has the expected time and value
+  expect(curve.keys.length).to.equal(1);
+  expect(curve.keys[0].time).to.equal(0.0);
+  
+  // Depending on the implementation, the value should be either 0.3 or 0.4
+  const expectedValue = curve.keys[0].value === 0.3 ? 0.3 : 0.4;
+  expect(curve.keys[0].value).to.equal(expectedValue);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
+ expect(curve.keys.length).to.equal(1);
+ expect(curve.keys[0].time).to.equal(0.0);
+ expect(curve.keys[0].value).to.equal(0.4);
// After removing two keys, verify that:
// 1. Only one key remains
// 2. That key has the expected time and value
expect(curve.keys.length).to.equal(1);
expect(curve.keys[0].time).to.equal(0.0);
// Depending on the implementation, the value should be either 0.3 or 0.4
const expectedValue = curve.keys[0].value === 0.3 ? 0.3 : 0.4;
expect(curve.keys[0].value).to.equal(expectedValue);
🧰 Tools
🪛 ESLint

[error] 68-68: Replace +·· with ···+

(prettier/prettier)


[error] 69-69: Replace +·· with ···+

(prettier/prettier)

Copy link
Contributor

@johanzhu johanzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@GuoLei1990 GuoLei1990 merged commit 2cd5b85 into galacean:main Feb 28, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request particle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants