Skip to content

docs: clarify color comparison options — tolerance, perceptual_threshold, color_distance_limit#176

Merged
pftg merged 2 commits intomasterfrom
emdash/feat-colordistancelimit-difference-tolerance-326
Apr 12, 2026
Merged

docs: clarify color comparison options — tolerance, perceptual_threshold, color_distance_limit#176
pftg merged 2 commits intomasterfrom
emdash/feat-colordistancelimit-difference-tolerance-326

Conversation

@pftg
Copy link
Copy Markdown
Collaborator

@pftg pftg commented Apr 12, 2026

Summary

Fixed 7 documentation consistency issues discovered during analysis of color comparison options.

Changes

  • Fix incorrect default tolerance — docs said 0.0005, code uses 0.001
  • Add decision tree for choosing between perceptual_threshold vs color_distance_limit
  • Clarify tolerance relationship — works with both color methods (not exclusive as docs claimed); applied by default for VIPS
  • Correct color_distance_limit scale — 0-441 → 0-510 (RGBA, not RGB)
  • Document driver difference — VIPS counts actual different pixels, ChunkyPNG counts diff bounding box area
  • Fix misleading example — drivers.md used tolerance 0.3, 600× more permissive than recommendations
  • Add missing YARD docs — perceptual_threshold option undocumented in DSL
  • Fix copy-paste errors — test named 'color threshold' demonstrating shift_distance_limit

Files Changed

  • README.md
  • docs/configuration.md
  • docs/drivers.md
  • lib/capybara_screenshot_diff/dsl.rb

Summary by Sourcery

Clarify and correct documentation around visual diff color comparison options and their interactions.

Documentation:

  • Update configuration and README docs to show accurate defaults and recommended values for tolerance and perceptual_threshold.
  • Document the decision process for choosing between perceptual_threshold and color_distance_limit, including their exclusivity and differing scales.
  • Explain how tolerance behaves across VIPS and ChunkyPNG drivers, including the stricter bounding-box behavior in ChunkyPNG.
  • Correct scales and semantics for color_distance_limit (RGBA 0-510) and add clearer usage examples with realistic tolerance values.
  • Add missing DSL option documentation for perceptual_threshold, color_distance_limit, and tolerance in the screenshot helper YARD docs.

…old, color_distance_limit

- Fix incorrect default tolerance value in docs (0.0005 → 0.001 to match code)
- Add decision tree for choosing between perceptual_threshold vs color_distance_limit
- Clarify tolerance works with both color methods (not exclusive as docs claimed)
- Correct color_distance_limit scale from 0-441 to 0-510 (RGBA, not RGB)
- Document VIPS vs ChunkyPNG tolerance calculation difference (pixels vs bounding box)
- Fix drivers.md tolerance example (0.3 → 0.001) to match recommendations
- Add perceptual_threshold to YARD DSL docs (was missing)
- Fix copy-paste errors in configuration.md section headings

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 12, 2026

Reviewer's Guide

Documentation-only PR that corrects and clarifies how color comparison options (tolerance, perceptual_threshold, color_distance_limit) behave and interact across VIPS and ChunkyPNG drivers, updates recommended values/examples, and adds missing DSL/YARD docs to match the actual implementation defaults.

Flow diagram for choosing color comparison method and tolerance

flowchart TD
  A(["Start: Configure visual diffs"]) --> B{"Which driver?"}

  B -->|"VIPS (ruby-vips)"| C{"Primary goal?"}
  B -->|"ChunkyPNG"| H{"Need cross-OS/browser robustness?"}

  C -->|"Handle font/anti-aliasing differences"| D["Use perceptual_threshold: 2.0 (recommended)"]
  C -->|"Legacy / fine-grained RGB control"| E["Use color_distance_limit (0-510)"]

  D --> F{"Need to allow some differing pixels?"}
  E --> F

  F -->|"Yes"| G["Set tolerance (0.0-1.0), default 0.001 for VIPS"]
  F -->|"No"| I["Rely on chosen color method only"]

  H -->|"Yes"| J["Prefer VIPS with perceptual_threshold if possible"]
  H -->|"No / staying on ChunkyPNG"| K["Use color_distance_limit (0-510)"]

  K --> L{"Need to allow some differing regions?"}
  L -->|"Yes"| M["Set tolerance (0.0-1.0) — counts diff bounding box area"]
  L -->|"No"| N["Rely on color_distance_limit only"]

  G --> O(["Done: perceptual_threshold or color_distance_limit + optional tolerance"])
  I --> O
  J --> C
  M --> O
  N --> O
Loading

Flow diagram for option exclusivity and evaluation order

flowchart TD
  A(["Start: Run screenshot comparison"]) --> B["Read configuration: perceptual_threshold, color_distance_limit, tolerance, driver"]

  B --> C{"Is perceptual_threshold set?"}
  C -->|"Yes"| D["Activate perceptual_threshold (CIE dE00, 0-100+)"]
  C -->|"No"| E{"Is color_distance_limit set?"}

  E -->|"Yes"| F["Activate color_distance_limit (RGBA Euclidean, 0-510)"]
  E -->|"No"| G["Use driver default color method (if any)"]

  D --> H
  F --> H
  G --> H

  H["Compute pixel-level differences using active color method"] --> I{"Is tolerance configured?"}

  I -->|"VIPS driver"| J["Interpret tolerance as ratio of differing pixels (0.0-1.0)"]
  I -->|"ChunkyPNG driver"| K["Interpret tolerance as ratio of diff bounding box area (0.0-1.0)"]
  I -->|"No tolerance"| L["Treat any detected difference as failure"]

  J --> M{"Difference ratio <= tolerance?"}
  K --> M

  M -->|"Yes"| N(["Result: Comparison passes (differences within tolerance)"])
  M -->|"No"| O(["Result: Comparison fails (differences exceed tolerance)"])
  L --> O
