Skip to content

Fix ParticleCompositeCurve zero max overload selection - #3083

Open
luzhuang wants to merge 1 commit into
galacean:dev/2.0from
luzhuang:fix/particle-composite-curve-zero-max
Open

Fix ParticleCompositeCurve zero max overload selection#3083
luzhuang wants to merge 1 commit into
galacean:dev/2.0from
luzhuang:fix/particle-composite-curve-zero-max

Conversation

@luzhuang

@luzhuang luzhuang commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • select ParticleCompositeCurve two-argument overloads by argument presence instead of truthiness
  • preserve 0 as a valid maximum constant
  • add a regression that verifies the hydrated Engine object mode, endpoints, and evaluation

Verification

  • HEADLESS=true pnpm vitest run tests/src/core/particle/ParticleCurve.test.ts (8 tests passed)
  • pnpm -F @galacean/engine-core b:types
  • pnpm eslint packages/core/src/particle/modules/ParticleCompositeCurve.ts (no errors; 6 pre-existing warnings elsewhere in the file)
  • pnpm prettier --check packages/core/src/particle/modules/ParticleCompositeCurve.ts tests/src/core/particle/ParticleCurve.test.ts

Closes #3082

Summary by CodeRabbit

  • Bug Fixes

    • Fixed composite curves with a maximum value of 0 being interpreted incorrectly.
    • Ensured two-value curve configurations evaluate correctly across their range.
  • Tests

    • Added coverage for composite curves using a maximum value of 0.

Downstream

  • Implements #3082 for galacean/editor#3813, which emits canonical ParticleCompositeCurve(min, max) runtime-v2 constructor data.
  • After this fix is merged and published in a new 2.0.0-alpha.*, Editor will bump its pinned Engine dependencies and restore the API → source-v2 → Builder → Loader → Engine object regression.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

ParticleCompositeCurve now detects provided second arguments explicitly, preserving zero-valued maxima in numeric and curve overloads. A regression test verifies ParticleCompositeCurve(5, 0) selects two-constant mode and evaluates correctly.

Changes

Particle composite curve handling

Layer / File(s) Summary
Constructor argument presence handling
packages/core/src/particle/modules/ParticleCompositeCurve.ts
Numeric and curve overloads use !== undefined, so defined falsy second arguments select the two-parameter modes.
Zero-maximum regression coverage
tests/src/core/particle/ParticleCurve.test.ts
Adds coverage for mode selection, endpoint values, and evaluation of ParticleCompositeCurve(5, 0).

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: particle

Suggested reviewers: cptbtptpbcptdtptp

Poem

I’m a bunny with ears held high,
Zero now hops through curves nearby.
Two constants meet, modes align,
Tests guard the path from five to zero—fine!
Thump, thump, the fix is mine.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The bug fix and 0-value overload behavior are addressed, but the requested regression for the hydrated Engine object is not evidenced. Add a regression test that hydrates the Engine object and asserts the final mode and endpoints, not just the ParticleCompositeCurve instance.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes stay focused on the overload-selection bug and its regression test, with no clear unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main fix: handling a zero max value in ParticleCompositeCurve overload selection.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/src/core/particle/ParticleCurve.test.ts`:
- Around line 19-26: Add a regression test using the Engine
hydration/deserialization entry point with serialized $args [5, 0], rather than
only constructing ParticleCompositeCurve directly. Assert the hydrated object’s
ParticleCurveMode, constantMin, constantMax, and evaluations at 0 and 1, while
retaining the existing constructor test unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3057f391-74dc-49db-8819-39d29613c198

📥 Commits

Reviewing files that changed from the base of the PR and between bd34daa and cfaa3bb.

📒 Files selected for processing (2)
  • packages/core/src/particle/modules/ParticleCompositeCurve.ts
  • tests/src/core/particle/ParticleCurve.test.ts

Comment on lines +19 to +26
it("Constructor with zero as the max constant", () => {
const gradient = new ParticleCompositeCurve(5, 0);
expect(gradient.mode).to.equal(ParticleCurveMode.TwoConstants);
expect(gradient.constantMin).to.equal(5);
expect(gradient.constantMax).to.equal(0);
expect(gradient.evaluate(undefined, 0)).to.equal(5);
expect(gradient.evaluate(undefined, 1)).to.equal(0);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Cover the Engine hydration path in the regression test.

This test validates the core constructor directly, but it cannot catch runtime-v2 hydration converting $args: [5, 0] into Constant 5. Add a test through the actual Engine hydration/deserialization entry point and assert the hydrated object’s mode, endpoints, and evaluation; retain this unit test as well.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/src/core/particle/ParticleCurve.test.ts` around lines 19 - 26, Add a
regression test using the Engine hydration/deserialization entry point with
serialized $args [5, 0], rather than only constructing ParticleCompositeCurve
directly. Assert the hydrated object’s ParticleCurveMode, constantMin,
constantMax, and evaluations at 0 and 1, while retaining the existing
constructor test unchanged.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.40%. Comparing base (bd34daa) to head (cfaa3bb).

Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #3083      +/-   ##
===========================================
- Coverage    85.42%   85.40%   -0.02%     
===========================================
  Files          811      811              
  Lines        94654    94654              
  Branches     11512    11504       -8     
===========================================
- Hits         80854    80839      -15     
- Misses       13710    13725      +15     
  Partials        90       90              
Flag Coverage Δ
unittests 85.40% <100.00%> (-0.02%) ⬇️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GuoLei1990 GuoLei1990 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🫧 尘小沫

结论

阻塞级别:无。已完成 bd34daa45612af8b402cd3be916ff181f21ae742...cfaa3bb4c97136019cce494b2dc33062522c06b9 的完整单提交增量审查;本轮未发现新的 P0/P1/P2,实际 review 动作为 COMMENTED,目标 HEAD 为 cfaa3bb4c97136019cce494b2dc33062522c06b9。CI 的 lint、三平台 build、四组 e2e 与 patch coverage 均通过;codecov/project 仍因整体覆盖率下降 0.02% 为红,patch 覆盖率为 100%。自动 CR 不替代人工 Reviewer 的合入门禁,本 review 不执行 APPROVE。

已关闭问题清单

  • discussion_r3670582660(要求增加 runtime-v2 hydration 回归)— 不适用ReflectionParser$args 只逐项 _resolveValue 后原样执行 new Class(...args),既不按 truthiness 选择重载,也不会过滤 0;本次根因和公开契约均由 ParticleCompositeCurve 构造器单点拥有。新增测试直接从公开构造入口断言 mode、两个端点及 evaluate,回退本修复后会失败,已经覆盖真实回归点;在本 PR 再复制一条未改动 generic loader 路径不会增加根因保护。

架构、熵增与测试治理

上游 Editor #3813 产出 canonical $args: [constantMin, constantMax];Engine loader 仅解析参数并原样展开;ParticleCompositeCurve 构造器是重载选择、端点写入和 mode 的唯一 owner;下游 EmissionModule 只通过 burst.count.evaluate(...) 消费该公开状态。改动把 owner 内部的 truthiness 判据替换为参数存在性判据,没有新增 owner、状态、转换、校验、兼容分支、wrapper 或持久化表示,概念净增为 0。

同根因扫描未发现第二套 numeric max 重载判断;相邻 ParticleCompositeGradient 的第二参数是对象,不存在合法 falsy 端点。两曲线分支同步改为存在性判断只统一同一个构造协议,没有引入平行状态机。测试使用公开入口和公开输出,且反转代码即可证伪;没有失效 fixture/mock/snapshot,也没有为了旧测试保留 legacy fallback 或第二条转换路径。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants