Skip to content

chore: Keep Screenshot editor sources under 500 lines#1782

Merged
hatayama merged 3 commits into
feature/god-class-split-integrationfrom
feat/split-screenshot-annotators
Jul 14, 2026
Merged

chore: Keep Screenshot editor sources under 500 lines#1782
hatayama merged 3 commits into
feature/god-class-split-integrationfrom
feat/split-screenshot-annotators

Conversation

@hatayama

@hatayama hatayama commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Split three Screenshot god classes so each implementation file stays under 500 lines without changing capture/annotation behavior.
  • Added ScreenshotUseCase characterization tests first; RaycastGridAnnotator/UIElementAnnotator already had strong dedicated coverage.

User Impact

  • No user-facing behavior change for screenshot capture, UI annotation, or raycast grid annotation.
  • Maintainability improves by separating capture orchestration, annotation rendering/styling, and raycast summary/physics builders.

Changes

  • ScreenshotUseCase → orchestration + coordinate metadata / parameter validator / file writer / response factory helpers
  • UIElementAnnotator → collection/overlay entrypoints + UIElementAnnotationRenderer / UIElementAnnotationStyling
  • RaycastGridAnnotator → grid orchestration + RaycastLayerSummaryBuilder / RaycastPhysicsColliderBuilder

Verification

  • uloop compile → 0/0
  • wc -l all target + extracted files < 500
  • EditMode Screenshot|RaycastGrid|UIElementAnnotator → 93 passed
  • dotnet test tests/UnityCliLoop.CodeComplexity.Tests → 12 passed

Made with Cursor

Review in cubic

hatayama and others added 2 commits July 14, 2026 17:47
Expose pure helper methods as internal and pin timeout/response/metadata/sanitization outputs so Extract Class on Screenshot files cannot silently change behavior. RaycastGridAnnotator already has extensive dedicated coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
Extract Class on ScreenshotUseCase, UIElementAnnotator, and RaycastGridAnnotator so capture orchestration, annotation rendering/styling, and raycast summary/physics builders each have one clear responsibility without changing screenshot behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hatayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2e91bbf1-3802-4e87-b64e-39a71fa77d97

📥 Commits

Reviewing files that changed from the base of the PR and between aad980d and 9040a41.

📒 Files selected for processing (3)
  • Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastGridAnnotator.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastPhysicsColliderBuilder.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotationRenderer.cs
📝 Walkthrough

Walkthrough

Screenshot capture responsibilities are extracted into validation, metadata, file-writing, response, raycast-building, and annotation-rendering helpers. ScreenshotUseCase and UIElementAnnotator delegate to these helpers, with characterization tests covering key helper behavior.

Changes

Screenshot capture and annotation

Layer / File(s) Summary
Capture validation and output helpers
Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs, Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotParameterValidator.cs, Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotCoordinateMetadata.cs, Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotFileWriter.cs, Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotResponseFactory.cs, Assets/Tests/Editor/ScreenshotUseCaseCharacterizationTests.cs
Validation, coordinate metadata, output writing, response assembly, and filename sanitization move into dedicated helpers and are covered by characterization tests.
Raycast sample and collider construction
Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastGridAnnotator.cs, Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastLayerSummaryBuilder.cs, Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastPhysicsColliderBuilder.cs
Layer-hit aggregation, representative-path selection, connected-component splitting, collider metadata, bounds, coverage, and physics element creation are extracted from RaycastGridAnnotator.
Annotation styling and rendering
Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotator.cs, Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotationStyling.cs, Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotationRenderer.cs
Annotation color, label, border, outline, geometry, and runtime UI construction move into styling and renderer helpers delegated by UIElementAnnotator.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly reflects the main change: splitting Screenshot editor code to keep files under 500 lines.
Description check ✅ Passed The description directly matches the refactor and characterization tests shown in the changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/split-screenshot-annotators

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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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
`@Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastPhysicsColliderBuilder.cs`:
- Around line 14-15: The clustered grid dimensions are duplicated between the
builder and annotator, allowing bounds and sampling to diverge. In
Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastPhysicsColliderBuilder.cs:14-15,
change CLUSTERED_GRID_COLUMNS and CLUSTERED_GRID_ROWS to internal const and use
them as the shared source of truth; in
Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastGridAnnotator.cs:16-17,
remove the local constants and reference
RaycastPhysicsColliderBuilder.CLUSTERED_GRID_COLUMNS and CLUSTERED_GRID_ROWS
from CollectClusterSamples.
- Around line 62-80: The physics-collider type literal is duplicated between
construction and rendering, allowing mismatches. In
RaycastPhysicsColliderBuilder.cs lines 62-80, add a shared internal constant
named TYPE_PHYSICS_COLLIDER with value "PhysicsCollider" and assign it to
UIElementInfo.Type; in UIElementAnnotationRenderer.cs lines 228-231, update
IsPhysicsColliderElement to compare against that shared constant instead of the
raw literal.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3968976a-b2fb-4945-a379-169c46490bd1

📥 Commits

Reviewing files that changed from the base of the PR and between 8027c30 and aad980d.

⛔ Files ignored due to path filters (9)
  • Assets/Tests/Editor/ScreenshotUseCaseCharacterizationTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastLayerSummaryBuilder.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastPhysicsColliderBuilder.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotCoordinateMetadata.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotFileWriter.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotParameterValidator.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotResponseFactory.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotationRenderer.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotationStyling.cs.meta is excluded by none and included by none
📒 Files selected for processing (12)
  • Assets/Tests/Editor/ScreenshotUseCaseCharacterizationTests.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastGridAnnotator.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastLayerSummaryBuilder.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/RaycastAnnotation/RaycastPhysicsColliderBuilder.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotCoordinateMetadata.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotFileWriter.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotParameterValidator.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotResponseFactory.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/ScreenshotUseCase.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotationRenderer.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotationStyling.cs
  • Packages/src/Editor/FirstPartyTools/Screenshot/UIElementAnnotator.cs

Keep sample-loop density and physics annotation Type checks on a single source of truth after the Extract Class split so the two sides cannot drift independently.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hatayama
hatayama merged commit 4ca41e8 into feature/god-class-split-integration Jul 14, 2026
2 checks passed
@hatayama
hatayama deleted the feat/split-screenshot-annotators branch July 14, 2026 09:08
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.

1 participant