Loading

File-Level Changes

Change Details Files
Align docs with actual defaults and semantics of tolerance and color comparison options.
  • Update configuration tables so VIPS tolerance default is 0.001 rather than 0.0005 and explicitly note ChunkyPNG has no default
  • Clarify that tolerance is a ratio of differing pixels (0.0–1.0) and is applied by default for VIPS while remaining independent of the color comparison method
  • Explain that tolerance answers "how many pixels can differ" while color comparison options answer "how different can a pixel be"
docs/configuration.md
README.md
docs/drivers.md
lib/capybara_screenshot_diff/dsl.rb
Clarify the relationship and mutual exclusivity between perceptual_threshold and color_distance_limit, including their scales and driver applicability.
  • Add a decision tree section to guide choosing between perceptual_threshold and color_distance_limit and explain that they are mutually exclusive with perceptual_threshold taking precedence
  • Document the different numeric scales and algorithms used: dE00 (0–100+) for perceptual_threshold vs Euclidean RGBA distance (0–510) for color_distance_limit
  • Update README and drivers docs to consistently state that you should set one color method or the other, and that tolerance can be used in combination with either
docs/configuration.md
README.md
docs/drivers.md
lib/capybara_screenshot_diff/dsl.rb
Correct misleading examples and numeric ranges to reflect realistic and recommended usage.
  • Fix the color_distance_limit scale from 0–441 (RGB) to 0–510 (RGBA) in docs
  • Replace overly permissive tolerance: 0.3 examples with realistic recommendations (e.g., 0.01 for noisy pages, 0.001 as VIPS default)
  • Update quick-start and usage tables to recommend perceptual_threshold: 2.0 for cross-OS/browser testing and better defaults per use case
docs/configuration.md
README.md
docs/drivers.md
Document driver-specific behavior differences that affect how tolerance is interpreted.
  • Clarify that VIPS counts actual differing pixels while ChunkyPNG uses the diff bounding box area, making ChunkyPNG stricter for the same tolerance value
  • Add explanatory notes in the configuration docs about this behavior so users understand why the same tolerance can behave differently across drivers
docs/configuration.md
Improve DSL/YARD documentation for screenshot options to match implementation and behavior.
  • Add/expand YARD comments for tolerance, color_distance_limit, and perceptual_threshold options in the DSL, including descriptions of their scales, algorithms, driver support, and mutual exclusivity
  • Clarify that perceptual_threshold is VIPS-only and takes priority over color_distance_limit when both are set
  • Fix copy inaccuracies around color/shift distance naming in comments
lib/capybara_screenshot_diff/dsl.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Warning

Rate limit exceeded

@pftg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 20 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5a27078f-4245-45d2-8e30-250c6ec19bf6

📥 Commits

Reviewing files that changed from the base of the PR and between b4f043c and 5e219f4.

📒 Files selected for processing (4)
  • README.md
  • docs/configuration.md
  • docs/drivers.md
  • lib/capybara_screenshot_diff/dsl.rb
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch emdash/feat-colordistancelimit-difference-tolerance-326

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 and usage tips.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In dsl.rb YARD docs for :color_distance_limit still describe it as Euclidean RGB with a 0–441 scale, which conflicts with the updated docs specifying RGBA and 0–510; align this description with the new behavior.
  • The README section labeling Capybara::Screenshot::Diff.tolerance = 0.0005 as "Raw RGB tolerance" is a bit misleading now that tolerance is documented as a ratio of differing pixels; consider rephrasing to match the terminology and explanation used in docs/configuration.md.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `dsl.rb` YARD docs for `:color_distance_limit` still describe it as Euclidean RGB with a 0–441 scale, which conflicts with the updated docs specifying RGBA and 0–510; align this description with the new behavior.
- The README section labeling `Capybara::Screenshot::Diff.tolerance = 0.0005` as "Raw RGB tolerance" is a bit misleading now that `tolerance` is documented as a ratio of differing pixels; consider rephrasing to match the terminology and explanation used in `docs/configuration.md`.

## Individual Comments

### Comment 1
<location path="docs/configuration.md" line_range="32" />
<code_context>
+| Standard Rails apps | 0.001 (default) | 15 | 1s |
 | Pixel-perfect design tests | 0.0001 | 5 | 1s |

+**Note:** VIPS defaults to `tolerance: 0.001` (allow 0.1% pixel difference). ChunkyPNG has no default tolerance.
+
+## Choosing the Right Color Comparison Method
</code_context>
<issue_to_address>
**nitpick (typo):** Consider changing "allow" to "allows" for grammatical agreement.

Because "VIPS defaults to `tolerance: 0.001`" is the subject, the parenthetical should use the third-person form: "(allows 0.1% pixel difference)".

```suggestion
**Note:** VIPS defaults to `tolerance: 0.001` (allows 0.1% pixel difference). ChunkyPNG has no default tolerance.
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread docs/configuration.md Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 12, 2026

Screenshot diffs resolved

All screenshots match their baselines. Previous diffs have been fixed.

- Fix dsl.rb YARD: RGB 0-441 → RGBA 0-510 to match updated docs
- Fix README: rename "Raw RGB tolerance" to "Tolerance-based comparison"
- Fix typo: "allow" → "allows" in configuration.md

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@pftg pftg merged commit b50cae3 into master Apr 12, 2026
8 checks passed
@pftg pftg deleted the emdash/feat-colordistancelimit-difference-tolerance-326 branch April 12, 2026 18:30
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